Optimize votes lookups for recent checkpoints (#3673)

This commit is contained in:
Francisco
2022-09-04 17:48:26 -03:00
committed by GitHub
parent a60ae0f18b
commit e09ccd1449
9 changed files with 96 additions and 104 deletions

View File

@ -56,6 +56,19 @@ contract('ERC20Votes', function (accounts) {
);
});
it('recent checkpoints', async function () {
await this.token.delegate(holder, { from: holder });
for (let i = 0; i < 6; i++) {
await this.token.mint(holder, 1);
}
const block = await web3.eth.getBlockNumber();
expect(await this.token.numCheckpoints(holder)).to.be.bignumber.equal('6');
// recent
expect(await this.token.getPastVotes(holder, block - 1)).to.be.bignumber.equal('5');
// non-recent
expect(await this.token.getPastVotes(holder, block - 6)).to.be.bignumber.equal('0');
});
describe('set delegation', function () {
describe('call', function () {
it('delegation with balance', async function () {