Skip to content

Commit 6ffa857

Browse files
authored
Merge pull request #87 from paritytech/pg/updates
Update eth-rpc tests
2 parents 7c76c13 + 10cacf5 commit 6ffa857

File tree

8 files changed

+369
-87
lines changed

8 files changed

+369
-87
lines changed

eth-rpc/contracts/Flipper.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ pragma solidity ^0.8.0;
55
contract Flipper {
66
bool public value;
77

8+
constructor() {
9+
value = true;
10+
}
11+
812
function flip() external {
9-
value = !value;
13+
value = !value;
1014
}
1115

1216
function getValue() external view returns (bool) {

eth-rpc/contracts/Tester.sol

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
// Flipper - Stores and toggles a boolean value
5+
contract Tester {
6+
uint256 public value;
7+
string public name;
8+
9+
event TesterDeployed(address indexed creator);
10+
11+
constructor() payable {
12+
emit TesterDeployed(msg.sender);
13+
value = 42;
14+
name = "Hello world";
15+
}
16+
17+
function setValue(uint256 v) external {
18+
value = v;
19+
}
20+
21+
function setName(string memory v) external {
22+
name = v;
23+
}
24+
25+
}
26+

eth-rpc/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"build": "npx tsx src/build-contracts.ts",
8-
"test": "vitest --test-timeout=30000",
9-
"test-init": "vitest run --test-timeout=30000",
8+
"test": "vitest --test-timeout=30000 --no-file-parallelism",
9+
"test-init": "vitest run --test-timeout=30000 --no-file-parallelism",
1010
"prettier": "prettier --write .",
1111
"solhint": "solhint \"contracts/**/*.sol\""
1212
},

eth-rpc/src/geth-diff.test.ts

Lines changed: 38 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import { jsonRpcErrors, getByteCode, visit, createEnv } from './util.ts'
1+
import {
2+
jsonRpcErrors,
3+
getByteCode,
4+
visit,
5+
createEnv,
6+
deployFactory,
7+
} from './util.ts'
28
import { afterEach, describe, expect, inject, test } from 'vitest'
39
import fs from 'node:fs'
410
import { fail } from 'node:assert'
511

6-
import { encodeFunctionData, Hex, parseEther, decodeEventLog } from 'viem'
12+
import { encodeFunctionData, parseEther, decodeEventLog } from 'viem'
713
import { ErrorsAbi } from '../abi/Errors.ts'
814
import { EventExampleAbi } from '../abi/EventExample.ts'
915
import { TracingCallerAbi } from '../abi/TracingCaller.ts'
@@ -15,78 +21,36 @@ afterEach(() => {
1521

1622
const envs = await Promise.all(inject('envs').map(createEnv))
1723
for (const env of envs) {
18-
describe(`${env.serverWallet.chain.name}`, () => {
19-
const getErrorTesterAddr = (() => {
20-
let contractAddress: Hex = '0x'
21-
return async () => {
22-
if (contractAddress !== '0x') {
23-
return contractAddress
24-
}
25-
const hash = await env.serverWallet.deployContract({
26-
abi: ErrorsAbi,
27-
bytecode: getByteCode('Errors', env.evm),
28-
})
29-
const deployReceipt =
30-
await env.serverWallet.waitForTransactionReceipt({ hash })
31-
contractAddress = deployReceipt.contractAddress!
32-
return contractAddress
33-
}
34-
})()
24+
const [getErrorTesterAddr] = deployFactory(env, () =>
25+
env.serverWallet.deployContract({
26+
abi: ErrorsAbi,
27+
bytecode: getByteCode('Errors', env.evm),
28+
})
29+
)
3530

36-
const getEventExampleAddr = (() => {
37-
let contractAddress: Hex = '0x'
38-
return async () => {
39-
if (contractAddress !== '0x') {
40-
return contractAddress
41-
}
42-
const hash = await env.serverWallet.deployContract({
43-
abi: EventExampleAbi,
44-
bytecode: getByteCode('EventExample', env.evm),
45-
})
46-
const deployReceipt =
47-
await env.serverWallet.waitForTransactionReceipt({ hash })
48-
contractAddress = deployReceipt.contractAddress!
49-
return contractAddress
50-
}
51-
})()
52-
53-
const getTracingExampleAddrs = (() => {
54-
let callerAddr: Hex = '0x'
55-
let calleeAddr: Hex = '0x'
56-
return async () => {
57-
if (callerAddr !== '0x') {
58-
return [callerAddr, calleeAddr]
59-
}
60-
calleeAddr = await (async () => {
61-
const hash = await env.serverWallet.deployContract({
62-
abi: TracingCalleeAbi,
63-
bytecode: getByteCode('TracingCallee', env.evm),
64-
})
65-
const receipt =
66-
await env.serverWallet.waitForTransactionReceipt({
67-
hash,
68-
})
69-
return receipt.contractAddress!
70-
})()
71-
72-
callerAddr = await (async () => {
73-
const hash = await env.serverWallet.deployContract({
74-
abi: TracingCallerAbi,
75-
args: [calleeAddr],
76-
bytecode: getByteCode('TracingCaller', env.evm),
77-
value: parseEther('10'),
78-
})
79-
const receipt =
80-
await env.serverWallet.waitForTransactionReceipt({
81-
hash,
82-
})
83-
return receipt.contractAddress!
84-
})()
85-
86-
return [callerAddr, calleeAddr]
87-
}
88-
})()
31+
const [getEventExampleAddr] = deployFactory(env, async () =>
32+
env.serverWallet.deployContract({
33+
abi: EventExampleAbi,
34+
bytecode: getByteCode('EventExample', env.evm),
35+
})
36+
)
8937

38+
const [getTracingCalleeAddr] = deployFactory(env, async () =>
39+
env.serverWallet.deployContract({
40+
abi: TracingCalleeAbi,
41+
bytecode: getByteCode('TracingCallee', env.evm),
42+
})
43+
)
44+
45+
const [getTracingCallerAddr] = deployFactory(env, async () =>
46+
env.serverWallet.deployContract({
47+
abi: TracingCallerAbi,
48+
args: [await getTracingCalleeAddr()],
49+
bytecode: getByteCode('TracingCaller', env.evm),
50+
value: parseEther('10'),
51+
})
52+
)
53+
describe(`${env.serverWallet.chain.name}`, () => {
9054
test('triggerAssertError', async () => {
9155
try {
9256
await env.accountWallet.readContract({
@@ -390,7 +354,8 @@ for (const env of envs) {
390354
})
391355

392356
test('tracing', async () => {
393-
let [callerAddr, calleeAddr] = await getTracingExampleAddrs()
357+
const calleeAddr = await getTracingCalleeAddr()
358+
const callerAddr = await getTracingCallerAddr()
394359

395360
const receipt = await (async () => {
396361
const { request } = await env.serverWallet.simulateContract({

0 commit comments

Comments
 (0)