mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
Move mock txs to tx mocking class
This commit is contained in:
parent
1ffb406480
commit
c76194d7c3
40
test/lib/mock-tx-gen.js
Normal file
40
test/lib/mock-tx-gen.js
Normal file
@ -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
|
@ -1,5 +1,6 @@
|
||||
const assert = require('assert')
|
||||
const NonceTracker = require('../../app/scripts/lib/nonce-tracker')
|
||||
const MockTxGen = require('../lib/mock-tx-gen')
|
||||
|
||||
describe('Nonce Tracker', function () {
|
||||
let nonceTracker, provider
|
||||
@ -8,41 +9,9 @@ describe('Nonce Tracker', function () {
|
||||
let providerResultStub = {}
|
||||
|
||||
beforeEach(function () {
|
||||
pendingTxs = [{
|
||||
'status': 'submitted',
|
||||
'txParams': {
|
||||
'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
|
||||
'gas': '0x30d40',
|
||||
'value': '0x0',
|
||||
'nonce': '0x3',
|
||||
},
|
||||
}]
|
||||
confirmedTxs = [{
|
||||
'status': 'confirmed',
|
||||
'txParams': {
|
||||
'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
|
||||
'gas': '0x30d40',
|
||||
'value': '0x0',
|
||||
'nonce': '0x0',
|
||||
},
|
||||
}, {
|
||||
'status': 'confirmed',
|
||||
'txParams': {
|
||||
'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
|
||||
'gas': '0x30d40',
|
||||
'value': '0x0',
|
||||
'nonce': '0x1',
|
||||
},
|
||||
}, {
|
||||
'status': 'confirmed',
|
||||
'txParams': {
|
||||
'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
|
||||
'gas': '0x30d40',
|
||||
'value': '0x0',
|
||||
'nonce': '0x2',
|
||||
},
|
||||
}]
|
||||
|
||||
const txGen = new MockTxGen()
|
||||
confirmedTxs = txGen.generate({ status: 'confirmed' }, { count: 3 })
|
||||
pendingTxs = txGen.generate({ status: 'pending' }, { count: 1 })
|
||||
|
||||
getPendingTransactions = () => pendingTxs
|
||||
getConfirmedTransactions = () => confirmedTxs
|
||||
@ -68,6 +37,10 @@ describe('Nonce Tracker', function () {
|
||||
await nonceLock.releaseLock()
|
||||
})
|
||||
|
||||
it('should return 0 if there are no previous transactions', async function () {
|
||||
|
||||
})
|
||||
|
||||
it('should use localNonce if network returns a nonce lower then a confirmed tx in state', async function () {
|
||||
this.timeout(15000)
|
||||
providerResultStub.result = '0x1'
|
||||
|
Loading…
Reference in New Issue
Block a user