|
|
|
@ -1,10 +1,10 @@ |
|
|
|
|
const assert = require('assert') |
|
|
|
|
const extend = require('xtend') |
|
|
|
|
// const extend = require('xtend')
|
|
|
|
|
const EventEmitter = require('events') |
|
|
|
|
const ethUtil = require('ethereumjs-util') |
|
|
|
|
const EthTx = require('ethereumjs-tx') |
|
|
|
|
const ObservableStore = require('obs-store') |
|
|
|
|
const STORAGE_KEY = 'metamask-persistance-key' |
|
|
|
|
// const STORAGE_KEY = 'metamask-persistance-key'
|
|
|
|
|
const TransactionManager = require('../../app/scripts/transaction-manager') |
|
|
|
|
const noop = () => true |
|
|
|
|
const currentNetworkId = 42 |
|
|
|
@ -22,25 +22,25 @@ describe('Transaction Manager', function() { |
|
|
|
|
signTransaction: (ethTx) => new Promise((resolve) => { |
|
|
|
|
ethTx.sign(privKey) |
|
|
|
|
resolve() |
|
|
|
|
}) |
|
|
|
|
}), |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('#validateTxParams', function () { |
|
|
|
|
it('returns null for positive values', function () { |
|
|
|
|
var sample = { |
|
|
|
|
value: '0x01' |
|
|
|
|
value: '0x01', |
|
|
|
|
} |
|
|
|
|
var res = txManager.txProviderUtils.validateTxParams(sample, (err) => { |
|
|
|
|
txManager.txProviderUtils.validateTxParams(sample, (err) => { |
|
|
|
|
assert.equal(err, null, 'no error') |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('returns error for negative values', function () { |
|
|
|
|
var sample = { |
|
|
|
|
value: '-0x01' |
|
|
|
|
value: '-0x01', |
|
|
|
|
} |
|
|
|
|
var res = txManager.txProviderUtils.validateTxParams(sample, (err) => { |
|
|
|
|
txManager.txProviderUtils.validateTxParams(sample, (err) => { |
|
|
|
|
assert.ok(err, 'error') |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
@ -81,7 +81,7 @@ describe('Transaction Manager', function() { |
|
|
|
|
it('cuts off early txs beyond a limit', function () { |
|
|
|
|
const limit = txManager.txHistoryLimit |
|
|
|
|
for (let i = 0; i < limit + 1; i++) { |
|
|
|
|
let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
const tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
txManager.addTx(tx, noop) |
|
|
|
|
} |
|
|
|
|
var result = txManager.getTxList() |
|
|
|
@ -92,7 +92,7 @@ describe('Transaction Manager', function() { |
|
|
|
|
it('cuts off early txs beyond a limit whether or not it is confirmed or rejected', function () { |
|
|
|
|
const limit = txManager.txHistoryLimit |
|
|
|
|
for (let i = 0; i < limit + 1; i++) { |
|
|
|
|
let tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
const tx = { id: i, time: new Date(), status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
txManager.addTx(tx, noop) |
|
|
|
|
} |
|
|
|
|
var result = txManager.getTxList() |
|
|
|
@ -105,7 +105,7 @@ describe('Transaction Manager', function() { |
|
|
|
|
txManager.addTx(unconfirmedTx, noop) |
|
|
|
|
const limit = txManager.txHistoryLimit |
|
|
|
|
for (let i = 1; i < limit + 1; i++) { |
|
|
|
|
let tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
const tx = { id: i, time: new Date(), status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
txManager.addTx(tx, noop) |
|
|
|
|
} |
|
|
|
|
var result = txManager.getTxList() |
|
|
|
@ -130,7 +130,7 @@ describe('Transaction Manager', function() { |
|
|
|
|
it('should emit a signed event to signal the exciton of callback', (done) => { |
|
|
|
|
this.timeout(10000) |
|
|
|
|
var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
let noop = function () { |
|
|
|
|
const noop = function () { |
|
|
|
|
assert(true, 'event listener has been triggered and noop executed') |
|
|
|
|
done() |
|
|
|
|
} |
|
|
|
@ -155,14 +155,13 @@ describe('Transaction Manager', function() { |
|
|
|
|
this.timeout(10000) |
|
|
|
|
var tx = { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} } |
|
|
|
|
txManager.addTx(tx) |
|
|
|
|
let noop = function (err, txId) { |
|
|
|
|
const noop = function (err, txId) { |
|
|
|
|
assert(true, 'event listener has been triggered and noop executed') |
|
|
|
|
done() |
|
|
|
|
} |
|
|
|
|
txManager.on('1:rejected', noop) |
|
|
|
|
txManager.setTxStatusRejected(1) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('#updateTx', function () { |
|
|
|
@ -179,7 +178,7 @@ describe('Transaction Manager', function() { |
|
|
|
|
it('returns unapproved txs in a hash', function () { |
|
|
|
|
txManager.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop) |
|
|
|
|
txManager.addTx({ id: '2', status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }, noop) |
|
|
|
|
let result = txManager.getUnapprovedTxList() |
|
|
|
|
const result = txManager.getUnapprovedTxList() |
|
|
|
|
assert.equal(typeof result, 'object') |
|
|
|
|
assert.equal(result['1'].status, 'unapproved') |
|
|
|
|
assert.equal(result['2'], undefined) |
|
|
|
@ -197,7 +196,7 @@ describe('Transaction Manager', function() { |
|
|
|
|
|
|
|
|
|
describe('#getFilteredTxList', function () { |
|
|
|
|
it('returns a tx with the requested data', function () { |
|
|
|
|
let txMetas = [ |
|
|
|
|
const txMetas = [ |
|
|
|
|
{ id: 0, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId }, |
|
|
|
|
{ id: 1, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId }, |
|
|
|
|
{ id: 2, status: 'unapproved', txParams: { from: '0xaa', to: '0xbb' }, metamaskNetworkId: currentNetworkId }, |
|
|
|
@ -237,5 +236,4 @@ describe('Transaction Manager', function() { |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|