ERC20Votes.test.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /* eslint-disable */
  2. const { BN, constants, expectEvent, expectRevert, time } = require('@openzeppelin/test-helpers');
  3. const { expect } = require('chai');
  4. const { MAX_UINT256, ZERO_ADDRESS, ZERO_BYTES32 } = constants;
  5. const { fromRpcSig } = require('ethereumjs-util');
  6. const ethSigUtil = require('eth-sig-util');
  7. const Wallet = require('ethereumjs-wallet').default;
  8. const { promisify } = require('util');
  9. const queue = promisify(setImmediate);
  10. const ERC20VotesMock = artifacts.require('ERC20VotesMock');
  11. const { EIP712Domain, domainSeparator } = require('../../../helpers/eip712');
  12. const Delegation = [
  13. { name: 'delegatee', type: 'address' },
  14. { name: 'nonce', type: 'uint256' },
  15. { name: 'expiry', type: 'uint256' },
  16. ];
  17. async function countPendingTransactions() {
  18. return parseInt(
  19. await network.provider.send('eth_getBlockTransactionCountByNumber', ['pending'])
  20. );
  21. }
  22. async function batchInBlock (txs) {
  23. try {
  24. // disable auto-mining
  25. await network.provider.send('evm_setAutomine', [false]);
  26. // send all transactions
  27. const promises = txs.map(fn => fn());
  28. // wait for node to have all pending transactions
  29. while (txs.length > await countPendingTransactions()) {
  30. await queue();
  31. }
  32. // mine one block
  33. await network.provider.send('evm_mine');
  34. // fetch receipts
  35. const receipts = await Promise.all(promises);
  36. // Sanity check, all tx should be in the same block
  37. const minedBlocks = new Set(receipts.map(({ receipt }) => receipt.blockNumber));
  38. expect(minedBlocks.size).to.equal(1);
  39. return receipts;
  40. } finally {
  41. // enable auto-mining
  42. await network.provider.send('evm_setAutomine', [true]);
  43. }
  44. }
  45. contract('ERC20Votes', function (accounts) {
  46. const [ holder, recipient, holderDelegatee, recipientDelegatee, other1, other2 ] = accounts;
  47. const name = 'My Token';
  48. const symbol = 'MTKN';
  49. const version = '1';
  50. const supply = new BN('10000000000000000000000000');
  51. beforeEach(async function () {
  52. this.token = await ERC20VotesMock.new(name, symbol);
  53. // We get the chain id from the contract because Ganache (used for coverage) does not return the same chain id
  54. // from within the EVM as from the JSON RPC interface.
  55. // See https://github.com/trufflesuite/ganache-core/issues/515
  56. this.chainId = await this.token.getChainId();
  57. });
  58. it('initial nonce is 0', async function () {
  59. expect(await this.token.nonces(holder)).to.be.bignumber.equal('0');
  60. });
  61. it('domain separator', async function () {
  62. expect(
  63. await this.token.DOMAIN_SEPARATOR(),
  64. ).to.equal(
  65. await domainSeparator(name, version, this.chainId, this.token.address),
  66. );
  67. });
  68. it('minting restriction', async function () {
  69. const amount = new BN('2').pow(new BN('224'));
  70. await expectRevert(
  71. this.token.mint(holder, amount),
  72. 'ERC20Votes: total supply risks overflowing votes',
  73. );
  74. });
  75. describe('set delegation', function () {
  76. describe('call', function () {
  77. it('delegation with balance', async function () {
  78. await this.token.mint(holder, supply);
  79. expect(await this.token.delegates(holder)).to.be.equal(ZERO_ADDRESS);
  80. const { receipt } = await this.token.delegate(holder, { from: holder });
  81. expectEvent(receipt, 'DelegateChanged', {
  82. delegator: holder,
  83. fromDelegate: ZERO_ADDRESS,
  84. toDelegate: holder,
  85. });
  86. expectEvent(receipt, 'DelegateVotesChanged', {
  87. delegate: holder,
  88. previousBalance: '0',
  89. newBalance: supply,
  90. });
  91. expect(await this.token.delegates(holder)).to.be.equal(holder);
  92. expect(await this.token.getVotes(holder)).to.be.bignumber.equal(supply);
  93. expect(await this.token.getPastVotes(holder, receipt.blockNumber - 1)).to.be.bignumber.equal('0');
  94. await time.advanceBlock();
  95. expect(await this.token.getPastVotes(holder, receipt.blockNumber)).to.be.bignumber.equal(supply);
  96. });
  97. it('delegation without balance', async function () {
  98. expect(await this.token.delegates(holder)).to.be.equal(ZERO_ADDRESS);
  99. const { receipt } = await this.token.delegate(holder, { from: holder });
  100. expectEvent(receipt, 'DelegateChanged', {
  101. delegator: holder,
  102. fromDelegate: ZERO_ADDRESS,
  103. toDelegate: holder,
  104. });
  105. expectEvent.notEmitted(receipt, 'DelegateVotesChanged');
  106. expect(await this.token.delegates(holder)).to.be.equal(holder);
  107. });
  108. });
  109. describe('with signature', function () {
  110. const delegator = Wallet.generate();
  111. const delegatorAddress = web3.utils.toChecksumAddress(delegator.getAddressString());
  112. const nonce = 0;
  113. const buildData = (chainId, verifyingContract, message) => ({ data: {
  114. primaryType: 'Delegation',
  115. types: { EIP712Domain, Delegation },
  116. domain: { name, version, chainId, verifyingContract },
  117. message,
  118. }});
  119. beforeEach(async function () {
  120. await this.token.mint(delegatorAddress, supply);
  121. });
  122. it('accept signed delegation', async function () {
  123. const { v, r, s } = fromRpcSig(ethSigUtil.signTypedMessage(
  124. delegator.getPrivateKey(),
  125. buildData(this.chainId, this.token.address, {
  126. delegatee: delegatorAddress,
  127. nonce,
  128. expiry: MAX_UINT256,
  129. }),
  130. ));
  131. expect(await this.token.delegates(delegatorAddress)).to.be.equal(ZERO_ADDRESS);
  132. const { receipt } = await this.token.delegateBySig(delegatorAddress, nonce, MAX_UINT256, v, r, s);
  133. expectEvent(receipt, 'DelegateChanged', {
  134. delegator: delegatorAddress,
  135. fromDelegate: ZERO_ADDRESS,
  136. toDelegate: delegatorAddress,
  137. });
  138. expectEvent(receipt, 'DelegateVotesChanged', {
  139. delegate: delegatorAddress,
  140. previousBalance: '0',
  141. newBalance: supply,
  142. });
  143. expect(await this.token.delegates(delegatorAddress)).to.be.equal(delegatorAddress);
  144. expect(await this.token.getVotes(delegatorAddress)).to.be.bignumber.equal(supply);
  145. expect(await this.token.getPastVotes(delegatorAddress, receipt.blockNumber - 1)).to.be.bignumber.equal('0');
  146. await time.advanceBlock();
  147. expect(await this.token.getPastVotes(delegatorAddress, receipt.blockNumber)).to.be.bignumber.equal(supply);
  148. });
  149. it('rejects reused signature', async function () {
  150. const { v, r, s } = fromRpcSig(ethSigUtil.signTypedMessage(
  151. delegator.getPrivateKey(),
  152. buildData(this.chainId, this.token.address, {
  153. delegatee: delegatorAddress,
  154. nonce,
  155. expiry: MAX_UINT256,
  156. }),
  157. ));
  158. await this.token.delegateBySig(delegatorAddress, nonce, MAX_UINT256, v, r, s);
  159. await expectRevert(
  160. this.token.delegateBySig(delegatorAddress, nonce, MAX_UINT256, v, r, s),
  161. 'ERC20Votes: invalid nonce',
  162. );
  163. });
  164. it('rejects bad delegatee', async function () {
  165. const { v, r, s } = fromRpcSig(ethSigUtil.signTypedMessage(
  166. delegator.getPrivateKey(),
  167. buildData(this.chainId, this.token.address, {
  168. delegatee: delegatorAddress,
  169. nonce,
  170. expiry: MAX_UINT256,
  171. }),
  172. ));
  173. const receipt = await this.token.delegateBySig(holderDelegatee, nonce, MAX_UINT256, v, r, s);
  174. const { args } = receipt.logs.find(({ event }) => event == 'DelegateChanged');
  175. expect(args.delegator).to.not.be.equal(delegatorAddress);
  176. expect(args.fromDelegate).to.be.equal(ZERO_ADDRESS);
  177. expect(args.toDelegate).to.be.equal(holderDelegatee);
  178. });
  179. it('rejects bad nonce', async function () {
  180. const { v, r, s } = fromRpcSig(ethSigUtil.signTypedMessage(
  181. delegator.getPrivateKey(),
  182. buildData(this.chainId, this.token.address, {
  183. delegatee: delegatorAddress,
  184. nonce,
  185. expiry: MAX_UINT256,
  186. }),
  187. ));
  188. await expectRevert(
  189. this.token.delegateBySig(delegatorAddress, nonce + 1, MAX_UINT256, v, r, s),
  190. 'ERC20Votes: invalid nonce',
  191. );
  192. });
  193. it('rejects expired permit', async function () {
  194. const expiry = (await time.latest()) - time.duration.weeks(1);
  195. const { v, r, s } = fromRpcSig(ethSigUtil.signTypedMessage(
  196. delegator.getPrivateKey(),
  197. buildData(this.chainId, this.token.address, {
  198. delegatee: delegatorAddress,
  199. nonce,
  200. expiry,
  201. }),
  202. ));
  203. await expectRevert(
  204. this.token.delegateBySig(delegatorAddress, nonce, expiry, v, r, s),
  205. 'ERC20Votes: signature expired',
  206. );
  207. });
  208. });
  209. });
  210. describe('change delegation', function () {
  211. beforeEach(async function () {
  212. await this.token.mint(holder, supply);
  213. await this.token.delegate(holder, { from: holder });
  214. });
  215. it('call', async function () {
  216. expect(await this.token.delegates(holder)).to.be.equal(holder);
  217. const { receipt } = await this.token.delegate(holderDelegatee, { from: holder });
  218. expectEvent(receipt, 'DelegateChanged', {
  219. delegator: holder,
  220. fromDelegate: holder,
  221. toDelegate: holderDelegatee,
  222. });
  223. expectEvent(receipt, 'DelegateVotesChanged', {
  224. delegate: holder,
  225. previousBalance: supply,
  226. newBalance: '0',
  227. });
  228. expectEvent(receipt, 'DelegateVotesChanged', {
  229. delegate: holderDelegatee,
  230. previousBalance: '0',
  231. newBalance: supply,
  232. });
  233. expect(await this.token.delegates(holder)).to.be.equal(holderDelegatee);
  234. expect(await this.token.getVotes(holder)).to.be.bignumber.equal('0');
  235. expect(await this.token.getVotes(holderDelegatee)).to.be.bignumber.equal(supply);
  236. expect(await this.token.getPastVotes(holder, receipt.blockNumber - 1)).to.be.bignumber.equal(supply);
  237. expect(await this.token.getPastVotes(holderDelegatee, receipt.blockNumber - 1)).to.be.bignumber.equal('0');
  238. await time.advanceBlock();
  239. expect(await this.token.getPastVotes(holder, receipt.blockNumber)).to.be.bignumber.equal('0');
  240. expect(await this.token.getPastVotes(holderDelegatee, receipt.blockNumber)).to.be.bignumber.equal(supply);
  241. });
  242. });
  243. describe('transfers', function () {
  244. beforeEach(async function () {
  245. await this.token.mint(holder, supply);
  246. });
  247. it('no delegation', async function () {
  248. const { receipt } = await this.token.transfer(recipient, 1, { from: holder });
  249. expectEvent(receipt, 'Transfer', { from: holder, to: recipient, value: '1' });
  250. expectEvent.notEmitted(receipt, 'DelegateVotesChanged');
  251. this.holderVotes = '0';
  252. this.recipientVotes = '0';
  253. });
  254. it('sender delegation', async function () {
  255. await this.token.delegate(holder, { from: holder });
  256. const { receipt } = await this.token.transfer(recipient, 1, { from: holder });
  257. expectEvent(receipt, 'Transfer', { from: holder, to: recipient, value: '1' });
  258. expectEvent(receipt, 'DelegateVotesChanged', { delegate: holder, previousBalance: supply, newBalance: supply.subn(1) });
  259. const { logIndex: transferLogIndex } = receipt.logs.find(({ event }) => event == 'Transfer');
  260. expect(receipt.logs.filter(({ event }) => event == 'DelegateVotesChanged').every(({ logIndex }) => transferLogIndex < logIndex)).to.be.equal(true);
  261. this.holderVotes = supply.subn(1);
  262. this.recipientVotes = '0';
  263. });
  264. it('receiver delegation', async function () {
  265. await this.token.delegate(recipient, { from: recipient });
  266. const { receipt } = await this.token.transfer(recipient, 1, { from: holder });
  267. expectEvent(receipt, 'Transfer', { from: holder, to: recipient, value: '1' });
  268. expectEvent(receipt, 'DelegateVotesChanged', { delegate: recipient, previousBalance: '0', newBalance: '1' });
  269. const { logIndex: transferLogIndex } = receipt.logs.find(({ event }) => event == 'Transfer');
  270. expect(receipt.logs.filter(({ event }) => event == 'DelegateVotesChanged').every(({ logIndex }) => transferLogIndex < logIndex)).to.be.equal(true);
  271. this.holderVotes = '0';
  272. this.recipientVotes = '1';
  273. });
  274. it('full delegation', async function () {
  275. await this.token.delegate(holder, { from: holder });
  276. await this.token.delegate(recipient, { from: recipient });
  277. const { receipt } = await this.token.transfer(recipient, 1, { from: holder });
  278. expectEvent(receipt, 'Transfer', { from: holder, to: recipient, value: '1' });
  279. expectEvent(receipt, 'DelegateVotesChanged', { delegate: holder, previousBalance: supply, newBalance: supply.subn(1) });
  280. expectEvent(receipt, 'DelegateVotesChanged', { delegate: recipient, previousBalance: '0', newBalance: '1' });
  281. const { logIndex: transferLogIndex } = receipt.logs.find(({ event }) => event == 'Transfer');
  282. expect(receipt.logs.filter(({ event }) => event == 'DelegateVotesChanged').every(({ logIndex }) => transferLogIndex < logIndex)).to.be.equal(true);
  283. this.holderVotes = supply.subn(1);
  284. this.recipientVotes = '1';
  285. });
  286. afterEach(async function () {
  287. expect(await this.token.getVotes(holder)).to.be.bignumber.equal(this.holderVotes);
  288. expect(await this.token.getVotes(recipient)).to.be.bignumber.equal(this.recipientVotes);
  289. // need to advance 2 blocks to see the effect of a transfer on "getPastVotes"
  290. const blockNumber = await time.latestBlock();
  291. await time.advanceBlock();
  292. expect(await this.token.getPastVotes(holder, blockNumber)).to.be.bignumber.equal(this.holderVotes);
  293. expect(await this.token.getPastVotes(recipient, blockNumber)).to.be.bignumber.equal(this.recipientVotes);
  294. });
  295. });
  296. // The following tests are a adaptation of https://github.com/compound-finance/compound-protocol/blob/master/tests/Governance/CompTest.js.
  297. describe('Compound test suite', function () {
  298. beforeEach(async function () {
  299. await this.token.mint(holder, supply);
  300. });
  301. describe('balanceOf', function () {
  302. it('grants to initial account', async function () {
  303. expect(await this.token.balanceOf(holder)).to.be.bignumber.equal('10000000000000000000000000');
  304. });
  305. });
  306. describe('numCheckpoints', function () {
  307. it('returns the number of checkpoints for a delegate', async function () {
  308. await this.token.transfer(recipient, '100', { from: holder }); //give an account a few tokens for readability
  309. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('0');
  310. const t1 = await this.token.delegate(other1, { from: recipient });
  311. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('1');
  312. const t2 = await this.token.transfer(other2, 10, { from: recipient });
  313. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('2');
  314. const t3 = await this.token.transfer(other2, 10, { from: recipient });
  315. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('3');
  316. const t4 = await this.token.transfer(recipient, 20, { from: holder });
  317. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('4');
  318. expect(await this.token.checkpoints(other1, 0)).to.be.deep.equal([ t1.receipt.blockNumber.toString(), '100' ]);
  319. expect(await this.token.checkpoints(other1, 1)).to.be.deep.equal([ t2.receipt.blockNumber.toString(), '90' ]);
  320. expect(await this.token.checkpoints(other1, 2)).to.be.deep.equal([ t3.receipt.blockNumber.toString(), '80' ]);
  321. expect(await this.token.checkpoints(other1, 3)).to.be.deep.equal([ t4.receipt.blockNumber.toString(), '100' ]);
  322. await time.advanceBlock();
  323. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber)).to.be.bignumber.equal('100');
  324. expect(await this.token.getPastVotes(other1, t2.receipt.blockNumber)).to.be.bignumber.equal('90');
  325. expect(await this.token.getPastVotes(other1, t3.receipt.blockNumber)).to.be.bignumber.equal('80');
  326. expect(await this.token.getPastVotes(other1, t4.receipt.blockNumber)).to.be.bignumber.equal('100');
  327. });
  328. it('does not add more than one checkpoint in a block', async function () {
  329. await this.token.transfer(recipient, '100', { from: holder });
  330. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('0');
  331. const [ t1, t2, t3 ] = await batchInBlock([
  332. () => this.token.delegate(other1, { from: recipient, gas: 100000 }),
  333. () => this.token.transfer(other2, 10, { from: recipient, gas: 100000 }),
  334. () => this.token.transfer(other2, 10, { from: recipient, gas: 100000 }),
  335. ]);
  336. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('1');
  337. expect(await this.token.checkpoints(other1, 0)).to.be.deep.equal([ t1.receipt.blockNumber.toString(), '80' ]);
  338. // expectReve(await this.token.checkpoints(other1, 1)).to.be.deep.equal([ '0', '0' ]); // Reverts due to array overflow check
  339. // expect(await this.token.checkpoints(other1, 2)).to.be.deep.equal([ '0', '0' ]); // Reverts due to array overflow check
  340. const t4 = await this.token.transfer(recipient, 20, { from: holder });
  341. expect(await this.token.numCheckpoints(other1)).to.be.bignumber.equal('2');
  342. expect(await this.token.checkpoints(other1, 1)).to.be.deep.equal([ t4.receipt.blockNumber.toString(), '100' ]);
  343. });
  344. });
  345. describe('getPastVotes', function () {
  346. it('reverts if block number >= current block', async function () {
  347. await expectRevert(
  348. this.token.getPastVotes(other1, 5e10),
  349. 'ERC20Votes: block not yet mined',
  350. );
  351. });
  352. it('returns 0 if there are no checkpoints', async function () {
  353. expect(await this.token.getPastVotes(other1, 0)).to.be.bignumber.equal('0');
  354. });
  355. it('returns the latest block if >= last checkpoint block', async function () {
  356. const t1 = await this.token.delegate(other1, { from: holder });
  357. await time.advanceBlock();
  358. await time.advanceBlock();
  359. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber)).to.be.bignumber.equal('10000000000000000000000000');
  360. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber + 1)).to.be.bignumber.equal('10000000000000000000000000');
  361. });
  362. it('returns zero if < first checkpoint block', async function () {
  363. await time.advanceBlock();
  364. const t1 = await this.token.delegate(other1, { from: holder });
  365. await time.advanceBlock();
  366. await time.advanceBlock();
  367. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber - 1)).to.be.bignumber.equal('0');
  368. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber + 1)).to.be.bignumber.equal('10000000000000000000000000');
  369. });
  370. it('generally returns the voting balance at the appropriate checkpoint', async function () {
  371. const t1 = await this.token.delegate(other1, { from: holder });
  372. await time.advanceBlock();
  373. await time.advanceBlock();
  374. const t2 = await this.token.transfer(other2, 10, { from: holder });
  375. await time.advanceBlock();
  376. await time.advanceBlock();
  377. const t3 = await this.token.transfer(other2, 10, { from: holder });
  378. await time.advanceBlock();
  379. await time.advanceBlock();
  380. const t4 = await this.token.transfer(holder, 20, { from: other2 });
  381. await time.advanceBlock();
  382. await time.advanceBlock();
  383. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber - 1)).to.be.bignumber.equal('0');
  384. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber)).to.be.bignumber.equal('10000000000000000000000000');
  385. expect(await this.token.getPastVotes(other1, t1.receipt.blockNumber + 1)).to.be.bignumber.equal('10000000000000000000000000');
  386. expect(await this.token.getPastVotes(other1, t2.receipt.blockNumber)).to.be.bignumber.equal('9999999999999999999999990');
  387. expect(await this.token.getPastVotes(other1, t2.receipt.blockNumber + 1)).to.be.bignumber.equal('9999999999999999999999990');
  388. expect(await this.token.getPastVotes(other1, t3.receipt.blockNumber)).to.be.bignumber.equal('9999999999999999999999980');
  389. expect(await this.token.getPastVotes(other1, t3.receipt.blockNumber + 1)).to.be.bignumber.equal('9999999999999999999999980');
  390. expect(await this.token.getPastVotes(other1, t4.receipt.blockNumber)).to.be.bignumber.equal('10000000000000000000000000');
  391. expect(await this.token.getPastVotes(other1, t4.receipt.blockNumber + 1)).to.be.bignumber.equal('10000000000000000000000000');
  392. });
  393. });
  394. });
  395. describe('getPastTotalSupply', function () {
  396. beforeEach(async function () {
  397. await this.token.delegate(holder, { from: holder });
  398. });
  399. it('reverts if block number >= current block', async function () {
  400. await expectRevert(
  401. this.token.getPastTotalSupply(5e10),
  402. 'ERC20Votes: block not yet mined',
  403. );
  404. });
  405. it('returns 0 if there are no checkpoints', async function () {
  406. expect(await this.token.getPastTotalSupply(0)).to.be.bignumber.equal('0');
  407. });
  408. it('returns the latest block if >= last checkpoint block', async function () {
  409. t1 = await this.token.mint(holder, supply);
  410. await time.advanceBlock();
  411. await time.advanceBlock();
  412. expect(await this.token.getPastTotalSupply(t1.receipt.blockNumber)).to.be.bignumber.equal(supply);
  413. expect(await this.token.getPastTotalSupply(t1.receipt.blockNumber + 1)).to.be.bignumber.equal(supply);
  414. });
  415. it('returns zero if < first checkpoint block', async function () {
  416. await time.advanceBlock();
  417. const t1 = await this.token.mint(holder, supply);
  418. await time.advanceBlock();
  419. await time.advanceBlock();
  420. expect(await this.token.getPastTotalSupply(t1.receipt.blockNumber - 1)).to.be.bignumber.equal('0');
  421. expect(await this.token.getPastTotalSupply(t1.receipt.blockNumber + 1)).to.be.bignumber.equal('10000000000000000000000000');
  422. });
  423. it('generally returns the voting balance at the appropriate checkpoint', async function () {
  424. const t1 = await this.token.mint(holder, supply);
  425. await time.advanceBlock();
  426. await time.advanceBlock();
  427. const t2 = await this.token.burn(holder, 10);
  428. await time.advanceBlock();
  429. await time.advanceBlock();
  430. const t3 = await this.token.burn(holder, 10);
  431. await time.advanceBlock();
  432. await time.advanceBlock();
  433. const t4 = await this.token.mint(holder, 20);
  434. await time.advanceBlock();
  435. await time.advanceBlock();
  436. expect(await this.token.getPastTotalSupply(t1.receipt.blockNumber - 1)).to.be.bignumber.equal('0');
  437. expect(await this.token.getPastTotalSupply(t1.receipt.blockNumber)).to.be.bignumber.equal('10000000000000000000000000');
  438. expect(await this.token.getPastTotalSupply(t1.receipt.blockNumber + 1)).to.be.bignumber.equal('10000000000000000000000000');
  439. expect(await this.token.getPastTotalSupply(t2.receipt.blockNumber)).to.be.bignumber.equal('9999999999999999999999990');
  440. expect(await this.token.getPastTotalSupply(t2.receipt.blockNumber + 1)).to.be.bignumber.equal('9999999999999999999999990');
  441. expect(await this.token.getPastTotalSupply(t3.receipt.blockNumber)).to.be.bignumber.equal('9999999999999999999999980');
  442. expect(await this.token.getPastTotalSupply(t3.receipt.blockNumber + 1)).to.be.bignumber.equal('9999999999999999999999980');
  443. expect(await this.token.getPastTotalSupply(t4.receipt.blockNumber)).to.be.bignumber.equal('10000000000000000000000000');
  444. expect(await this.token.getPastTotalSupply(t4.receipt.blockNumber + 1)).to.be.bignumber.equal('10000000000000000000000000');
  445. });
  446. });
  447. });