Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): add back missing txData for signTransaction,sendTransaction #263

Merged
merged 3 commits into from
Nov 6, 2023
Merged
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
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 @@
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 @@
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 Expand Up @@ -441,7 +443,7 @@
*
* @param address - The address to validate and normalize.
* @param req - The request object.
* @returns {string} - The normalized address, if valid. Otherwise, throws

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

There must be no hyphen before @returns description

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

JSDoc description does not satisfy the regex pattern

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Types are not permitted on @returns

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

There must be no hyphen before @returns description

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

JSDoc description does not satisfy the regex pattern

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Types are not permitted on @returns

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

There must be no hyphen before @returns description

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

JSDoc description does not satisfy the regex pattern

Check warning on line 446 in src/wallet.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Types are not permitted on @returns
* an error
*/
async function validateAndNormalizeKeyholder(
Expand Down
Loading