1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/test/lib/mock-tx-gen.js

42 lines
774 B
JavaScript
Raw Normal View History

import { BN } from 'ethereumjs-util'
2017-08-21 20:35:18 +02:00
const template = {
'status': 'submitted',
'history': [{}],
2017-08-21 20:35:18 +02:00
'txParams': {
'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
'gas': '0x30d40',
'value': '0x0',
'nonce': '0x3',
},
}
class TxGenerator {
constructor () {
this.txs = []
}
generate (tx = {}, opts = {}) {
2018-07-03 00:49:33 +02:00
const { count, fromNonce } = opts
2017-08-21 20:35:18 +02:00
let nonce = fromNonce || this.txs.length
2018-07-03 00:49:33 +02:00
const txs = []
2017-08-21 20:35:18 +02:00
for (let i = 0; i < count; i++) {
txs.push(Object.assign({}, template, {
2017-08-21 20:35:18 +02:00
txParams: {
nonce: hexify(nonce++),
2018-07-03 00:49:33 +02:00
},
2017-08-21 20:35:18 +02:00
}, tx))
}
this.txs = this.txs.concat(txs)
return txs
}
}
function hexify (number) {
return '0x' + (new BN(number)).toString(16)
}
export default TxGenerator