ReentrancyGuard.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. const { expectThrow } = require('../helpers/expectThrow');
  2. const ReentrancyMock = artifacts.require('ReentrancyMock');
  3. const ReentrancyAttack = artifacts.require('ReentrancyAttack');
  4. const BigNumber = web3.BigNumber;
  5. require('chai')
  6. .use(require('chai-bignumber')(BigNumber))
  7. .should();
  8. contract('ReentrancyGuard', function () {
  9. beforeEach(async function () {
  10. this.reentrancyMock = await ReentrancyMock.new();
  11. (await this.reentrancyMock.counter()).should.be.bignumber.equal(0);
  12. });
  13. it('should not allow remote callback', async function () {
  14. const attacker = await ReentrancyAttack.new();
  15. await expectThrow(this.reentrancyMock.countAndCall(attacker.address));
  16. });
  17. // The following are more side-effects than intended behavior:
  18. // I put them here as documentation, and to monitor any changes
  19. // in the side-effects.
  20. it('should not allow local recursion', async function () {
  21. await expectThrow(this.reentrancyMock.countLocalRecursive(10));
  22. });
  23. it('should not allow indirect local recursion', async function () {
  24. await expectThrow(this.reentrancyMock.countThisRecursive(10));
  25. });
  26. });