Make ERC20Votes independent from ERC20Permit (#3816)
Co-authored-by: Francisco <frangio.1@gmail.com>
This commit is contained in:
@ -3,9 +3,6 @@
|
||||
const { BN, expectEvent, time } = require('@openzeppelin/test-helpers');
|
||||
const { expect } = require('chai');
|
||||
|
||||
const { promisify } = require('util');
|
||||
const queue = promisify(setImmediate);
|
||||
|
||||
const ERC721VotesMock = artifacts.require('ERC721VotesMock');
|
||||
|
||||
const { shouldBehaveLikeVotes } = require('../../../governance/utils/Votes.behavior');
|
||||
@ -23,18 +20,18 @@ contract('ERC721Votes', function (accounts) {
|
||||
// See https://github.com/trufflesuite/ganache-core/issues/515
|
||||
this.chainId = await this.votes.getChainId();
|
||||
|
||||
this.NFT0 = new BN('10000000000000000000000000');
|
||||
this.NFT1 = new BN('10');
|
||||
this.NFT2 = new BN('20');
|
||||
this.NFT3 = new BN('30');
|
||||
this.token0 = new BN('10000000000000000000000000');
|
||||
this.token1 = new BN('10');
|
||||
this.token2 = new BN('20');
|
||||
this.token3 = new BN('30');
|
||||
});
|
||||
|
||||
describe('balanceOf', function () {
|
||||
beforeEach(async function () {
|
||||
await this.votes.mint(account1, this.NFT0);
|
||||
await this.votes.mint(account1, this.NFT1);
|
||||
await this.votes.mint(account1, this.NFT2);
|
||||
await this.votes.mint(account1, this.NFT3);
|
||||
await this.votes.mint(account1, this.token0);
|
||||
await this.votes.mint(account1, this.token1);
|
||||
await this.votes.mint(account1, this.token2);
|
||||
await this.votes.mint(account1, this.token3);
|
||||
});
|
||||
|
||||
it('grants to initial account', async function () {
|
||||
@ -44,12 +41,12 @@ contract('ERC721Votes', function (accounts) {
|
||||
|
||||
describe('transfers', function () {
|
||||
beforeEach(async function () {
|
||||
await this.votes.mint(account1, this.NFT0);
|
||||
await this.votes.mint(account1, this.token0);
|
||||
});
|
||||
|
||||
it('no delegation', async function () {
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.NFT0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.NFT0 });
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.token0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.token0 });
|
||||
expectEvent.notEmitted(receipt, 'DelegateVotesChanged');
|
||||
|
||||
this.account1Votes = '0';
|
||||
@ -59,8 +56,8 @@ contract('ERC721Votes', function (accounts) {
|
||||
it('sender delegation', async function () {
|
||||
await this.votes.delegate(account1, { from: account1 });
|
||||
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.NFT0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.NFT0 });
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.token0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.token0 });
|
||||
expectEvent(receipt, 'DelegateVotesChanged', { delegate: account1, previousBalance: '1', newBalance: '0' });
|
||||
|
||||
const { logIndex: transferLogIndex } = receipt.logs.find(({ event }) => event == 'Transfer');
|
||||
@ -73,8 +70,8 @@ contract('ERC721Votes', function (accounts) {
|
||||
it('receiver delegation', async function () {
|
||||
await this.votes.delegate(account2, { from: account2 });
|
||||
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.NFT0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.NFT0 });
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.token0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.token0 });
|
||||
expectEvent(receipt, 'DelegateVotesChanged', { delegate: account2, previousBalance: '0', newBalance: '1' });
|
||||
|
||||
const { logIndex: transferLogIndex } = receipt.logs.find(({ event }) => event == 'Transfer');
|
||||
@ -88,8 +85,8 @@ contract('ERC721Votes', function (accounts) {
|
||||
await this.votes.delegate(account1, { from: account1 });
|
||||
await this.votes.delegate(account2, { from: account2 });
|
||||
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.NFT0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.NFT0 });
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.token0, { from: account1 });
|
||||
expectEvent(receipt, 'Transfer', { from: account1, to: account2, tokenId: this.token0 });
|
||||
expectEvent(receipt, 'DelegateVotesChanged', { delegate: account1, previousBalance: '1', newBalance: '0'});
|
||||
expectEvent(receipt, 'DelegateVotesChanged', { delegate: account2, previousBalance: '0', newBalance: '1' });
|
||||
|
||||
@ -103,7 +100,7 @@ contract('ERC721Votes', function (accounts) {
|
||||
it('returns the same total supply on transfers', async function () {
|
||||
await this.votes.delegate(account1, { from: account1 });
|
||||
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.NFT0, { from: account1 });
|
||||
const { receipt } = await this.votes.transferFrom(account1, account2, this.token0, { from: account1 });
|
||||
|
||||
await time.advanceBlock();
|
||||
await time.advanceBlock();
|
||||
@ -116,22 +113,22 @@ contract('ERC721Votes', function (accounts) {
|
||||
});
|
||||
|
||||
it('generally returns the voting balance at the appropriate checkpoint', async function () {
|
||||
await this.votes.mint(account1, this.NFT1);
|
||||
await this.votes.mint(account1, this.NFT2);
|
||||
await this.votes.mint(account1, this.NFT3);
|
||||
await this.votes.mint(account1, this.token1);
|
||||
await this.votes.mint(account1, this.token2);
|
||||
await this.votes.mint(account1, this.token3);
|
||||
|
||||
const total = await this.votes.balanceOf(account1);
|
||||
|
||||
const t1 = await this.votes.delegate(other1, { from: account1 });
|
||||
await time.advanceBlock();
|
||||
await time.advanceBlock();
|
||||
const t2 = await this.votes.transferFrom(account1, other2, this.NFT0, { from: account1 });
|
||||
const t2 = await this.votes.transferFrom(account1, other2, this.token0, { from: account1 });
|
||||
await time.advanceBlock();
|
||||
await time.advanceBlock();
|
||||
const t3 = await this.votes.transferFrom(account1, other2, this.NFT2, { from: account1 });
|
||||
const t3 = await this.votes.transferFrom(account1, other2, this.token2, { from: account1 });
|
||||
await time.advanceBlock();
|
||||
await time.advanceBlock();
|
||||
const t4 = await this.votes.transferFrom(other2, account1, this.NFT2, { from: other2 });
|
||||
const t4 = await this.votes.transferFrom(other2, account1, this.token2, { from: other2 });
|
||||
await time.advanceBlock();
|
||||
await time.advanceBlock();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user