ReentrancyGuard.test.js 1.0 KB

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