Skip to content

Commit

Permalink
test: fix viem tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRFelix committed Jun 6, 2024
1 parent e8675f1 commit 2cbf728
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ import { NativeEVMTokenConstantAddress } from "../../ethereum";
import { BridgeProviderContext } from "../../interface";
import { AxelarBridgeProvider } from "../index";

jest.mock("ethers", () => {
const originalModule = jest.requireActual("ethers");
jest.mock("viem", () => {
const originalModule = jest.requireActual("viem");
return {
...originalModule,
ethers: {
...originalModule.ethers,
JsonRpcProvider: jest.fn().mockImplementation(() => ({
estimateGas: jest.fn().mockResolvedValue("21000"),
_perform: jest.fn().mockResolvedValue("0x4a817c800"),
})),
},
createPublicClient: jest.fn().mockImplementation(() => ({
estimateGas: jest.fn().mockResolvedValue(BigInt("21000")),
getGasPrice: jest.fn().mockResolvedValue(BigInt("0x4a817c800")),
})),
http: jest.fn(),
};
});

Expand Down
34 changes: 11 additions & 23 deletions packages/bridge/src/skip/__tests__/skip-bridge-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,19 @@ import {
import { SkipBridgeProvider } from "..";
import { SkipMsg } from "../types";

jest.mock("ethers", () => {
const originalModule = jest.requireActual("ethers");
jest.mock("viem", () => {
const originalModule = jest.requireActual("viem");
return {
...originalModule,
ethers: {
...originalModule.ethers,
JsonRpcProvider: jest.fn().mockImplementation(() => ({
estimateGas: jest.fn().mockResolvedValue("21000"),
send: jest.fn().mockResolvedValue("0x4a817c800"),
getFeeData: jest.fn().mockResolvedValue({
gasPrice: BigInt("20000000000"),
maxFeePerGas: BigInt("30000000000"),
maxPriorityFeePerGas: BigInt("1000000000"),
}),
})),
Contract: jest.fn().mockImplementation(() => ({
allowance: jest.fn().mockResolvedValue(BigInt("100")),
approve: {
populateTransaction: jest.fn().mockResolvedValue({
to: "0x123",
data: "0xabcdef",
}),
},
})),
},
createPublicClient: jest.fn().mockImplementation(() => ({
estimateGas: jest.fn().mockResolvedValue(BigInt("21000")),
request: jest.fn().mockResolvedValue("0x4a817c800"),
getGasPrice: jest.fn().mockResolvedValue(BigInt("20000000000")),
readContract: jest.fn().mockResolvedValue(BigInt("100")),
})),
encodeFunctionData: jest.fn().mockReturnValue("0xabcdef"),
encodePacked: jest.fn().mockReturnValue("0xabcdef"),
keccak256: jest.fn().mockReturnValue("0xabcdef"),
};
});

Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/src/skip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class SkipBridgeProvider implements BridgeProvider {
type: "evm",
to: message.to as Address,
data: `0x${message.data}`,
value: toHex(message.value),
value: toHex(BigInt(message.value)),
approvalTransactionRequest,
};
}
Expand Down
30 changes: 12 additions & 18 deletions packages/bridge/src/squid/__tests__/squid-bridge-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,20 @@ import { BridgeQuoteError } from "../../errors";
import { BridgeProviderContext } from "../../interface";
import { SquidBridgeProvider } from "../index";

jest.mock("ethers", () => {
const originalModule = jest.requireActual("ethers");
jest.mock("viem", () => {
const originalModule = jest.requireActual("viem");
return {
...originalModule,
ethers: {
...originalModule.ethers,
JsonRpcProvider: jest.fn().mockImplementation(() => ({
estimateGas: jest.fn().mockResolvedValue("21000"),
send: jest.fn().mockResolvedValue("0x4a817c800"),
})),
Contract: jest.fn().mockImplementation(() => ({
allowance: jest.fn().mockResolvedValue(BigInt("100")),
approve: {
populateTransaction: jest.fn().mockResolvedValue({
to: "0x123",
data: "0xabcdef",
}),
},
})),
},
createPublicClient: jest.fn().mockImplementation(() => ({
readContract: jest.fn().mockImplementation(({ functionName }) => {
if (functionName === "allowance") {
return Promise.resolve(BigInt("100"));
}
return Promise.reject(new Error("Unknown function"));
}),
})),
encodeFunctionData: jest.fn().mockImplementation(() => "0xabcdef"),
http: jest.fn().mockImplementation(() => ({})),
};
});
beforeEach(() => {
Expand Down
12 changes: 6 additions & 6 deletions packages/bridge/src/squid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,19 @@ export class SquidBridgeProvider implements BridgeProvider {
data: transactionRequest.data as Address,
value:
transactionRequest.routeType !== "SEND"
? toHex(transactionRequest.value)
? toHex(BigInt(transactionRequest.value))
: undefined,
...(transactionRequest.maxPriorityFeePerGas
? {
gas: toHex(transactionRequest.gasLimit),
maxFeePerGas: toHex(transactionRequest.maxFeePerGas),
gas: toHex(BigInt(transactionRequest.gasLimit)),
maxFeePerGas: toHex(BigInt(transactionRequest.maxFeePerGas)),
maxPriorityFeePerGas: toHex(
transactionRequest.maxPriorityFeePerGas
BigInt(transactionRequest.maxPriorityFeePerGas)
),
}
: {
gas: toHex(transactionRequest.gasLimit),
gasPrice: toHex(transactionRequest.gasPrice),
gas: toHex(BigInt(transactionRequest.gasLimit)),
gasPrice: toHex(BigInt(transactionRequest.gasPrice)),
}),
approvalTransactionRequest: approvalTx,
};
Expand Down

0 comments on commit 2cbf728

Please sign in to comment.