committed by
Leo Arias
parent
0678f67289
commit
2f3f0d3c8a
20
test/utils/Address.test.js
Normal file
20
test/utils/Address.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const AddressImpl = artifacts.require('AddressImpl');
|
||||
const SimpleToken = artifacts.require('SimpleToken');
|
||||
|
||||
require('chai')
|
||||
.should();
|
||||
|
||||
contract('Address', function ([_, anyone]) {
|
||||
beforeEach(async function () {
|
||||
this.mock = await AddressImpl.new();
|
||||
});
|
||||
|
||||
it('should return false for account address', async function () {
|
||||
(await this.mock.isContract(anyone)).should.equal(false);
|
||||
});
|
||||
|
||||
it('should return true for contract address', async function () {
|
||||
const contract = await SimpleToken.new();
|
||||
(await this.mock.isContract(contract.address)).should.equal(true);
|
||||
});
|
||||
});
|
||||
36
test/utils/ReentrancyGuard.test.js
Normal file
36
test/utils/ReentrancyGuard.test.js
Normal file
@ -0,0 +1,36 @@
|
||||
const { expectThrow } = require('./helpers/expectThrow');
|
||||
const ReentrancyMock = artifacts.require('ReentrancyMock');
|
||||
const ReentrancyAttack = artifacts.require('ReentrancyAttack');
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
require('chai')
|
||||
.use(require('chai-bignumber')(BigNumber))
|
||||
.should();
|
||||
|
||||
contract('ReentrancyGuard', function () {
|
||||
let reentrancyMock;
|
||||
|
||||
beforeEach(async function () {
|
||||
reentrancyMock = await ReentrancyMock.new();
|
||||
const initialCounter = await reentrancyMock.counter();
|
||||
initialCounter.should.be.bignumber.equal(0);
|
||||
});
|
||||
|
||||
it('should not allow remote callback', async function () {
|
||||
const attacker = await ReentrancyAttack.new();
|
||||
await expectThrow(reentrancyMock.countAndCall(attacker.address));
|
||||
});
|
||||
|
||||
// The following are more side-effects than intended behavior:
|
||||
// I put them here as documentation, and to monitor any changes
|
||||
// in the side-effects.
|
||||
|
||||
it('should not allow local recursion', async function () {
|
||||
await expectThrow(reentrancyMock.countLocalRecursive(10));
|
||||
});
|
||||
|
||||
it('should not allow indirect local recursion', async function () {
|
||||
await expectThrow(reentrancyMock.countThisRecursive(10));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user