From 12104102dad017e390f4c415c596c5c45b87471e Mon Sep 17 00:00:00 2001 From: Yi Sun Date: Wed, 14 Feb 2024 14:22:27 -0500 Subject: [PATCH] feat: add functional test --- src/UnsupportedAssetRefund.sol | 6 +++--- test/UnsupportedAssetRefund.t.sol | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/UnsupportedAssetRefund.sol b/src/UnsupportedAssetRefund.sol index 40b2e2b..1ca92d7 100644 --- a/src/UnsupportedAssetRefund.sol +++ b/src/UnsupportedAssetRefund.sol @@ -32,7 +32,7 @@ contract UnsupportedAssetRefund is IUnsupportedAssetRefund, AxiomV2Client, Ownab emit AxiomCallbackQuerySchemaUpdated(_axiomCallbackQuerySchema); } - /// @inheritdoc IAxiomV2Client + /// @inheritdoc AxiomV2Client /// @notice Gives a refund to `fromAddress` for each transfer made to `toAddress` from `fromAddress` /// for the ERC-20 at `tokenContractAddress`. Checks that the range of `claimId` used in these /// transfers is valid and that the allowance of the ERC-20 at `tokenContractAddress` is sufficient. @@ -72,10 +72,10 @@ contract UnsupportedAssetRefund is IUnsupportedAssetRefund, AxiomV2Client, Ownab } } - /// @inheritdoc IAxiomV2Client + /// @inheritdoc AxiomV2Client function _validateAxiomV2Call( AxiomCallbackType, /* callbackType */ - uint64, /* sourceChainId */ + uint64 sourceChainId, address, /* caller */ bytes32 querySchema, uint256, /* queryId */ diff --git a/test/UnsupportedAssetRefund.t.sol b/test/UnsupportedAssetRefund.t.sol index 138a66e..8f0748f 100644 --- a/test/UnsupportedAssetRefund.t.sol +++ b/test/UnsupportedAssetRefund.t.sol @@ -23,6 +23,8 @@ contract UnsupportedAssetRefundTest is AxiomTest { AxiomInput public input; bytes32 public querySchema; + event RefundClaimed(address indexed token, address indexed refundee, address indexed refunder, uint256 value); + address public constant UNI_ADDR = 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984; address public constant UNI_SENDER_ADDR = 0x84F722ec6713E2e645576387a3Cb28cfF6126ac4; address public constant UNI_RECEIVER_ADDR = 0xe534b1d79cB4C8e11bEB93f00184a12bd85a63fD; @@ -51,14 +53,29 @@ contract UnsupportedAssetRefundTest is AxiomTest { } function test_refund() public { + // Prank approval from `UNI_RECEIVER_ADDR` to `assetRefund` vm.prank(UNI_RECEIVER_ADDR); IERC20(UNI_ADDR).approve(address(assetRefund), MAX_INT); + // Prank balance of `UNI_RECEIVER_ADDR` deal(UNI_ADDR, UNI_RECEIVER_ADDR, 100 * 1e18); + // Create a query to prove that `UNI_SENDER_ADDR` sent UNI to `UNI_RECEIVER_ADDR` Query memory q = query(querySchema, abi.encode(input), address(assetRefund)); + // Send the query to AxiomV2Query q.send(); + + // record balances before refund + uint256 balanceBefore = IERC20(UNI_ADDR).balanceOf(UNI_RECEIVER_ADDR); + + // Prank fulfillment from Axiom, specifying `UNI_SENDER_ADDR` as the sender of the query bytes32[] memory results = q.prankFulfill(UNI_SENDER_ADDR); + + // record balances after refund + uint256 balanceAfter = IERC20(UNI_ADDR).balanceOf(UNI_RECEIVER_ADDR); + + // assert that the refund was successful + assertEq(balanceAfter, balanceBefore - 5 * 1e16); } }