Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe("BaseAccountActionProvider", () => {
networkId: "base-mainnet",
}),
sendTransaction: jest.fn().mockResolvedValue("0xmockTransactionHash"),
waitForTransactionReceipt: jest.fn(),
waitForTransactionReceipt: jest.fn().mockResolvedValue({ status: "success" }),
} as unknown as jest.Mocked<EvmWalletProvider>;

// Reset mocks before each test
Expand Down Expand Up @@ -322,6 +322,36 @@ describe("BaseAccountActionProvider", () => {
data: "0xspendCallData",
value: BigInt("0x0"),
});
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith("0xmockTransactionHash");
});

it("should not report success when spend receipt reverts", async () => {
mockFetchPermissions.mockResolvedValue([mockPermission]);
mockGetPermissionStatus.mockResolvedValue(mockPermissionStatus);
mockGetTokenDetails.mockResolvedValue(mockTokenDetails);
mockPrepareSpendCallData.mockResolvedValue([
{
to: "0xSpendContract",
data: "0xspendCallData",
value: "0x0",
},
]);
mockWallet.waitForTransactionReceipt.mockResolvedValue({ status: "reverted" });

const args = {
baseAccount: MOCK_BASE_ACCOUNT,
amount: 10.5,
tokenAddress: null,
permissionIndex: null,
};

const response = await actionProvider.spendFromBaseAccountPermission(mockWallet, args);
const parsedResponse = JSON.parse(response);

expect(parsedResponse.success).toBe(false);
expect(parsedResponse.error).toContain("failed or was reverted");
expect(parsedResponse.transactionHash).toBe("0xmockTransactionHash");
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith("0xmockTransactionHash");
});

it("should handle insufficient allowance", async () => {
Expand Down Expand Up @@ -395,6 +425,30 @@ describe("BaseAccountActionProvider", () => {
data: "0xrevokeCallData",
value: BigInt("0x0"),
});
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith("0xmockTransactionHash");
});

it("should not report success when revoke receipt reverts", async () => {
mockFetchPermissions.mockResolvedValue([mockPermission]);
mockPrepareRevokeCallData.mockResolvedValue({
to: "0xRevokeContract",
data: "0xrevokeCallData",
value: "0x0",
});
mockWallet.waitForTransactionReceipt.mockResolvedValue({ status: "reverted" });

const args = {
baseAccount: MOCK_BASE_ACCOUNT,
permissionIndex: 1,
};

const response = await actionProvider.revokeBaseAccountSpendPermission(mockWallet, args);
const parsedResponse = JSON.parse(response);

expect(parsedResponse.success).toBe(false);
expect(parsedResponse.error).toContain("failed or was reverted");
expect(parsedResponse.transactionHash).toBe("0xmockTransactionHash");
expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith("0xmockTransactionHash");
});

it("should handle out of range permission index", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ Important notes:
value: BigInt(callData.value || "0x0"),
});

// Wait for confirmation before reporting success. Returning success on
// broadcast alone lets agents/frameworks retry on later revert, which can
// double-spend against remaining allowance (same class as sushi #1401).
const receipt = await walletProvider.waitForTransactionReceipt(txHash);
if (receipt.status !== "complete" && receipt.status !== "success") {
return JSON.stringify({
success: false,
transactionHash: txHash,
error: "Spend transaction failed or was reverted",
baseAccount: baseAccount,
spender: spenderAddress,
tokenAddress: permissionTokenAddress,
tokenName: tokenDetails.name,
permissionIndex: permissionIndex,
});
}

const amountSpentFormatted = formatUnits(amountInAtomicUnits, tokenDetails.decimals);

return JSON.stringify({
Expand Down Expand Up @@ -417,6 +434,18 @@ Important notes:
value: BigInt(revokeCall.value || "0x0"),
});

const receipt = await walletProvider.waitForTransactionReceipt(txHash);
if (receipt.status !== "complete" && receipt.status !== "success") {
return JSON.stringify({
success: false,
transactionHash: txHash,
error: "Revoke transaction failed or was reverted",
revokedPermissionIndex: permissionIndex,
baseAccount: baseAccount,
spender: spenderAddress,
});
}

return JSON.stringify({
success: true,
transactionHash: txHash,
Expand Down
Loading