Skip to content

Commit 036f1e9

Browse files
authored
Merge pull request #39 from paritytech/pg/update-node-env
Add fibs benchmark
2 parents 4510160 + 9ef475d commit 036f1e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2147
-1293
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@
22
logs
33
*.log
44
.env
5+
56
npm-debug.log*
67
yarn-debug.log*
78
yarn-error.log*
89
pnpm-debug.log*
910
lerna-debug.log*
1011

1112
codegen/*.ts
13+
codegen/*.json
1214
codegen/abi/*
1315
codegen/pvm/*
1416
codegen/evm/*
1517
*.sha256.txt
1618

19+
# Benchmark artifacts
20+
stats.db
21+
benchmark/.ipynb_checkpoints/
22+
1723
node_modules
1824
dist
1925
dist-ssr

benchmark/contracts.ts

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env -S deno run --env-file --allow-all
2+
import { deploy as deployContract, env } from '../tools/lib/index.ts'
3+
import { abis } from '../codegen/abis.ts'
4+
import { logger } from '../utils/logger.ts'
5+
import {
6+
Artifacts,
7+
build,
8+
deleteChainData,
9+
deploy,
10+
execute,
11+
ink,
12+
rust,
13+
solidity,
14+
} from './lib.ts'
15+
import { parseArgs } from '@std/cli'
16+
import { parseEther } from 'viem'
17+
18+
export const contracts: Artifacts = [
19+
{
20+
id: 'Fibonacci',
21+
srcs: [
22+
ink('fibonacci'),
23+
rust('fibonacci'),
24+
rust('fibonacci_u128'),
25+
rust('fibonacci_u256'),
26+
...solidity('fibonacci.sol', 'Fibonacci'),
27+
],
28+
deploy: (id, name, bytecode) => {
29+
return deployContract({
30+
name: { id, name },
31+
bytecode,
32+
args: [],
33+
})
34+
},
35+
calls: [
36+
{
37+
name: 'fib_10',
38+
exec: async (address) => {
39+
return await env.wallet.writeContract({
40+
address,
41+
abi: abis.Fibonacci,
42+
functionName: 'fibonacci',
43+
args: [10],
44+
})
45+
},
46+
},
47+
],
48+
},
49+
{
50+
id: 'SimpleToken',
51+
srcs: [
52+
ink('simple_token'),
53+
rust('simple_token_no_alloc'),
54+
...solidity('simple_token.sol', 'SimpleToken'),
55+
],
56+
deploy: (id, name, bytecode) => {
57+
return deployContract({
58+
name: { id, name },
59+
bytecode,
60+
args: [],
61+
})
62+
},
63+
calls: [
64+
{
65+
name: 'mint',
66+
exec: (address) => {
67+
return env.wallet.writeContract({
68+
address,
69+
abi: abis.SimpleToken,
70+
functionName: 'mint',
71+
args: [
72+
env.wallet.account.address,
73+
10_000_000_000_000_000_000_000_000n,
74+
],
75+
})
76+
},
77+
},
78+
{
79+
name: 'transfer',
80+
exec: async (address) => {
81+
// fund destination first
82+
await env.wallet.sendTransaction({
83+
to: '0x3d26c9637dFaB74141bA3C466224C0DBFDfF4A63',
84+
value: parseEther('1'),
85+
})
86+
87+
return env.wallet.writeContract({
88+
address,
89+
abi: abis.SimpleToken,
90+
functionName: 'transfer',
91+
args: [
92+
'0x3d26c9637dFaB74141bA3C466224C0DBFDfF4A63',
93+
10_000_000_000_000_000_000_000_000n,
94+
],
95+
})
96+
},
97+
},
98+
],
99+
},
100+
]
101+
102+
const cli = parseArgs(Deno.args, {
103+
boolean: ['build', 'execute', 'report', 'clean'],
104+
})
105+
106+
if (cli.build) {
107+
logger.info(`Building contracts...`)
108+
await build(contracts)
109+
}
110+
if (cli.execute) {
111+
logger.info(`Deleting existing data for chain: ${env.chain.name}`)
112+
deleteChainData(env.chain.name)
113+
114+
logger.info(`Deploying contracts...`)
115+
await deploy(contracts)
116+
117+
logger.info(`Executing contracts...`)
118+
await execute(contracts)
119+
}
120+
121+
if (cli.report) {
122+
logger.info(`Generating reports...`)
123+
const { report } = await import('./reports.ts')
124+
await report(contracts)
125+
}

0 commit comments

Comments
 (0)