I'm trying to call a interface function for testing, but it can't work.
Here is my test contract:
pragma solidity ^0.4.24;
interface InterfaceTest{
function testInterface() external pure returns(uint);
}
contract TestContract {
InterfaceTest _inter;
function test2(address _addr) public returns(uint) {
_inter = InterfaceTest(_addr);
return 2;
}
function test4() public view returns(uint) {
uint t = _inter.testInterface();
return t;
}
}
And here is the implement:
interface InterfaceTest{
function testInterface() external pure returns(uint);
}
contract InterfaceContract is InterfaceTest {
function testInterface() external pure returns(uint) {
return 9;
}
}
I deployed them with truffle(4.1.14) and Ganache, the test2()
function work well and return 2, but when I tried to call test4()
, it said VM Exception while processing transaction: revert
, is there any Error in my code?
There is an interesting error I found:
function test2(address _addr) public {
_interAddr = _addr;
}
function test22() public view returns(address) {
return _interAddr;
}
function test222(address _addr) public view returns(bool) {
if (_addr == _interAddr){
return true;
}
return false;
}
First I set the _interAddr
, and then I get it, but the TWO address are different, what looks like set 0x1d77078832a0f88c6e064cc5e4df88b83d3dd8ca
and get 0x1d77078832a0f8eca804a4989f812d2e80000000
. in test222
, the last numbers have no effect to the result, my contract always return true.
Does anyone have the same error?
Finally I resolved. If you want to set an address
, you must enclose address in ""
, what a stupid mistake.
This problem has been solved, thank you guys.