Skip to content

Instantly share code, notes, and snippets.

@oneleo
Last active October 12, 2022 07:31
Show Gist options
  • Select an option

  • Save oneleo/ec28bfb312f3f658279e2889bbbd0180 to your computer and use it in GitHub Desktop.

Select an option

Save oneleo/ec28bfb312f3f658279e2889bbbd0180 to your computer and use it in GitHub Desktop.
Print Byte32 via Foundry Test
// Reference: https://stackoverflow.com/questions/67893318/solidity-how-to-represent-bytes32-as-string
// Excute: forge test -vvv --match-path "contracts/test/Spender.t.sol" --match-test "testSpendFromUser*"
function testSpendFromUser() public {
bytes32 out1 = keccak256(
abi.encodePacked(
"SpendWithPermit(",
"address tokenAddr,",
"address user,",
"address recipient,",
"uint256 amount,",
"uint256 salt,",
"uint64 expiry",
")"
)
);
console2.logString("0xef4569e9739cba74d90490d1bd03bf9bb1ce2f4b9134ad0e79ba922a1f70c1a1");
console2.logBytes32(out1);
bytes32 out2 = keccak256(
abi.encodePacked(
"SpendWithPermit(",
"address tokenAddr,",
"address requester,",
"address user,",
"address recipient,",
"uint256 amount,",
"uint256 salt,",
"uint64 expiry",
")"
)
);
console2.logBytes32(out2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment