ReentrancyGuard.test.js 1.0 KB

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