ReentrancyGuard.test.js 1.1 KB

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