ERC20Votes.test.js 23 KB

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