Skip to content

Commit

Permalink
contractkit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pahor167 committed Sep 19, 2023
1 parent f306742 commit 87946ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/sdk/contractkit/src/wrappers/Governance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,30 @@ testWithGanache('Governance Wrapper', (web3: Web3) => {
expect(voteRecord?.abstainVotes).toEqBigNumber(0)
})

it('#getVoteRecord for same index proposal', async () => {
const voter = accounts[2]
await proposeFn(accounts[0])
await timeTravel(expConfig.dequeueFrequency, web3)
await governance.dequeueProposalsIfReady().sendAndWaitForReceipt()
await approveFn()
await voteFn(voter)
// expire & delete proposal
await timeTravel(expConfig.referendumStageDuration + expConfig.executionStageDuration, web3)
await approveFn()
// propose new proposal with same index
await proposeFn(accounts[0])
await timeTravel(expConfig.dequeueFrequency, web3)
await governance.dequeueProposalsIfReady().sendAndWaitForReceipt()

const yesVotes = (await governance.getVotes(proposalID))[VoteValue.Yes]
expect(yesVotes).toEqBigNumber(0)

const voteRecord = await governance.getVoteRecord(voter, proposalID)
expect(voteRecord?.yesVotes ?? 0).toEqBigNumber(0)
expect(voteRecord?.noVotes ?? 0).toEqBigNumber(0)
expect(voteRecord?.abstainVotes ?? 0).toEqBigNumber(0)
})

it('#votePartially', async () => {
await proposeFn(accounts[0])
await timeTravel(expConfig.dequeueFrequency, web3)
Expand Down
8 changes: 7 additions & 1 deletion packages/sdk/contractkit/src/wrappers/Governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,14 @@ export class GovernanceWrapper extends BaseWrapperForGoverning<Governance> {
try {
const proposalIndex = await this.getDequeueIndex(proposalID)
const res = await this.contract.methods.getVoteRecord(voter, proposalIndex).call()
const returnedProposalId = valueToBigNumber(res[0])
// Vote record is for a different historical proposal with same index
if (returnedProposalId.toString() != proposalID.toString()) {
return null
}

return {
proposalID: valueToBigNumber(res[0]),
proposalID: returnedProposalId,
value: Object.keys(VoteValue)[valueToInt(res[1])] as VoteValue,
votes: valueToBigNumber(res[2]),
yesVotes: valueToBigNumber(res[3]),
Expand Down

0 comments on commit 87946ac

Please sign in to comment.