Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed May 12, 2021
1 parent 690f43d commit 5060eb9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/token/ERC20/extensions/draft-ERC20Votes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const { BN, constants, expectEvent, expectRevert, time } = require('@openzeppeli
const { expect } = require('chai');
const { MAX_UINT256, ZERO_ADDRESS, ZERO_BYTES32 } = constants;

const events = require('events');
const { fromRpcSig } = require('ethereumjs-util');
const ethSigUtil = require('eth-sig-util');
const Wallet = require('ethereumjs-wallet').default;

const { promisify } = require('util');
const queue = promisify(setImmediate);

const ERC20VotesMock = artifacts.require('ERC20VotesMock');

const { EIP712Domain, domainSeparator } = require('../../../helpers/eip712');
Expand All @@ -19,12 +21,20 @@ const Delegation = [
{ name: 'expiry', type: 'uint256' },
];

async function countPendingTransactions() {
return parseInt(
await network.provider.send('eth_getBlockTransactionCountByNumber', ['pending'])
);
}

async function batchInBlock (txs) {
await network.provider.send('evm_setAutomine', [false]);

try {
const promises = txs.map(fn => fn());
await Promise.all(promises.map(p => events.once(p, 'transactionHash')));
do {
await queue();
} while (txs.length > await countPendingTransactions());
await network.provider.send('evm_mine');
const receipts = await Promise.all(promises);

Expand Down Expand Up @@ -360,9 +370,9 @@ contract('ERC20Votes', function (accounts) {
expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('0');

const [ t1, t2, t3 ] = await batchInBlock([
() => this.token.delegate(other1, { from: recipient }),
() => this.token.transfer(other2, 10, { from: recipient }),
() => this.token.transfer(other2, 10, { from: recipient }),
() => 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' ]);
Expand Down

0 comments on commit 5060eb9

Please sign in to comment.