Skip to content

Instantly share code, notes, and snippets.

@androlo
Created July 30, 2017 22:24
Show Gist options
  • Save androlo/fd8c482eca9c68843395104ee144767b to your computer and use it in GitHub Desktop.
Save androlo/fd8c482eca9c68843395104ee144767b to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.13;
library InputChecker {
function isAddressZero(address addr) constant internal returns (bool) {
return addr == 0;
}
}
contract CheckInput {
modifier addressNotZero(address addr) {
if (InputChecker.isAddressZero(addr))
revert();
_;
}
}
contract CheckInputTester is CheckInput {
function testAddressNotZero(address addr) addressNotZero(addr) constant returns (bool) {
return true;
}
}
// Could just as well be done from web3 or any other contracts API
contract CheckInputTestRunner {
address constant TEST_ADDRESS_ZERO = 0;
address constant TEST_ADDRESS_NOT_ZERO = 0x1;
CheckInputTester cit;
function CheckInputTestRunner() {
cit = new CheckInputTester();
}
function runIsAddressZeroTrueTest() constant returns (bool) {
return InputChecker.isAddressZero(TEST_ADDRESS_ZERO);
}
function runIsAddressZeroFalseTest() constant returns (bool) {
return !InputChecker.isAddressZero(TEST_ADDRESS_NOT_ZERO);
}
function runAddressNotZeroSuccessTest() constant returns (bool) {
return cit.testAddressNotZero(TEST_ADDRESS_NOT_ZERO);
}
function runAddressNotZeroFailTest() constant returns (bool) {
return cit.testAddressNotZero(TEST_ADDRESS_ZERO);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment