Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion eth-rpc/contracts/Flipper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ pragma solidity ^0.8.0;
contract Flipper {
bool public value;

constructor() {
value = true;
}

function flip() external {
value = !value;
value = !value;
}

function getValue() external view returns (bool) {
Expand Down
26 changes: 26 additions & 0 deletions eth-rpc/contracts/Tester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Flipper - Stores and toggles a boolean value
contract Tester {
uint256 public value;
string public name;

event TesterDeployed(address indexed creator);

constructor() payable {
emit TesterDeployed(msg.sender);
value = 42;
name = "Hello world";
}

function setValue(uint256 v) external {
value = v;
}

function setName(string memory v) external {
name = v;
}

}

4 changes: 2 additions & 2 deletions eth-rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"type": "module",
"scripts": {
"build": "npx tsx src/build-contracts.ts",
"test": "vitest --test-timeout=30000",
"test-init": "vitest run --test-timeout=30000",
"test": "vitest --test-timeout=30000 --no-file-parallelism",
"test-init": "vitest run --test-timeout=30000 --no-file-parallelism",
"prettier": "prettier --write .",
"solhint": "solhint \"contracts/**/*.sol\""
},
Expand Down
111 changes: 38 additions & 73 deletions eth-rpc/src/geth-diff.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { jsonRpcErrors, getByteCode, visit, createEnv } from './util.ts'
import {
jsonRpcErrors,
getByteCode,
visit,
createEnv,
deployFactory,
} from './util.ts'
import { afterEach, describe, expect, inject, test } from 'vitest'
import fs from 'node:fs'
import { fail } from 'node:assert'

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

const envs = await Promise.all(inject('envs').map(createEnv))
for (const env of envs) {
describe(`${env.serverWallet.chain.name}`, () => {
const getErrorTesterAddr = (() => {
let contractAddress: Hex = '0x'
return async () => {
if (contractAddress !== '0x') {
return contractAddress
}
const hash = await env.serverWallet.deployContract({
abi: ErrorsAbi,
bytecode: getByteCode('Errors', env.evm),
})
const deployReceipt =
await env.serverWallet.waitForTransactionReceipt({ hash })
contractAddress = deployReceipt.contractAddress!
return contractAddress
}
})()
const [getErrorTesterAddr] = deployFactory(env, () =>
env.serverWallet.deployContract({
abi: ErrorsAbi,
bytecode: getByteCode('Errors', env.evm),
})
)

const getEventExampleAddr = (() => {
let contractAddress: Hex = '0x'
return async () => {
if (contractAddress !== '0x') {
return contractAddress
}
const hash = await env.serverWallet.deployContract({
abi: EventExampleAbi,
bytecode: getByteCode('EventExample', env.evm),
})
const deployReceipt =
await env.serverWallet.waitForTransactionReceipt({ hash })
contractAddress = deployReceipt.contractAddress!
return contractAddress
}
})()

const getTracingExampleAddrs = (() => {
let callerAddr: Hex = '0x'
let calleeAddr: Hex = '0x'
return async () => {
if (callerAddr !== '0x') {
return [callerAddr, calleeAddr]
}
calleeAddr = await (async () => {
const hash = await env.serverWallet.deployContract({
abi: TracingCalleeAbi,
bytecode: getByteCode('TracingCallee', env.evm),
})
const receipt =
await env.serverWallet.waitForTransactionReceipt({
hash,
})
return receipt.contractAddress!
})()

callerAddr = await (async () => {
const hash = await env.serverWallet.deployContract({
abi: TracingCallerAbi,
args: [calleeAddr],
bytecode: getByteCode('TracingCaller', env.evm),
value: parseEther('10'),
})
const receipt =
await env.serverWallet.waitForTransactionReceipt({
hash,
})
return receipt.contractAddress!
})()

return [callerAddr, calleeAddr]
}
})()
const [getEventExampleAddr] = deployFactory(env, async () =>
env.serverWallet.deployContract({
abi: EventExampleAbi,
bytecode: getByteCode('EventExample', env.evm),
})
)

const [getTracingCalleeAddr] = deployFactory(env, async () =>
env.serverWallet.deployContract({
abi: TracingCalleeAbi,
bytecode: getByteCode('TracingCallee', env.evm),
})
)

const [getTracingCallerAddr] = deployFactory(env, async () =>
env.serverWallet.deployContract({
abi: TracingCallerAbi,
args: [await getTracingCalleeAddr()],
bytecode: getByteCode('TracingCaller', env.evm),
value: parseEther('10'),
})
)
describe(`${env.serverWallet.chain.name}`, () => {
test('triggerAssertError', async () => {
try {
await env.accountWallet.readContract({
Expand Down Expand Up @@ -390,7 +354,8 @@ for (const env of envs) {
})

test('tracing', async () => {
let [callerAddr, calleeAddr] = await getTracingExampleAddrs()
const calleeAddr = await getTracingCalleeAddr()
const callerAddr = await getTracingCallerAddr()

const receipt = await (async () => {
const { request } = await env.serverWallet.simulateContract({
Expand Down
Loading