From 15b7d657ffe724ee7cdbb96acc202239860eb050 Mon Sep 17 00:00:00 2001 From: Sem <931684+sembrestels@users.noreply.github.com> Date: Thu, 17 Aug 2023 20:49:58 +0200 Subject: [PATCH] Fix verify-givbacks command --- packages/evmcrispr/hardhat.config.ts | 2 +- .../giveth/commands/verify-givbacks.ts | 54 +++++++++++++------ .../giveth/commands/verify-givbacks.test.ts | 12 ++++- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/packages/evmcrispr/hardhat.config.ts b/packages/evmcrispr/hardhat.config.ts index 42bf95c5..29f8ce02 100644 --- a/packages/evmcrispr/hardhat.config.ts +++ b/packages/evmcrispr/hardhat.config.ts @@ -57,7 +57,7 @@ const config: HardhatUserConfig = { chainId: 100, forking: { url: ARCHIVE_NODE_ENDPOINT, - blockNumber: 24_730_000, + blockNumber: 29509000, }, }, }, diff --git a/packages/evmcrispr/src/modules/giveth/commands/verify-givbacks.ts b/packages/evmcrispr/src/modules/giveth/commands/verify-givbacks.ts index c013df80..6a4af5b9 100644 --- a/packages/evmcrispr/src/modules/giveth/commands/verify-givbacks.ts +++ b/packages/evmcrispr/src/modules/giveth/commands/verify-givbacks.ts @@ -59,7 +59,11 @@ export const verifyGivbacks: ICommand = { decodedVoteScript.length !== 1 || decodedVoteScript[0].to !== agent.toLowerCase() ) { - throw new Error('Vote script does not match script in ' + hash); + throw new Error( + 'Vote script does not match script in ' + + hash + + '. Main call is not to the agent.', + ); } const decodedAgentScript = decodeCallScript( @@ -73,31 +77,47 @@ export const verifyGivbacks: ICommand = { if ( decodedAgentScript.some((call) => call.to !== relayerAddr.toLowerCase()) ) { - throw new Error('Vote script does not match script in ' + hash); + throw new Error( + 'Vote script does not match script in ' + + hash + + '. Some calls are not to the relayer.', + ); } - const decodedRelayerCalls = decodedAgentScript.map((call) => - relayer.interface.decodeFunctionData('addBatches', call.data), + if (decodedAgentScript.length !== 1) { + throw new Error( + 'Vote script does not match script in ' + + hash + + '. There are more than one calls to the relayer.', + ); + } + + const decodedRelayerCall = relayer.interface.decodeFunctionData( + 'addBatches', + decodedAgentScript[0].data, ); - // if one of the decoded calls is not the expected batch, throw - if ( - decodedRelayerCalls.some((call) => utils.toUtf8String(call[1]) !== hash) - ) { - throw new Error('Vote script does not match script in ' + hash); + // if the decoded call has not the expected ipfs hash, throw + if (utils.toUtf8String(decodedRelayerCall[1]) !== hash) { + throw new Error( + 'Vote script does not match script in ' + + hash + + '. The IPFS hash do not correspond to the one in the script.', + ); } - // if one of the decoded calls is not the expected batch, throw + // if the decoded call has not the expected batches, throw if ( - decodedRelayerCalls.some((call) => - call[0].some((batch: string) => !batches.includes(batch)), + decodedRelayerCall[0].length !== batches.length || + !decodedRelayerCall[0].every( + (batch: string, i: number) => batch === batches[i], ) ) { - throw new Error('Vote script does not match script in ' + hash); - } - - if (decodedRelayerCalls.length !== batches.length) { - throw new Error('Vote script does not match script in ' + hash); + throw new Error( + 'Vote script does not match script in ' + + hash + + '. Some calls are not to the expected batch, vis.', + ); } module.evmcrispr.log('Vote script matches script in ' + hash); diff --git a/packages/evmcrispr/test/modules/giveth/commands/verify-givbacks.test.ts b/packages/evmcrispr/test/modules/giveth/commands/verify-givbacks.test.ts index c256d4d1..a7082076 100644 --- a/packages/evmcrispr/test/modules/giveth/commands/verify-givbacks.test.ts +++ b/packages/evmcrispr/test/modules/giveth/commands/verify-givbacks.test.ts @@ -9,7 +9,7 @@ import { createInterpreter } from '../../../test-helpers/cas11'; import { expectThrowAsync } from '../../../test-helpers/expects'; import { findGivethCommandNode } from '../../../test-helpers/giveth'; -describe('Giveth > commands > verify-givbacks [--relayer ]', () => { +describe.only('Giveth > commands > verify-givbacks [--relayer ]', () => { let signer: Signer; before(async () => { @@ -50,6 +50,14 @@ describe('Giveth > commands > verify-givbacks [--relayer { const ipfsHash = 'QmYYpntQPV3CSeCGKUZSYK2ET6czvrwqtDQdzopoqUwws1'; const voteId = 49; @@ -62,7 +70,7 @@ describe('Giveth > commands > verify-givbacks [--relayer interpreter.interpret(), error);