-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (67 loc) · 2.31 KB
/
index.js
File metadata and controls
75 lines (67 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const ethers = require("ethers");
const { expect } = require("chai");
const proposal = require(`./proposalSpecs/${process.env.PROPOSAL}.json`);
const providerUrl = process.env.PROVIDER_URL;
const provider = providerUrl
? new ethers.providers.JsonRpcProvider(providerUrl)
: ethers.providers.getDefaultProvider("mainnet");
console.log(JSON.stringify(proposal, null, 2));
const votingAppAddress = "0x05811ad31cbd5905e4e1427482713e3fb04a4c05";
const agentAppAddress = "0xe7af7c5982e073ac6525a34821fe1b3e8e432099";
// Constants
const executeSignature = encodeFunctionSignature(
"execute(address,uint256,bytes)"
);
const votingAppAbi = [
"function getVote(uint256 _voteId) public view returns (bool open, bool executed, uint64 startDate, uint64 snapshotBlock, uint64 supportRequired, uint64 minAcceptQuorum, uint256 yea, uint256 nay, uint256 votingPower, bytes script)",
];
function encodeFunctionSignature(functionSignature) {
return ethers.utils.hexDataSlice(
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(functionSignature)),
0,
4
);
}
async function verifyProposal() {
const parameterTypes = proposal.specs.targetFunction
.substring(
proposal.specs.targetFunction.indexOf("(") + 1,
proposal.specs.targetFunction.indexOf(")")
)
.split(",");
const encodedParameters = ethers.utils.defaultAbiCoder.encode(
parameterTypes,
proposal.specs.parameters
);
const callData =
executeSignature +
ethers.utils.defaultAbiCoder
.encode(
["address", "uint256", "bytes"],
[
proposal.specs.targetContractAddress,
proposal.specs.value,
encodeFunctionSignature(proposal.specs.targetFunction) +
encodedParameters.substring(2),
]
)
.substring(2);
const callDataLengthInBytes = ethers.utils.hexZeroPad(
ethers.BigNumber.from(callData.substring(2).length / 2).toHexString(),
4
);
const evmScript =
"0x00000001" +
agentAppAddress.substring(2) +
callDataLengthInBytes.substring(2) +
callData.substring(2);
const votingApp = new ethers.Contract(
votingAppAddress,
votingAppAbi,
provider
);
const vote = await votingApp.getVote(proposal.specs.proposalNo);
expect(vote.script).to.equal(evmScript);
console.log(`Proposal #${process.env.PROPOSAL} is verified!`);
}
verifyProposal();