Skip to content

Commit

Permalink
Fix verify-givbacks command
Browse files Browse the repository at this point in the history
  • Loading branch information
sembrestels committed Aug 17, 2023
1 parent 9d91d67 commit 15b7d65
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/evmcrispr/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const config: HardhatUserConfig = {
chainId: 100,
forking: {
url: ARCHIVE_NODE_ENDPOINT,
blockNumber: 24_730_000,
blockNumber: 29509000,
},
},
},
Expand Down
54 changes: 37 additions & 17 deletions packages/evmcrispr/src/modules/giveth/commands/verify-givbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export const verifyGivbacks: ICommand<Giveth> = {
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(
Expand All @@ -73,31 +77,47 @@ export const verifyGivbacks: ICommand<Giveth> = {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ipfsHash> <voteId> [--relayer <relayer>]', () => {
describe.only('Giveth > commands > verify-givbacks <ipfsHash> <voteId> [--relayer <relayer>]', () => {
let signer: Signer;

before(async () => {
Expand Down Expand Up @@ -50,6 +50,14 @@ describe('Giveth > commands > verify-givbacks <ipfsHash> <voteId> [--relayer <re
};

it('should return a correct verify-givbacks action', testVerifyGivbacks());
it(
'should return a correct verify-givbacks action with multiple batches',
testVerifyGivbacks(
defaultRelayerAddr,
'QmUz2rm8wDV5ZWNjwehWLEoUoviXwGapgYokmfqEuy4nW9',
131,
),
);
it('should fail when hash do not match the vote', async () => {
const ipfsHash = 'QmYYpntQPV3CSeCGKUZSYK2ET6czvrwqtDQdzopoqUwws1';
const voteId = 49;
Expand All @@ -62,7 +70,7 @@ describe('Giveth > commands > verify-givbacks <ipfsHash> <voteId> [--relayer <re
const c = findGivethCommandNode(interpreter.ast, 'verify-givbacks')!;
const error = new CommandError(
c,
`Vote script does not match script in ${ipfsHash}`,
`Vote script does not match script in ${ipfsHash}. The IPFS hash do not correspond to the one in the script.`,
);

await expectThrowAsync(() => interpreter.interpret(), error);
Expand Down

0 comments on commit 15b7d65

Please sign in to comment.