Skip to content

Commit

Permalink
feat: add functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-sun committed Feb 14, 2024
1 parent 933fc6c commit 1210410
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/UnsupportedAssetRefund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 */
Expand Down
17 changes: 17 additions & 0 deletions test/UnsupportedAssetRefund.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1210410

Please sign in to comment.