Skip to content

Commit

Permalink
feat: add gas snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
marktoda committed Oct 22, 2024
1 parent adb74f7 commit e93a7b4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 5 files
+193 −0 CONTRIBUTING.md
+16 −0 README.md
+12 −1 scripts/vm.py
+126 −16 src/Vm.sol
+2 −2 test/Vm.t.sol
34 changes: 34 additions & 0 deletions snapshots/TheCompactTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"basicTransfer": "57171",
"basicWithdrawal": "62511",
"batchClaim": "112279",
"batchClaimWithWitness": "113250",
"batchTransfer": "82957",
"batchWithdrawal": "105514",
"claim": "60392",
"claimAndWithdraw": "75409",
"claimWithWitness": "59934",
"depositBatchSingleERC20": "69802",
"depositBatchViaPermit2SingleERC20": "109739",
"depositERC20AndURI": "69135",
"depositERC20Basic": "69140",
"depositERC20ViaPermit2AndURI": "100228",
"depositETHAndURI": "28869",
"depositETHBasic": "30332",
"qualifiedBatchClaim": "113429",
"qualifiedBatchClaimWithWitness": "113212",
"qualifiedClaim": "60178",
"qualifiedClaimWithWitness": "59267",
"qualifiedSplitBatchClaim": "140805",
"qualifiedSplitBatchClaimWithWitness": "141072",
"qualifiedSplitClaim": "86438",
"qualifiedSplitClaimWithWitness": "87191",
"splitBatchClaim": "140469",
"splitBatchClaimWithWitness": "140714",
"splitBatchTransfer": "113597",
"splitBatchWithdrawal": "149301",
"splitClaim": "86498",
"splitClaimWithWitness": "86422",
"splitTransfer": "83166",
"splitWithdrawal": "98318"
}
32 changes: 32 additions & 0 deletions test/TheCompact.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
uint256 id = theCompact.deposit{ value: amount }(allocator);
vm.snapshotGasLastCall("depositETHBasic");

(address derivedToken, address derivedAllocator, ResetPeriod derivedResetPeriod, Scope derivedScope) = theCompact.getLockDetails(id);
assertEq(derivedToken, address(0));
Expand All @@ -192,6 +193,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
uint256 id = theCompact.deposit{ value: amount }(allocator, resetPeriod, scope, recipient);
vm.snapshotGasLastCall("depositETHAndURI");

(address derivedToken, address derivedAllocator, ResetPeriod derivedResetPeriod, Scope derivedScope) = theCompact.getLockDetails(id);
assertEq(derivedToken, address(0));
Expand All @@ -216,6 +218,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
uint256 id = theCompact.deposit(address(token), allocator, amount);
vm.snapshotGasLastCall("depositERC20Basic");

(address derivedToken, address derivedAllocator, ResetPeriod derivedResetPeriod, Scope derivedScope) = theCompact.getLockDetails(id);
assertEq(derivedToken, address(token));
Expand All @@ -240,6 +243,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
uint256 id = theCompact.deposit(address(token), allocator, resetPeriod, scope, amount, recipient);
vm.snapshotGasLastCall("depositERC20AndURI");

(address derivedToken, address derivedAllocator, ResetPeriod derivedResetPeriod, Scope derivedScope) = theCompact.getLockDetails(id);
assertEq(derivedToken, address(token));
Expand Down Expand Up @@ -269,6 +273,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool ok = theCompact.deposit(idsAndAmounts, recipient);
vm.snapshotGasLastCall("depositBatchSingleERC20");
assert(ok);

(address derivedToken, address derivedAllocator, ResetPeriod derivedResetPeriod, Scope derivedScope) = theCompact.getLockDetails(id);
Expand Down Expand Up @@ -326,6 +331,7 @@ contract TheCompactTest is Test {
uint96 allocatorId = theCompact.__register(allocator, "");

uint256 id = theCompact.deposit(address(token), amount, nonce, deadline, swapper, allocator, resetPeriod, scope, recipient, signature);
vm.snapshotGasLastCall("depositERC20ViaPermit2AndURI");

(address derivedToken, address derivedAllocator, ResetPeriod derivedResetPeriod, Scope derivedScope) = theCompact.getLockDetails(id);
assertEq(derivedToken, address(token));
Expand Down Expand Up @@ -384,6 +390,7 @@ contract TheCompactTest is Test {
tokenPermissions[0] = ISignatureTransfer.TokenPermissions({ token: address(token), amount: amount });

uint256[] memory ids = theCompact.deposit(swapper, tokenPermissions, allocator, resetPeriod, scope, recipient, nonce, deadline, signature);
vm.snapshotGasLastCall("depositBatchViaPermit2SingleERC20");

assertEq(ids.length, 1);

Expand Down Expand Up @@ -429,6 +436,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedTransfer(transfer);
vm.snapshotGasLastCall("basicTransfer");
assert(status);

assertEq(token.balanceOf(address(theCompact)), amount);
Expand Down Expand Up @@ -478,6 +486,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedTransfer(transfer);
vm.snapshotGasLastCall("splitTransfer");
assert(status);

assertEq(token.balanceOf(address(theCompact)), amount);
Expand Down Expand Up @@ -539,6 +548,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedTransfer(transfer);
vm.snapshotGasLastCall("batchTransfer");
assert(status);

assertEq(token.balanceOf(recipient), 0);
Expand Down Expand Up @@ -610,6 +620,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedTransfer(transfer);
vm.snapshotGasLastCall("splitBatchTransfer");
assert(status);

assertEq(token.balanceOf(recipientOne), 0);
Expand Down Expand Up @@ -651,6 +662,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedWithdrawal(transfer);
vm.snapshotGasLastCall("basicWithdrawal");
assert(status);

assertEq(token.balanceOf(address(theCompact)), 0);
Expand Down Expand Up @@ -700,6 +712,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedWithdrawal(transfer);
vm.snapshotGasLastCall("splitWithdrawal");
assert(status);

assertEq(token.balanceOf(address(theCompact)), 0);
Expand Down Expand Up @@ -762,6 +775,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedWithdrawal(transfer);
vm.snapshotGasLastCall("batchWithdrawal");
assert(status);

assertEq(token.balanceOf(recipient), amountOne);
Expand Down Expand Up @@ -836,6 +850,7 @@ contract TheCompactTest is Test {

vm.prank(swapper);
bool status = theCompact.allocatedWithdrawal(transfer);
vm.snapshotGasLastCall("splitBatchWithdrawal");
assert(status);

assertEq(token.balanceOf(recipientOne), amountOne);
Expand Down Expand Up @@ -880,6 +895,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("claim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -919,6 +935,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claimAndWithdraw(claim);
vm.snapshotGasLastCall("claimAndWithdraw");
assert(status);

assertEq(address(theCompact).balance, 0);
Expand Down Expand Up @@ -967,6 +984,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedClaim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1020,6 +1038,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("claimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1084,6 +1103,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedClaimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1134,6 +1154,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("splitClaim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1195,6 +1216,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedSplitClaim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1261,6 +1283,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("splitClaimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1338,6 +1361,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedSplitClaimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1408,6 +1432,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("batchClaim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1488,6 +1513,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedBatchClaim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1564,6 +1590,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("batchClaimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1650,6 +1677,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedBatchClaimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1732,6 +1760,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("splitBatchClaim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1820,6 +1849,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("splitBatchClaimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -1912,6 +1942,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedSplitBatchClaim");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down Expand Up @@ -2010,6 +2041,7 @@ contract TheCompactTest is Test {

vm.prank(arbiter);
(bool status) = theCompact.claim(claim);
vm.snapshotGasLastCall("qualifiedSplitBatchClaimWithWitness");
assert(status);

assertEq(address(theCompact).balance, amount);
Expand Down

0 comments on commit e93a7b4

Please sign in to comment.