From 5fb22b0b3f3d28d5083e2d78e27e711da0425cdc Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Thu, 8 Aug 2024 09:49:45 +0100 Subject: [PATCH 1/2] feat: add eth shanghai test --- network/config/genesis.json | 3 +- test/evm/compatability.test.ts | 51 +++++++++++++++++++++++++++++ test/evm/paris/simple-paris.test.ts | 28 ---------------- 3 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 test/evm/compatability.test.ts delete mode 100644 test/evm/paris/simple-paris.test.ts diff --git a/network/config/genesis.json b/network/config/genesis.json index ca6b3e5..6cb668c 100644 --- a/network/config/genesis.json +++ b/network/config/genesis.json @@ -8,7 +8,8 @@ "BLOCKLIST": 0, "ETH_IST": 0, "VIP214": 0, - "FINALITY": 0 + "FINALITY": 0, + "ETH_SH": 0 }, "accounts": [ { diff --git a/test/evm/compatability.test.ts b/test/evm/compatability.test.ts new file mode 100644 index 0000000..e123243 --- /dev/null +++ b/test/evm/compatability.test.ts @@ -0,0 +1,51 @@ +import { ThorWallet } from '../../src/wallet' +import { + SimpleCounterParis__factory as ParisCounter, + SimpleCounterShanghai__factory as ShanghaiCounter, +} from '../../typechain-types' +import { pollReceipt } from '../../src/transactions' + +/** + * @group opcodes + * @group evm + */ +describe('fork contract tests', () => { + const wallet: ThorWallet = ThorWallet.withFunds() + + const counters = [ + { + countrct: ParisCounter, + name: 'Paris', + }, + { + countrct: ShanghaiCounter, + name: 'Shanghai', + }, + ] + + counters.forEach((counter) => { + it.e2eTest( + `should be able to deploy a ${counter.name} contract`, + 'all', + async () => { + const contract = await wallet.deployContract( + counter.countrct.bytecode, + counter.countrct.abi, + ) + + const startValue = await contract.read + .getCounter() + .then((r) => r[0]) + + expect(startValue).toBe(0n) + const increment = await contract.transact.incrementCounter() + await pollReceipt(increment.id) + + const endValue = await contract.read + .getCounter() + .then((r) => r[0]) + expect(endValue).toBe(1n) + }, + ) + }) +}) diff --git a/test/evm/paris/simple-paris.test.ts b/test/evm/paris/simple-paris.test.ts deleted file mode 100644 index f3932f2..0000000 --- a/test/evm/paris/simple-paris.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { ThorWallet } from '../../../src/wallet' -import { SimpleCounterParis__factory as ParisCounter } from '../../../typechain-types' -import { pollReceipt } from '../../../src/transactions' - -/** - * @group opcodes - * @group evm - * @group paris - */ -describe('Simple Paris', () => { - const wallet: ThorWallet = ThorWallet.withFunds() - - it.e2eTest('should be able to deploy a paris contract', 'all', async () => { - const contract = await wallet.deployContract( - ParisCounter.bytecode, - ParisCounter.abi, - ) - - const startValue = await contract.read.getCounter().then((r) => r[0]) - - expect(startValue).toBe(0n) - const increment = await contract.transact.incrementCounter() - await pollReceipt(increment.id) - - const endValue = await contract.read.getCounter().then((r) => r[0]) - expect(endValue).toBe(1n) - }) -}) From 78478e83844dc665b8bdc53acd91e969b575c6ca Mon Sep 17 00:00:00 2001 From: Darren Kelly Date: Fri, 9 Aug 2024 10:09:14 +0100 Subject: [PATCH 2/2] fix: update inividual opcodes test --- test/evm/individual-opcodes.test.ts | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/test/evm/individual-opcodes.test.ts b/test/evm/individual-opcodes.test.ts index 7455100..005861b 100644 --- a/test/evm/individual-opcodes.test.ts +++ b/test/evm/individual-opcodes.test.ts @@ -544,27 +544,18 @@ describe('Individual OpCodes', () => { 'should give the correct output for opcode: PUSH0', 'all', async () => { - const clauses = [ - { - data: ShanghaiCounter.bytecode, - value: '0x0', - to: null, - }, - ] - - const tx = await wallet.sendClauses(clauses, false) - - const receipt = await pollReceipt(tx.id ?? '') - - expect(receipt.reverted).toBe(true) - - // 0x5f is the PUSH0 opcode - const simulation = await Client.raw.executeAccountBatch({ - clauses, + const debugged = await Client.raw.traceContractCall({ + to: null, + data: ShanghaiCounter.bytecode, + value: '0x0', caller, + gas: 1_000_000, }) - - expect(simulation.body?.[0]?.vmError).toEqual('invalid opcode 0x5f') + expect(debugged.httpCode).toBe(200) + expect(debugged.body.failed).toBe(false) + expect( + debugged.body.structLogs.some((log: any) => log.op === 'PUSH0'), + ).toBe(true) }, ) })