ReentrancyGuard.js 1.1 KB

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