Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
slight rfk
Browse files Browse the repository at this point in the history
  • Loading branch information
erhant committed Oct 13, 2023
1 parent 2fc3465 commit 7746148
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ node_modules/
cache/
out/

# Vscode
.vscode/

# huffc artifacts
artifacts

Expand Down
7 changes: 2 additions & 5 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
9 changes: 9 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -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/
10 changes: 5 additions & 5 deletions src/Huffd1.huff
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -182,13 +180,17 @@
//// 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]
[BAL_SLOT] sstore // []
}

#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
Expand Down Expand Up @@ -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
}
9 changes: 9 additions & 0 deletions src/test/Huffd1.t.huff
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 18 additions & 1 deletion test/Huffd1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

0 comments on commit 7746148

Please sign in to comment.