Skip to content

Commit

Permalink
fix(wallet): add back missing txData for signTransaction,sendTransact…
Browse files Browse the repository at this point in the history
…ion (#263)

Co-authored-by: Salah-Eddine Saakoun <salah-eddine.saakoun@consensys.net>
  • Loading branch information
legobeat and cryptodev-2s authored Nov 6, 2023
1 parent ca572b2 commit abb9a20
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
43 changes: 43 additions & 0 deletions src/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ describe('wallet', () => {
'The requested account and/or method has not been authorized by the user.',
);
});

it('should not override other request params', async () => {
const { engine } = createTestSetup();
const getAccounts = async () => testAddresses.slice(0, 2);
const witnessedTxParams: TransactionParams[] = [];
const processTransaction = async (_txParams: TransactionParams) => {
witnessedTxParams.push(_txParams);
return testTxHash;
};
engine.push(createWalletMiddleware({ getAccounts, processTransaction }));
const txParams = {
from: testAddresses[0],
to: testAddresses[1],
};

const payload = { method: 'eth_sendTransaction', params: [txParams] };
await pify(engine.handle).call(engine, payload);
expect(witnessedTxParams).toHaveLength(1);
expect(witnessedTxParams[0]).toStrictEqual(txParams);
});
});

describe('signTransaction', () => {
Expand Down Expand Up @@ -144,6 +164,29 @@ describe('wallet', () => {
expect(witnessedTxParams[0]).toStrictEqual(txParams);
});

it('should not override other request params', async () => {
const { engine } = createTestSetup();
const getAccounts = async () => testAddresses.slice(0, 2);
const witnessedTxParams: TransactionParams[] = [];
const processSignTransaction = async (_txParams: TransactionParams) => {
witnessedTxParams.push(_txParams);
return testTxHash;
};

engine.push(
createWalletMiddleware({ getAccounts, processSignTransaction }),
);
const txParams = {
from: testAddresses[0],
to: testAddresses[1],
};

const payload = { method: 'eth_signTransaction', params: [txParams] };
await pify(engine.handle).call(engine, payload);
expect(witnessedTxParams).toHaveLength(1);
expect(witnessedTxParams[0]).toStrictEqual(txParams);
});

it('should throw when provided invalid address', async () => {
const { engine } = createTestSetup();
const getAccounts = async () => testAddresses.slice(0, 2);
Expand Down
10 changes: 6 additions & 4 deletions src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ WalletMiddlewareOptions): JsonRpcMiddleware<any, Block> {
throw rpcErrors.invalidInput();
}

const params = req.params as [TransactionParams?];
const params = req.params[0] as TransactionParams | undefined;
const txParams: TransactionParams = {
from: await validateAndNormalizeKeyholder(params[0]?.from || '', req),
...params,
from: await validateAndNormalizeKeyholder(params?.from || '', req),
};
res.result = await processTransaction(txParams, req);
}
Expand All @@ -176,9 +177,10 @@ WalletMiddlewareOptions): JsonRpcMiddleware<any, Block> {
throw rpcErrors.invalidInput();
}

const params = req.params as [TransactionParams?];
const params = req.params[0] as TransactionParams | undefined;
const txParams: TransactionParams = {
from: await validateAndNormalizeKeyholder(params[0]?.from || '', req),
...params,
from: await validateAndNormalizeKeyholder(params?.from || '', req),
};
res.result = await processSignTransaction(txParams, req);
}
Expand Down

0 comments on commit abb9a20

Please sign in to comment.