Skip to content

Commit

Permalink
set data and input
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Apr 26, 2024
1 parent 7f3cf6d commit b47e1ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 12 additions & 5 deletions src/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ describe('wallet', () => {
expect(sendTxResult).toBeDefined();
expect(sendTxResult).toStrictEqual(testTxHash);
expect(witnessedTxParams).toHaveLength(1);
expect(witnessedTxParams[0]).toStrictEqual(txParams);
expect(witnessedTxParams[0]).toStrictEqual({
from: testAddresses[0],
data: '0x0',
input: '0x0',
});
});

it('processes transaction with input field but without data field', async () => {
Expand All @@ -161,8 +165,9 @@ describe('wallet', () => {
expect(sendTxResult).toStrictEqual(testTxHash);
expect(witnessedTxParams).toHaveLength(1);
expect(witnessedTxParams[0]).toStrictEqual({
from: txParams.from,
data: txParams.input,
from: testAddresses[0],
data: '0x0',
input: '0x0',
});
});

Expand All @@ -188,8 +193,9 @@ describe('wallet', () => {
expect(sendTxResult).toStrictEqual(testTxHash);
expect(witnessedTxParams).toHaveLength(1);
expect(witnessedTxParams[0]).toStrictEqual({
from: txParams.from,
data: txParams.data,
from: testAddresses[0],
data: '0x0',
input: '0x0',
});
});

Expand Down Expand Up @@ -227,6 +233,7 @@ describe('wallet', () => {
from: testAddresses[0],
to: testAddresses[1],
data: '0x0',
input: '0x0',
};

const payload = { method: 'eth_sendTransaction', params: [txParams] };
Expand Down
6 changes: 4 additions & 2 deletions src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ WalletMiddlewareOptions): JsonRpcMiddleware<any, Block> {
}

const txParamsData = data || input;
const txParams: TransactionParams & { data?: string } = {
const txParams: TransactionParams & { data?: string; input?: string } = {
...restParams,
...(txParamsData ? { data: txParamsData } : undefined),
...(txParamsData
? { data: txParamsData, input: txParamsData }
: undefined),
from: await validateAndNormalizeKeyholder(from || '', req),
};
res.result = await processTransaction(txParams, req);
Expand Down

0 comments on commit b47e1ba

Please sign in to comment.