22pragma solidity ^ 0.8.17 ;
33
44import "forge-std/Test.sol " ;
5- import "./mocks/MockPermit2 .sol " ;
6- import {TokenProvider} from "./utils/TokenProvider.sol " ;
5+ import ".. /mocks/IMockPermit2 .sol " ;
6+ import {TokenProvider} from ".. /utils/TokenProvider.sol " ;
77
8- contract AllowanceUnitTest is Test , TokenProvider {
9- MockPermit2 permit2;
8+ abstract contract BaseAllowanceUnitTest is Test , TokenProvider {
9+ IMockPermit2 permit2;
1010
1111 address from = address (0xBEEE );
1212 address spender = address (0xBBBB );
1313
14- function setUp () public {
15- permit2 = new MockPermit2 ();
16- initializeERC20Tokens ();
17- }
14+ function setUp () public virtual {}
15+
16+ function allowance (address from , address token , address spender ) public virtual returns (uint160 , uint48 , uint48 );
17+
18+ function token () public virtual returns (address );
1819
1920 function testUpdateAmountExpirationRandomly (uint160 amount , uint48 expiration ) public {
20- address token = address (token1 );
21+ address token = token ( );
2122
22- (,, uint48 nonce ) = permit2. allowance (from, token, spender);
23+ (,, uint48 nonce ) = allowance (from, token, spender);
2324
2425 permit2.mockUpdateSome (from, token, spender, amount, expiration);
2526
2627 uint48 timestampAfterUpdate = expiration == 0 ? uint48 (block .timestamp ) : expiration;
2728
28- (uint160 amount1 , uint48 expiration1 , uint48 nonce1 ) = permit2. allowance (from, token, spender);
29+ (uint160 amount1 , uint48 expiration1 , uint48 nonce1 ) = allowance (from, token, spender);
2930 assertEq (amount, amount1);
3031 assertEq (timestampAfterUpdate, expiration1);
3132 /// nonce shouldnt change
@@ -37,14 +38,14 @@ contract AllowanceUnitTest is Test, TokenProvider {
3738 // we assume we will never be able to reach 2**48
3839 vm.assume (nonce < type (uint48 ).max);
3940
40- address token = address (token1 );
41+ address token = token ( );
4142
4243 permit2.mockUpdateAll (from, token, spender, amount, expiration, nonce);
4344
4445 uint48 nonceAfterUpdate = nonce + 1 ;
4546 uint48 timestampAfterUpdate = expiration == 0 ? uint48 (block .timestamp ) : expiration;
4647
47- (uint160 amount1 , uint48 expiration1 , uint48 nonce1 ) = permit2. allowance (from, token, spender);
48+ (uint160 amount1 , uint48 expiration1 , uint48 nonce1 ) = allowance (from, token, spender);
4849
4950 assertEq (amount, amount1);
5051 assertEq (timestampAfterUpdate, expiration1);
@@ -54,18 +55,18 @@ contract AllowanceUnitTest is Test, TokenProvider {
5455 function testPackAndUnpack (uint160 amount , uint48 expiration , uint48 nonce ) public {
5556 // pack some numbers
5657 uint256 word = Allowance.pack (amount, expiration, nonce);
57-
58+ address token = token ();
5859 // store the raw word
59- permit2.doStore (from, address (token1) , spender, word);
60+ permit2.doStore (from, token , spender, word);
6061
6162 // load it as a packed allowance
62- (uint160 amount1 , uint48 expiration1 , uint48 nonce1 ) = permit2. allowance (from, address (token1) , spender);
63+ (uint160 amount1 , uint48 expiration1 , uint48 nonce1 ) = allowance (from, token , spender);
6364 assertEq (amount, amount1);
6465 assertEq (expiration, expiration1);
6566 assertEq (nonce, nonce1);
6667
6768 // get the stored word
68- uint256 word1 = permit2.getStore (from, address (token1) , spender);
69+ uint256 word1 = permit2.getStore (from, token , spender);
6970 assertEq (word, word1);
7071 }
7172}
0 commit comments