Skip to content

Commit

Permalink
fix null value request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed May 14, 2024
1 parent 763050d commit aec29ad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/wallet-connect/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function wcRouter(
{
to: tx.to,
chainId: parseInt(stripEip155Prefix(chainId)),
value: fromHex(tx.value || "0x", "bigint"),
value: fromHex(tx.value || "0x0", "bigint"),
data: tx.data,
gas: tx.gas ? fromHex(tx.gas, "bigint") : undefined,
},
Expand Down
37 changes: 36 additions & 1 deletion tests/wc.handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Wallet Connect", () => {
202, 85, 99, 164, 77, 162, 209, 137, 199, 133, 194, 59, 178, 150, 153, 78,
]);
});
it("wcRouter: sendTransaction", async () => {
it("wcRouter: sendTransaction (with value)", async () => {
const request = {
method: "eth_sendTransaction",
params: [
Expand Down Expand Up @@ -64,6 +64,41 @@ describe("Wallet Connect", () => {
});
/// can't test payload: its non-deterministic because of gas values!
});

it("wcRouter: sendTransaction (null value)", async () => {
const request = {
method: "eth_sendTransaction",
params: [
{
gas: "0xa8c3",
from: "0xa61d98854f7ab25402e3d12548a2e93a080c1f97",
to: "0xfff9976782d46cc05630d1f6ebab18b2324d6b14",
data: "0x2e1a7d4d000000000000000000000000000000000000000000000000002386f26fc10000",
},
],
};

const { evmMessage } = await wcRouter(
request.method,
chainId,
request.params as EthTransactionParams[]
);
const tx = evmMessage as TransactionSerializable;

delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
delete tx.nonce;

expect(tx).toEqual({
account: "0xa61d98854f7ab25402e3d12548a2e93a080c1f97",
chainId: 11155111,
data: "0x2e1a7d4d000000000000000000000000000000000000000000000000002386f26fc10000",
gas: 43203n,
to: "0xfff9976782d46cc05630d1f6ebab18b2324d6b14",
value: 0n,
});
/// can't test payload: its non-deterministic because of gas values!
});
it("wcRouter: eth_signTypedData", async () => {
const jsonStr = `{
"types": {
Expand Down

0 comments on commit aec29ad

Please sign in to comment.