aboutsummaryrefslogtreecommitdiffstats
path: root/test/lib/mock-tx-gen.js
diff options
context:
space:
mode:
authorDan Finlay <flyswatter@users.noreply.github.com>2017-08-24 02:50:27 +0800
committerGitHub <noreply@github.com>2017-08-24 02:50:27 +0800
commitd836e281de099463d8b4a2854f6b6ba0cfcac866 (patch)
treedb3121480869ad5e52cf130fee250e45391c9929 /test/lib/mock-tx-gen.js
parent86d3169423547530691d9547ab0193a195342b38 (diff)
parent09235a59247b93b8882b4cd95dbccb9a0ff5f3e0 (diff)
downloadtangerine-wallet-browser-d836e281de099463d8b4a2854f6b6ba0cfcac866.tar.gz
tangerine-wallet-browser-d836e281de099463d8b4a2854f6b6ba0cfcac866.tar.zst
tangerine-wallet-browser-d836e281de099463d8b4a2854f6b6ba0cfcac866.zip
Merge pull request #1945 from MetaMask/useLocalNonce
Use local nonce
Diffstat (limited to 'test/lib/mock-tx-gen.js')
-rw-r--r--test/lib/mock-tx-gen.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/lib/mock-tx-gen.js b/test/lib/mock-tx-gen.js
new file mode 100644
index 000000000..7aea09c59
--- /dev/null
+++ b/test/lib/mock-tx-gen.js
@@ -0,0 +1,40 @@
+const extend = require('xtend')
+const BN = require('ethereumjs-util').BN
+const template = {
+ 'status': 'submitted',
+ 'txParams': {
+ 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
+ 'gas': '0x30d40',
+ 'value': '0x0',
+ 'nonce': '0x3',
+ },
+}
+
+class TxGenerator {
+
+ constructor () {
+ this.txs = []
+ }
+
+ generate (tx = {}, opts = {}) {
+ let { count, fromNonce } = opts
+ let nonce = fromNonce || this.txs.length
+ let txs = []
+ for (let i = 0; i < count; i++) {
+ txs.push(extend(template, {
+ txParams: {
+ nonce: hexify(nonce++),
+ }
+ }, tx))
+ }
+ this.txs = this.txs.concat(txs)
+ return txs
+ }
+
+}
+
+function hexify (number) {
+ return '0x' + (new BN(number)).toString(16)
+}
+
+module.exports = TxGenerator