ReentrancyGuard.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. let reentrancyMock;
  10. beforeEach(async function () {
  11. reentrancyMock = await ReentrancyMock.new();
  12. const initialCounter = await reentrancyMock.counter();
  13. initialCounter.should.be.bignumber.equal(0);
  14. });
  15. it('should not allow remote callback', async function () {
  16. const attacker = await ReentrancyAttack.new();
  17. await expectThrow(reentrancyMock.countAndCall(attacker.address));
  18. });
  19. // The following are more side-effects than intended behavior:
  20. // I put them here as documentation, and to monitor any changes
  21. // in the side-effects.
  22. it('should not allow local recursion', async function () {
  23. await expectThrow(reentrancyMock.countLocalRecursive(10));
  24. });
  25. it('should not allow indirect local recursion', async function () {
  26. await expectThrow(reentrancyMock.countThisRecursive(10));
  27. });
  28. });