Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f28ede6
Add Nonces contract
JulissaDantes Nov 14, 2022
1931d64
Remove permit from erc20votes
JulissaDantes Nov 15, 2022
cc25b3f
Update ERC20Permit contract
JulissaDantes Nov 15, 2022
39bd173
Update Changelog
JulissaDantes Nov 15, 2022
5df3792
Add Nonces dcumentation
JulissaDantes Nov 15, 2022
b9c425f
Update changelog with PR number
JulissaDantes Nov 16, 2022
485a322
Use Votes for ERC20Votes
JulissaDantes Nov 17, 2022
f40bf1c
Remove duplicate tests
JulissaDantes Nov 21, 2022
1c07a94
Fix Votes tests
JulissaDantes Nov 21, 2022
f4baabe
update changelog
JulissaDantes Nov 22, 2022
a7ec549
Update CHANGELOG.md
JulissaDantes Nov 25, 2022
8fab231
Merge branch 'next-v5.0' into refactor/erc20-votes
JulissaDantes Nov 25, 2022
5202e0d
Add test case
JulissaDantes Nov 25, 2022
0a2a857
Update test
JulissaDantes Nov 25, 2022
c140d72
Merge branch 'refactor/erc20-votes' of https://github.com/JulissaDant…
JulissaDantes Nov 25, 2022
cffa45c
Update tests
JulissaDantes Nov 25, 2022
f881aad
Merge branch 'next-v5.0' into refactor/erc20-votes
JulissaDantes Nov 25, 2022
390f04a
Add numCheckpoints
JulissaDantes Nov 28, 2022
b41574c
Add tests to ERC20VotesComp
JulissaDantes Nov 28, 2022
4cda6a0
Update template
JulissaDantes Nov 28, 2022
c2a9537
Update contracts/token/ERC20/extensions/ERC20Votes.sol
JulissaDantes Nov 29, 2022
6adfc96
Update contracts/token/ERC20/extensions/ERC20Votes.sol
JulissaDantes Nov 29, 2022
e31342b
Update contracts/utils/Checkpoints.sol
JulissaDantes Nov 29, 2022
3f001ad
update template
JulissaDantes Nov 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests to ERC20VotesComp
  • Loading branch information
JulissaDantes committed Nov 28, 2022
commit b41574c5baace808c3fd7f49e2141130b98b2506
50 changes: 50 additions & 0 deletions test/token/ERC20/extensions/ERC20VotesComp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { BN, constants, expectEvent, expectRevert, time } = require('@openzeppeli
const { expect } = require('chai');
const { MAX_UINT256, ZERO_ADDRESS } = constants;

const { batchInBlock } = require('../../../helpers/txpool');
const { shouldBehaveLikeVotes } = require('../../../governance/utils/Votes.behavior');
const { fromRpcSig } = require('ethereumjs-util');
const ethSigUtil = require('eth-sig-util');
Expand Down Expand Up @@ -325,6 +326,55 @@ contract('ERC20VotesComp', function (accounts) {
});
});

describe('numCheckpoints', function () {
it('returns the number of checkpoints for a delegate', async function () {
await this.token.transfer(recipient, '100', { from: holder }); //give an account a few tokens for readability
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('0');

const t1 = await this.token.delegate(other1, { from: recipient });
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('1');

const t2 = await this.token.transfer(other2, 10, { from: recipient });
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('2');

const t3 = await this.token.transfer(other2, 10, { from: recipient });
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('3');

const t4 = await this.token.transfer(recipient, 20, { from: holder });
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('4');

expect(await this.token.checkpoints(other1, 0)).to.be.deep.equal([ t1.receipt.blockNumber.toString(), '100' ]);
expect(await this.token.checkpoints(other1, 1)).to.be.deep.equal([ t2.receipt.blockNumber.toString(), '90' ]);
expect(await this.token.checkpoints(other1, 2)).to.be.deep.equal([ t3.receipt.blockNumber.toString(), '80' ]);
expect(await this.token.checkpoints(other1, 3)).to.be.deep.equal([ t4.receipt.blockNumber.toString(), '100' ]);

await time.advanceBlock();
expect(await this.token.getPriorVotes(other1, t1.receipt.blockNumber)).to.be.bignumber.equal('100');
expect(await this.token.getPriorVotes(other1, t2.receipt.blockNumber)).to.be.bignumber.equal('90');
expect(await this.token.getPriorVotes(other1, t3.receipt.blockNumber)).to.be.bignumber.equal('80');
expect(await this.token.getPriorVotes(other1, t4.receipt.blockNumber)).to.be.bignumber.equal('100');
});

it('does not add more than one checkpoint in a block', async function () {
await this.token.transfer(recipient, '100', { from: holder });
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('0');

const [ t1, t2, t3 ] = await batchInBlock([
() => this.token.delegate(other1, { from: recipient, gas: 100000 }),
() => this.token.transfer(other2, 10, { from: recipient, gas: 100000 }),
() => this.token.transfer(other2, 10, { from: recipient, gas: 100000 }),
]);
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('1');
expect(await this.token.checkpoints(other1, 0)).to.be.deep.equal([ t1.receipt.blockNumber.toString(), '80' ]);
// expectReve(await this.token.checkpoints(other1, 1)).to.be.deep.equal([ '0', '0' ]); // Reverts due to array overflow check
// expect(await this.token.checkpoints(other1, 2)).to.be.deep.equal([ '0', '0' ]); // Reverts due to array overflow check

const t4 = await this.token.transfer(recipient, 20, { from: holder });
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('2');
expect(await this.token.checkpoints(other1, 1)).to.be.deep.equal([ t4.receipt.blockNumber.toString(), '100' ]);
});
});

describe('getPriorVotes', function () {
it('reverts if block number >= current block', async function () {
await expectRevert(
Expand Down