ERC20Votes.test.js 23 KB

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