Skip to content

Commit

Permalink
Merge branch '1.0' into issue/2731
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida committed Apr 26, 2019
2 parents 7718ba5 + 98e3a10 commit 88bd5dc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
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

0 comments on commit 88bd5dc

Please sign in to comment.