contract A {
address public a;
function test() public returns (address b){ b = address(this); a = b;}
}
部署后得到 A 合约的地址,我们再利用 A 合约的地址部署 B 合约:
contract B {
address public a;
address Aaddress = //这里填入 A 合约的地址;
function testCall() public{ Aaddress.call(abi.encodeWithSignature(test())); }
function testDelegatecall() public{ Aaddress.delegatecall(abi.encodeWithSignature(test())); }
}
当我们调用B.testCall()或者B.testDelegatecall()函数时,这两个函数都会去调用 A.test() ,我们需要做的是观察 B 合约与 A 合约中的 address a 的变化。