Skip to content

Commit

Permalink
refactor: struct and constant to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
MerlinEgalite committed Sep 20, 2023
1 parent e9af3a3 commit 9c26dc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
27 changes: 12 additions & 15 deletions test/forge/PermitTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ contract PermitTest is BaseTest {
}

function testPermit() public {
SigUtils.Permit memory permit =
SigUtils.Permit({owner: owner, spender: spender, value: 1e18, nonce: 0, deadline: 1 days});
Permit memory permit = Permit({owner: owner, spender: spender, value: 1e18, nonce: 0, deadline: 1 days});

bytes32 digest = sigUtils.getTypedDataHash(permit);

Expand All @@ -39,8 +38,8 @@ contract PermitTest is BaseTest {
}

function testRevertExpiredPermit() public {
SigUtils.Permit memory permit =
SigUtils.Permit({owner: owner, spender: spender, value: 1e18, nonce: vault.nonces(owner), deadline: 1 days});
Permit memory permit =
Permit({owner: owner, spender: spender, value: 1e18, nonce: vault.nonces(owner), deadline: 1 days});

bytes32 digest = sigUtils.getTypedDataHash(permit);

Expand All @@ -53,8 +52,8 @@ contract PermitTest is BaseTest {
}

function testRevertInvalidSigner() public {
SigUtils.Permit memory permit =
SigUtils.Permit({owner: owner, spender: spender, value: 1e18, nonce: vault.nonces(owner), deadline: 1 days});
Permit memory permit =
Permit({owner: owner, spender: spender, value: 1e18, nonce: vault.nonces(owner), deadline: 1 days});

bytes32 digest = sigUtils.getTypedDataHash(permit);

Expand All @@ -65,7 +64,7 @@ contract PermitTest is BaseTest {
}

function testRevertInvalidNonce() public {
SigUtils.Permit memory permit = SigUtils.Permit({
Permit memory permit = Permit({
owner: owner,
spender: spender,
value: 1e18,
Expand All @@ -82,8 +81,7 @@ contract PermitTest is BaseTest {
}

function testRevertSignatureReplay() public {
SigUtils.Permit memory permit =
SigUtils.Permit({owner: owner, spender: spender, value: 1e18, nonce: 0, deadline: 1 days});
Permit memory permit = Permit({owner: owner, spender: spender, value: 1e18, nonce: 0, deadline: 1 days});

bytes32 digest = sigUtils.getTypedDataHash(permit);

Expand All @@ -96,8 +94,7 @@ contract PermitTest is BaseTest {
}

function testTransferFromLimitedPermit() public {
SigUtils.Permit memory permit =
SigUtils.Permit({owner: owner, spender: spender, value: 1e18, nonce: 0, deadline: 1 days});
Permit memory permit = Permit({owner: owner, spender: spender, value: 1e18, nonce: 0, deadline: 1 days});

bytes32 digest = sigUtils.getTypedDataHash(permit);

Expand All @@ -114,8 +111,8 @@ contract PermitTest is BaseTest {
}

function testTransferFromMaxPermit() public {
SigUtils.Permit memory permit =
SigUtils.Permit({owner: owner, spender: spender, value: type(uint256).max, nonce: 0, deadline: 1 days});
Permit memory permit =
Permit({owner: owner, spender: spender, value: type(uint256).max, nonce: 0, deadline: 1 days});

bytes32 digest = sigUtils.getTypedDataHash(permit);

Expand All @@ -132,7 +129,7 @@ contract PermitTest is BaseTest {
}

function testFailInvalidAllowance() public {
SigUtils.Permit memory permit = SigUtils.Permit({
Permit memory permit = Permit({
owner: owner,
spender: spender,
value: 5e17, // approve only 0.5 tokens
Expand All @@ -151,7 +148,7 @@ contract PermitTest is BaseTest {
}

function testFailInvalidBalance() public {
SigUtils.Permit memory permit = SigUtils.Permit({
Permit memory permit = Permit({
owner: owner,
spender: spender,
value: 2e18, // approve 2 tokens
Expand Down
20 changes: 10 additions & 10 deletions test/forge/helpers/SigUtils.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

contract SigUtils {
struct Permit {
address owner;
address spender;
uint256 value;
uint256 nonce;
uint256 deadline;
}
struct Permit {
address owner;
address spender;
uint256 value;
uint256 nonce;
uint256 deadline;
}

// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;

contract SigUtils {
bytes32 internal DOMAIN_SEPARATOR;

constructor(bytes32 _DOMAIN_SEPARATOR) {
Expand Down

0 comments on commit 9c26dc3

Please sign in to comment.