Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

signTransaction in Accounts module fixed #2735

Merged
merged 3 commits into from
Apr 25, 2019
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
2 changes: 1 addition & 1 deletion packages/web3-eth-accounts/src/Accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class Accounts extends AbstractWeb3Module {
tx.gasPrice = await this.getGasPrice();
}

if (!tx.nonce) {
if (!tx.nonce && tx.nonce !== 0) {
tx.nonce = await this.getTransactionCount(account.address);
}

Expand Down
41 changes: 40 additions & 1 deletion packages/web3-eth-accounts/tests/src/AccountsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ describe('AccountsTest', () => {
expect(accounts.getGasPrice).toHaveBeenCalled();
});

it('calls signTransaction without the nonce property and resolves with a promise', async () => {
it('calls signTransaction with the nonce set to 0 and resolves with a promise', async () => {
const callback = jest.fn();

const transaction = {
Expand All @@ -204,6 +204,45 @@ describe('AccountsTest', () => {
chainId: 1
};

const mappedTransaction = {
from: 0,
gas: 1,
gasPrice: 1,
nonce: 0,
chainId: 1
};

transactionSignerMock.sign = jest.fn(() => {
return Promise.resolve('signed-transaction');
});

const account = {privateKey: 'pk', address: '0x0'};
Account.fromPrivateKey.mockReturnValueOnce(account);

formatters.inputCallFormatter.mockReturnValueOnce(transaction);

await expect(accounts.signTransaction(transaction, 'pk', callback)).resolves.toEqual('signed-transaction');

expect(callback).toHaveBeenCalledWith(false, 'signed-transaction');

expect(Account.fromPrivateKey).toHaveBeenCalledWith('pk', accounts);

expect(transactionSignerMock.sign).toHaveBeenCalledWith(mappedTransaction, account.privateKey);

expect(formatters.inputCallFormatter).toHaveBeenCalledWith(transaction, accounts);
});

it('calls signTransaction with the nonce set to undefined and resolves with a promise', async () => {
const callback = jest.fn();

const transaction = {
from: 0,
gas: 1,
gasPrice: 1,
nonce: undefined,
chainId: 1
};

const mappedTransaction = {
from: 0,
gas: 1,
Expand Down