Skip to content

Commit

Permalink
FIX #20 nonce is required for RawTx
Browse files Browse the repository at this point in the history
  • Loading branch information
pubkey committed Mar 19, 2019
1 parent 770e8c7 commit 4ea9285
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
48 changes: 41 additions & 7 deletions test/typings.test.js
Expand Up @@ -3,6 +3,7 @@
* run via 'npm run test:typings'
*/
const assert = require('assert');
assert.ok(true);
const path = require('path');
const AsyncTestUtil = require('async-test-util');

Expand Down Expand Up @@ -44,13 +45,9 @@ describe('typings.test.ts', () => {
let x: string = 'foo';
x = 1337;
`;
let thrown = false;
try {
await transpileCode(brokenCode);
} catch (err) {
thrown = true;
}
assert.ok(thrown);
await AsyncTestUtil.assertThrows(
() => transpileCode(brokenCode)
);
});
});
describe('statics', () => {
Expand Down Expand Up @@ -102,5 +99,42 @@ describe('typings.test.ts', () => {
await transpileCode(code);
});
});
describe('rawTx', () => {
/**
* @link https://github.com/pubkey/eth-crypto/issues/20
*/
it('#20 should need a nonce for a RawTx', async () => {
const code = `
(async()=>{
const rawTx: EthCryptoAll.RawTx = {
from: '0xfoobar',
to: '0xfoobar',
value: 10,
gasLimit: 10,
gasPrice: 10,
nonce: 20
};
})();
`;
await transpileCode(code);

const badCodeWithoutNonce = `
(async()=>{
const rawTx: EthCryptoAll.RawTx = {
from: '0xfoobar',
to: '0xfoobar',
value: 10,
gasLimit: 10,
gasPrice: 10
};
})();
`;
await AsyncTestUtil.assertThrows(
() => transpileCode(badCodeWithoutNonce),
Error,
'nonce'
);
});
});
});
});
13 changes: 7 additions & 6 deletions typings/index.d.ts
Expand Up @@ -31,12 +31,13 @@ export type Encrypted = {
};

export type RawTx = {
from: string,
to: string,
value: number | string | BigNumber,
gasLimit: number,
gasPrice: number,
code?: string
from: string;
to: string;
value: number | string | BigNumber;
gasLimit: number;
gasPrice: number;
nonce: number;
code?: string;
};

type signType = (privateKey: string, message: string) => string;
Expand Down

0 comments on commit 4ea9285

Please sign in to comment.