Created
November 22, 2022 05:18
-
-
Save daog1/4360deed8bdd46ee1356f4e0d86c83f1 to your computer and use it in GitHub Desktop.
合约调用合约
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.13; | |
import "forge-std/Test.sol"; | |
contract Greeter is Test { | |
string private name = "DMZ"; | |
function greet(uint256 num) public { | |
emit log_named_uint("greet",num); | |
} | |
function greet2(uint256 num) public returns( string memory){ | |
emit log_named_uint("greet2",num); | |
return name; | |
} | |
function setname(string calldata n1) public { | |
name = n1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.13; | |
import "forge-std/Test.sol"; | |
import "src/Greeter.sol"; | |
contract GreeterTest is Test { | |
Greeter greeter; | |
function setUp() public { | |
greeter = new Greeter(); | |
} | |
function testExample() public { | |
//assertTrue(true); | |
greeter.greet(123); | |
bytes4 sign = 0xf9220889; | |
address(greeter).call(abi.encodeWithSelector(sign,123)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment