diff --git a/test/EIP7412.t.sol b/test/EIP7412.t.sol index f814d798..01e868e0 100644 --- a/test/EIP7412.t.sol +++ b/test/EIP7412.t.sol @@ -2,30 +2,73 @@ pragma solidity 0.8.20; import {EIP7412} from "src/utils/EIP7412.sol"; +import { + EIP7412Mock, + EIP7412MockRefund, + EIP7412MockRevert +} from "test/utils/mocks/EIP7412Mock.sol"; import {SynthetixMock} from "test/utils/mocks/SynthetixMock.sol"; import {Test} from "lib/forge-std/src/Test.sol"; contract EIP7412Test is Test, SynthetixMock { + EIP7412Mock eip7412Mock; + EIP7412MockRefund eip7412MockRefund; + EIP7412MockRevert eip7412MockRevert; + + uint256 amount = 1 ether; + + function setUp() public { + eip7412Mock = new EIP7412Mock(); + eip7412MockRefund = new EIP7412MockRefund(); + eip7412MockRevert = new EIP7412MockRevert(); + } + function test_fulfillOracleQuery(bytes calldata signedOffchainData) public { - address payable mock_eip7412_implementer = payable(address(0xE19)); + EIP7412 eip7412 = new EIP7412(); + + uint256 preBalance = address(this).balance; + uint preBalanceeip7412Mock = address(eip7412Mock).balance; + + eip7412.fulfillOracleQuery{value: amount}( + payable(address(eip7412Mock)), signedOffchainData + ); + + assertLt(address(this).balance, preBalance); + assertEq(address(eip7412Mock).balance, preBalanceeip7412Mock + amount); + } + + function test_fulfillOracleQuery_refund(bytes calldata signedOffchainData) + public + { + EIP7412 eip7412 = new EIP7412(); - mock_fulfillOracleQuery(mock_eip7412_implementer, signedOffchainData); + uint256 preBalance = address(this).balance; + + // refunds are not supported + vm.expectRevert("EIP7412MockRefund"); + + eip7412.fulfillOracleQuery{value: amount}( + payable(address(eip7412MockRefund)), signedOffchainData + ); + assert(address(this).balance == preBalance); + } + + function test_fulfillOracleQuery_revert(bytes calldata signedOffchainData) + public + { EIP7412 eip7412 = new EIP7412(); uint256 preBalance = address(this).balance; - (bool success,) = address(eip7412).call{value: 5 wei}( - abi.encodeWithSelector( - EIP7412.fulfillOracleQuery.selector, - mock_eip7412_implementer, - signedOffchainData - ) + vm.expectRevert("EIP7412MockRevert"); + + eip7412.fulfillOracleQuery{value: amount}( + payable(address(eip7412MockRevert)), signedOffchainData ); - assertTrue(success); - assertLt(address(this).balance, preBalance); + assert(address(this).balance == preBalance); } } diff --git a/test/utils/mocks/EIP7412Mock.sol b/test/utils/mocks/EIP7412Mock.sol new file mode 100644 index 00000000..a0078879 --- /dev/null +++ b/test/utils/mocks/EIP7412Mock.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +pragma solidity 0.8.20; + +contract EIP7412Mock { + function fulfillOracleQuery(bytes calldata) external payable {} +} + +contract EIP7412MockRefund { + function fulfillOracleQuery(bytes calldata) external payable { + (bool success,) = msg.sender.call{value: msg.value}(""); + require(success, "EIP7412MockRefund"); + } +} + +contract EIP7412MockRevert { + function fulfillOracleQuery(bytes calldata) external payable { + revert("EIP7412MockRevert"); + } +} diff --git a/test/utils/mocks/SynthetixMock.sol b/test/utils/mocks/SynthetixMock.sol index 57af2551..f239b377 100644 --- a/test/utils/mocks/SynthetixMock.sol +++ b/test/utils/mocks/SynthetixMock.sol @@ -51,19 +51,6 @@ contract SynthetixMock is Test { ); } - function mock_fulfillOracleQuery( - address EIP7412Implementer, - bytes calldata signedOffchainData - ) public { - vm.mockCall( - EIP7412Implementer, - abi.encodeWithSelector( - EIP7412.fulfillOracleQuery.selector, signedOffchainData - ), - abi.encode() - ); - } - function mock_getAccountOwner( address perpsMarketProxy, uint128 accountId,