Skip to content

Commit

Permalink
Add address 0 check to isContract
Browse files Browse the repository at this point in the history
Add tests.
  • Loading branch information
ßingen committed Mar 27, 2018
1 parent 0b01d5c commit 43d9c89
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/TestDelegateProxy.sol
Expand Up @@ -68,6 +68,17 @@ contract TestDelegateProxy is DelegateProxy {
delegatedFwd(target, target.fail.selector.toBytes());
}

function testIsContractZero() {
bool result = isContract(address(0));
Assert.isFalse(result, "should return false");
}

function testIsContractAddress() {
address nonContract = 0x1234;
bool result = isContract(nonContract);
Assert.isFalse(result, "should return false");
}

// keep as last test as it will kill this contract
function testDieIfMinReturn0() {
delegatedFwd(target, target.die.selector.toBytes());
Expand Down
16 changes: 16 additions & 0 deletions test/evm_script.js
Expand Up @@ -336,4 +336,20 @@ contract('EVM Script', accounts => {
})
})
})

context('isContract tests', async () => {
let delegateScript

before(async () => {
delegateScript = await getContract('DelegateScriptWrapper').new()
})

it('fails if address is 0', async () => {
assert.isFalse(await delegateScript.isContractWrapper('0x0'), "should return false")
})

it('fails if dst is not a contract', async () => {
assert.isFalse(await delegateScript.isContractWrapper('0x1234'), "should return false")
})
})
})
10 changes: 10 additions & 0 deletions test/mocks/DelegateScriptWrapper.sol
@@ -0,0 +1,10 @@
pragma solidity 0.4.18;

import "../../contracts/evmscript/executors/DelegateScript.sol";


contract DelegateScriptWrapper is DelegateScript {
function isContractWrapper(address _target) public view returns (bool) {
return isContract(_target);
}
}

0 comments on commit 43d9c89

Please sign in to comment.