Skip to content

Commit

Permalink
fix typo and refine by comment
Browse files Browse the repository at this point in the history
  • Loading branch information
alex0207s committed Dec 7, 2023
1 parent fb61d5f commit d4a2b55
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions test/forkMainnet/GenericSwap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ contract GenericSwapTest is Test, Tokens, BalanceUtil, Permit2Helper, SigHelper
Snapshot memory makerMakerToken = BalanceSnapshot.take({ owner: address(mockStrategy), token: gsData.makerToken });

uint256 actualOutput = 900;
uint256 realChangedInGas = actualOutput - 1;
uint256 realChangedInGS = actualOutput - 1; // leaving 1 wei in GS

// 800 < 900 < 1000
mockStrategy.setOutputAmountAndRecipient(actualOutput, payable(address(genericSwap)));
vm.expectEmit(true, true, true, true);
emit Swap(getGSDataHash(gsData), gsData.maker, taker, taker, gsData.takerToken, gsData.takerTokenAmount, gsData.makerToken, realChangedInGas);
emit Swap(getGSDataHash(gsData), gsData.maker, taker, taker, gsData.takerToken, gsData.takerTokenAmount, gsData.makerToken, realChangedInGS);
vm.prank(taker);
genericSwap.executeSwap(gsData, defaultTakerPermit);

takerTakerToken.assertChange(-int256(gsData.takerTokenAmount));
takerMakerToken.assertChange(int256(realChangedInGas));
takerMakerToken.assertChange(int256(realChangedInGS));
makerTakerToken.assertChange(int256(gsData.takerTokenAmount));
makerMakerToken.assertChange(-int256(actualOutput));
}
Expand All @@ -178,28 +178,21 @@ contract GenericSwapTest is Test, Tokens, BalanceUtil, Permit2Helper, SigHelper
gsData.takerToken = Constant.ETH_ADDRESS;
gsData.takerTokenAmount = 1 ether;

uint256 realChangedInGS = gsData.makerTokenAmount - 1; // leaving 1 wei in GS

Snapshot memory takerTakerToken = BalanceSnapshot.take({ owner: taker, token: gsData.takerToken });
Snapshot memory takerMakerToken = BalanceSnapshot.take({ owner: taker, token: gsData.makerToken });
Snapshot memory makerTakerToken = BalanceSnapshot.take({ owner: address(mockStrategy), token: gsData.takerToken });
Snapshot memory makerMakerToken = BalanceSnapshot.take({ owner: address(mockStrategy), token: gsData.makerToken });

mockStrategy.setOutputAmountAndRecipient(gsData.makerTokenAmount, payable(address(genericSwap)));
vm.expectEmit(true, true, true, true);
emit Swap(
getGSDataHash(gsData),
gsData.maker,
taker,
taker,
gsData.takerToken,
gsData.takerTokenAmount,
gsData.makerToken,
gsData.makerTokenAmount - 1
);
emit Swap(getGSDataHash(gsData), gsData.maker, taker, taker, gsData.takerToken, gsData.takerTokenAmount, gsData.makerToken, realChangedInGS);
vm.prank(taker);
genericSwap.executeSwap{ value: gsData.takerTokenAmount }(gsData, defaultTakerPermit);

takerTakerToken.assertChange(-int256(gsData.takerTokenAmount));
takerMakerToken.assertChange(int256(gsData.makerTokenAmount - 1)); // leaving 1 wei in GS
takerMakerToken.assertChange(int256(realChangedInGS));
makerTakerToken.assertChange(int256(gsData.takerTokenAmount));
makerMakerToken.assertChange(-int256(gsData.makerTokenAmount));
}
Expand All @@ -211,28 +204,21 @@ contract GenericSwapTest is Test, Tokens, BalanceUtil, Permit2Helper, SigHelper
gsData.makerTokenAmount = 1 ether;
gsData.minMakerTokenAmount = 1 ether - 1000;

uint256 realChangedInGS = gsData.makerTokenAmount - 1; // leaving 1 wei in GS

Snapshot memory takerTakerToken = BalanceSnapshot.take({ owner: taker, token: gsData.takerToken });
Snapshot memory takerMakerToken = BalanceSnapshot.take({ owner: taker, token: gsData.makerToken });
Snapshot memory makerTakerToken = BalanceSnapshot.take({ owner: address(mockStrategy), token: gsData.takerToken });
Snapshot memory makerMakerToken = BalanceSnapshot.take({ owner: address(mockStrategy), token: gsData.makerToken });

mockStrategy.setOutputAmountAndRecipient(gsData.makerTokenAmount, payable(address(genericSwap)));
vm.expectEmit(true, true, true, true);
emit Swap(
getGSDataHash(gsData),
gsData.maker,
taker,
taker,
gsData.takerToken,
gsData.takerTokenAmount,
gsData.makerToken,
gsData.makerTokenAmount - 1
);
emit Swap(getGSDataHash(gsData), gsData.maker, taker, taker, gsData.takerToken, gsData.takerTokenAmount, gsData.makerToken, realChangedInGS);
vm.prank(taker);
genericSwap.executeSwap(gsData, defaultTakerPermit);

takerTakerToken.assertChange(-int256(gsData.takerTokenAmount));
takerMakerToken.assertChange(int256(gsData.makerTokenAmount - 1)); // leaving 1 wei in GS
takerMakerToken.assertChange(int256(realChangedInGS));
makerTakerToken.assertChange(int256(gsData.takerTokenAmount));
makerMakerToken.assertChange(-int256(gsData.makerTokenAmount));
}
Expand Down

0 comments on commit d4a2b55

Please sign in to comment.