Skip to content

Commit

Permalink
test: return err for post order on transfer to wrong treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
EresDev committed Nov 4, 2024
1 parent d56f40d commit 9cc5e8f
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 0 deletions.
151 changes: 151 additions & 0 deletions tests/fixtures/post-order/parsed-tx-wrong-treasury.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"args": {
"permit": {
"0": { "token": "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d" },
"deadline": 33287622343
},
"transferDetails": {
"requestedAmount": "0x02b5e3af16b1880000",
"to": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
},

"0": [
["0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d", { "type": "BigNumber", "hex": "0x02b5e3af16b1880000" }],
{ "type": "BigNumber", "hex": "0x736d6a935bb4879ae1e94d2ff4ee433a5d705d6cef7b1fa174fa169575bf4a76" },
{ "type": "BigNumber", "hex": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }
],
"1": ["0xD51B09ad92e08B962c994374F4e417d4AD435189", { "type": "BigNumber", "hex": "0x02b5e3af16b1880000" }],
"2": "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"3": "0xf65ed5757fdee7f70a5c3b2ac021b7ae4f028293f6a63735fab3e4c973d00af67693d6435f4968ee446491391294e38ae46184e2351b1cc896d4d4e38520e0ec1c"
},

"functionFragment": {
"type": "function",
"name": "permitTransferFrom",
"constant": false,
"inputs": [
{
"name": "permit",
"type": "tuple",
"indexed": null,
"components": [
{
"name": "permitted",
"type": "tuple",
"indexed": null,
"components": [
{
"name": "token",
"type": "address",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "address",
"_isParamType": true
},
{
"name": "amount",
"type": "uint256",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "uint256",
"_isParamType": true
}
],
"arrayLength": null,
"arrayChildren": null,
"baseType": "tuple",
"_isParamType": true
},
{
"name": "nonce",
"type": "uint256",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "uint256",
"_isParamType": true
},
{
"name": "deadline",
"type": "uint256",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "uint256",
"_isParamType": true
}
],
"arrayLength": null,
"arrayChildren": null,
"baseType": "tuple",
"_isParamType": true
},
{
"name": "transferDetails",
"type": "tuple",
"indexed": null,
"components": [
{
"name": "to",
"type": "address",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "address",
"_isParamType": true
},
{
"name": "requestedAmount",
"type": "uint256",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "uint256",
"_isParamType": true
}
],
"arrayLength": null,
"arrayChildren": null,
"baseType": "tuple",
"_isParamType": true
},
{
"name": "owner",
"type": "address",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "address",
"_isParamType": true
},
{
"name": "signature",
"type": "bytes",
"indexed": null,
"components": null,
"arrayLength": null,
"arrayChildren": null,
"baseType": "bytes",
"_isParamType": true
}
],
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"gas": null,
"_isFragment": true
},
"name": "permitTransferFrom",
"signature": "permitTransferFrom(((address,uint256),uint256,uint256),(address,uint256),address,bytes)",
"sighash": "0x30f28b7a",
"value": { "type": "BigNumber", "hex": "0x00" }
}
37 changes: 37 additions & 0 deletions tests/unit/post-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import orderCard18597 from "../fixtures/post-order/order-card-18597.json";
import orderCard13959 from "../fixtures/post-order/order-card-13959.json";
import parsedTxWrongMethod from "../fixtures/post-order/parsed-tx-wrong-method.json";
import parsedTxWrongToken from "../fixtures/post-order/parsed-tx-wrong-token.json";
import parsedTxWrongTreasury from "../fixtures/post-order/parsed-tx-wrong-treasury.json";
import receiptNotPermit2 from "../fixtures/post-order/receipt-not-permit2.json";
import receiptPermitExpired from "../fixtures/post-order/receipt-permit-expired.json";
import receiptTooHigh from "../fixtures/post-order/receipt-too-high.json";
Expand Down Expand Up @@ -284,6 +285,42 @@ describe("Post order for a payment card", () => {
);
});

it.only("should return error with tx hash that transfers to wrong treasury", async () => {
const providers = await import("@ethersproject/providers");
providers.JsonRpcProvider.prototype.getTransactionReceipt = vi.fn().mockImplementation(async () => {
return receiptTxForMockedParse;
});
providers.JsonRpcProvider.prototype.getTransaction = vi.fn().mockImplementation(async () => {
return minedTxForMockedParse;
});
const { Interface } = await import("@ethersproject/abi");
Interface.prototype.parseTransaction = vi.fn().mockImplementation(() => {
return parsedTxWrongTreasury;
});

const request = new Request(`${TESTS_BASE_URL}/post-order`, {
method: "POST",
body: JSON.stringify({
type: "permit",
chainId: 31337,
txHash: "0xbef4c18032fbef0453f85191fb0fa91184b42d12ccc37f00eb7ae8c1d88a0233",
productId: 18597,
country: "US",
}),
}) as Request<unknown, IncomingRequestCfProperties<unknown>>;

const eventCtx = createEventContext(request, execContext);
const response = await pagesFunction(eventCtx);
await waitOnExecutionContext(execContext);
expect(response.status).toBe(403);
expect(await response.json()).toEqual(generalError);
expect(consoleMock).toHaveBeenLastCalledWith(
"Given transaction hash is not a token transfer to giftCardTreasuryAddress",
"txParsed.args.transferDetails.to=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"giftCardTreasuryAddress=0xD51B09ad92e08B962c994374F4e417d4AD435189"
);
});

it("should post order on sandbox", async () => {
const request = new Request(`${TESTS_BASE_URL}/post-order`, {
method: "POST",
Expand Down

0 comments on commit 9cc5e8f

Please sign in to comment.