From 77461489f77cf53ec2604602132ad6aea7851083 Mon Sep 17 00:00:00 2001 From: erhant Date: Fri, 13 Oct 2023 23:33:59 +0300 Subject: [PATCH] slight rfk --- .gitignore | 3 --- foundry.toml | 7 ++----- remappings.txt | 9 +++++++++ src/Huffd1.huff | 10 +++++----- src/test/Huffd1.t.huff | 9 +++++++++ test/Huffd1.t.sol | 19 ++++++++++++++++++- 6 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 remappings.txt create mode 100755 src/test/Huffd1.t.huff diff --git a/.gitignore b/.gitignore index b7ede71..69dfdc0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,9 +9,6 @@ node_modules/ cache/ out/ -# Vscode -.vscode/ - # huffc artifacts artifacts diff --git a/foundry.toml b/foundry.toml index 67846be..094b3eb 100644 --- a/foundry.toml +++ b/foundry.toml @@ -7,11 +7,8 @@ optimizer = true optimizer_runs = 200 # Default amount ffi = true fuzz_runs = 1_000 -remappings = [ - "forge-std=lib/forge-std/src/", - "foundry-huff=lib/foundry-huff/src/", -] fs_permissions = [ - { access = "read", path = "./src/test/Polynomial.t.huff" } + { access = "read", path = "./src/test/Polynomial.t.huff" }, + { access = "read", path = "./src/test/Huffd1.t.huff" } ] diff --git a/remappings.txt b/remappings.txt new file mode 100644 index 0000000..471e8ba --- /dev/null +++ b/remappings.txt @@ -0,0 +1,9 @@ +ds-test/=lib/forge-std/lib/ds-test/src/ +forge-std/=lib/forge-std/src/ +foundry-huff/=lib/foundry-huff/src/ +solidity-stringutils/=lib/foundry-huff/lib/solidity-stringutils/ +lib/forge-std:ds-test/=lib/forge-std/lib/ds-test/src/ +lib/foundry-huff:ds-test/=lib/foundry-huff/lib/forge-std/lib/ds-test/src/ +lib/foundry-huff:forge-std/=lib/foundry-huff/lib/forge-std/src/ +lib/foundry-huff:solidity-stringutils/=lib/foundry-huff/lib/solidity-stringutils/ +lib/foundry-huff:stringutils/=lib/foundry-huff/lib/solidity-stringutils/ diff --git a/src/Huffd1.huff b/src/Huffd1.huff index f14e607..69ff510 100644 --- a/src/Huffd1.huff +++ b/src/Huffd1.huff @@ -35,9 +35,7 @@ #define function ownerOf(uint256) view returns (address) #define function balanceOf(address) view returns (uint256) #define function transfer(address, uint256) nonpayable returns () - -// TODOS: -// #define function transferFrom(address,address,uint256) nonpayable returns () +#define function transferFrom(address,address,uint256) nonpayable returns () // #define function approve(address,uint256) nonpayable returns () // #define function getApproved(uint256) view returns (address) @@ -182,6 +180,8 @@ //// MAIN //// /////////////////////////////////////////////////////////////////////////////// #define macro HUFFD1_CONSTRUCTOR() = takes (0) returns (0) { + OWNED_CONSTRUCTOR() + // the constant polynomial equal to OWNER will result // in all tokens being owned by that OWNER [OWNER] sload // [owner] @@ -189,6 +189,8 @@ } #define macro HUFFD1_MAIN() = takes (1) returns (1) { + OWNED_MAIN() + dup1 __FUNC_SIG(name) eq name jumpi dup1 __FUNC_SIG(symbol) eq symbol jumpi dup1 __FUNC_SIG(ownerOf) eq ownerOf jumpi @@ -224,13 +226,11 @@ //// WRAPPERS //// /////////////////////////////////////////////////////////////////////////////// #define macro CONSTRUCTOR() = takes (0) returns (0) { - OWNED_CONSTRUCTOR() HUFFD1_CONSTRUCTOR() } #define macro MAIN() = takes (0) returns (0) { 0x00 calldataload 0xE0 shr - OWNED_MAIN() HUFFD1_MAIN() 0x00 0x00 revert } diff --git a/src/test/Huffd1.t.huff b/src/test/Huffd1.t.huff new file mode 100755 index 0000000..ea906fe --- /dev/null +++ b/src/test/Huffd1.t.huff @@ -0,0 +1,9 @@ +#define macro CONSTRUCTOR() = takes (0) returns (0) { + HUFFD1_CONSTRUCTOR() +} + +#define macro MAIN() = takes (0) returns (0) { + 0x00 calldataload 0xE0 shr + HUFFD1_MAIN() + 0x00 0x00 revert +} diff --git a/test/Huffd1.t.sol b/test/Huffd1.t.sol index 501365c..0ed7356 100644 --- a/test/Huffd1.t.sol +++ b/test/Huffd1.t.sol @@ -12,7 +12,14 @@ contract Huffd1Test is Test { /// @dev Set-up to run before each test. function setUp() public { - huffd1 = Huffd1(HuffDeployer.deploy_with_args("Huffd1", abi.encode(OWNER))); + string memory code = vm.readFile("src/test/Huffd1.t.huff"); + huffd1 = Huffd1( + HuffDeployer.deploy_with_code_args( + "Huffd1", + code, + abi.encode(OWNER) + ) + ); } /// @dev Should return correct name and symbol. @@ -74,19 +81,29 @@ contract Huffd1Test is Test { assertEq(huffd1.balanceOf(OWNER), TOTAL_SUPPLY - 1); assertEq(huffd1.balanceOf(NEW_OWNER), 1); } + + /// @dev Should revert to an invalid function selector. + function test_InvalidFunction() public { + (bool success, ) = address(huffd1).call(""); + assertEq(success, false); + } } // util/Owned.huff interface Owned { function owner() external view returns (address owner); + function setOwner(address newOwner) external; } interface Huffd1 is Owned { function name() external view returns (string memory name); + function symbol() external view returns (string memory symbol); function ownerOf(uint256 tokenId) external view returns (address owner); + function balanceOf(address owner) external view returns (uint256 balance); + function transfer(address to, uint256 tokenId) external; }