ReentrancyGuard.test.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import expectThrow from './helpers/expectThrow';
  2. const ReentrancyMock = artifacts.require('./mocks/ReentrancyMock.sol');
  3. const ReentrancyAttack = artifacts.require('./mocks/ReentrancyAttack.sol');
  4. contract('ReentrancyGuard', function (accounts) {
  5. let reentrancyMock;
  6. beforeEach(async function () {
  7. reentrancyMock = await ReentrancyMock.new();
  8. let initialCounter = await reentrancyMock.counter();
  9. assert.equal(initialCounter, 0);
  10. });
  11. it('should not allow remote callback', async function () {
  12. let 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. });