aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDan Finlay <flyswatter@users.noreply.github.com>2017-01-03 06:04:27 +0800
committerGitHub <noreply@github.com>2017-01-03 06:04:27 +0800
commit25d0ac147668e45da43a4dd74876e3e22bd6a246 (patch)
tree6a81531e5398afc26685e7b0523c7526dabd0f7f /test
parentedc5f9e821bf18fa6ec984e645790fba3457d0bb (diff)
parentfb002dc44eae82e0471b8b52acecc61ba5f39332 (diff)
downloadtangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar
tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.gz
tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.bz2
tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.lz
tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.xz
tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.tar.zst
tangerine-wallet-browser-25d0ac147668e45da43a4dd74876e3e22bd6a246.zip
Merge branch 'dev' into ShowDifferentAccounts
Diffstat (limited to 'test')
-rw-r--r--test/lib/mock-config-manager.js1
-rw-r--r--test/unit/config-manager-test.js83
-rw-r--r--test/unit/idStore-migration-test.js4
-rw-r--r--test/unit/idStore-test.js50
-rw-r--r--test/unit/keyring-controller-test.js4
-rw-r--r--test/unit/metamask-controller-test.js2
-rw-r--r--test/unit/tx-manager-test.js190
7 files changed, 203 insertions, 131 deletions
diff --git a/test/lib/mock-config-manager.js b/test/lib/mock-config-manager.js
index ccd518c68..b79f63090 100644
--- a/test/lib/mock-config-manager.js
+++ b/test/lib/mock-config-manager.js
@@ -9,6 +9,7 @@ module.exports = function() {
function loadData () {
var oldData = getOldStyleData()
var newData
+
try {
newData = JSON.parse(window.localStorage[STORAGE_KEY])
} catch (e) {}
diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js
index 477188b67..075abbe65 100644
--- a/test/unit/config-manager-test.js
+++ b/test/unit/config-manager-test.js
@@ -215,7 +215,7 @@ describe('config-manager', function() {
describe('transactions', function() {
beforeEach(function() {
- configManager._saveTxList([])
+ configManager.setTxList([])
})
describe('#getTxList', function() {
@@ -226,90 +226,13 @@ describe('config-manager', function() {
})
})
- describe('#_saveTxList', function() {
+ describe('#setTxList', function() {
it('saves the submitted data to the tx list', function() {
var target = [{ foo: 'bar' }]
- configManager._saveTxList(target)
+ configManager.setTxList(target)
var result = configManager.getTxList()
assert.equal(result[0].foo, 'bar')
})
})
-
- describe('#addTx', function() {
- it('adds a tx returned in getTxList', function() {
- var tx = { id: 1 }
- configManager.addTx(tx)
- var result = configManager.getTxList()
- assert.ok(Array.isArray(result))
- assert.equal(result.length, 1)
- assert.equal(result[0].id, 1)
- })
-
- it('cuts off early txs beyond a limit', function() {
- const limit = configManager.txLimit
- for (let i = 0; i < limit + 1; i++) {
- let tx = { id: i }
- configManager.addTx(tx)
- }
- var result = configManager.getTxList()
- assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
- assert.equal(result[0].id, 1, 'early txs truncted')
- })
- })
-
- describe('#confirmTx', function() {
- it('sets the tx status to confirmed', function() {
- var tx = { id: 1, status: 'unconfirmed' }
- configManager.addTx(tx)
- configManager.confirmTx(1)
- var result = configManager.getTxList()
- assert.ok(Array.isArray(result))
- assert.equal(result.length, 1)
- assert.equal(result[0].status, 'confirmed')
- })
- })
-
- describe('#rejectTx', function() {
- it('sets the tx status to rejected', function() {
- var tx = { id: 1, status: 'unconfirmed' }
- configManager.addTx(tx)
- configManager.rejectTx(1)
- var result = configManager.getTxList()
- assert.ok(Array.isArray(result))
- assert.equal(result.length, 1)
- assert.equal(result[0].status, 'rejected')
- })
- })
-
- describe('#updateTx', function() {
- it('replaces the tx with the same id', function() {
- configManager.addTx({ id: '1', status: 'unconfirmed' })
- configManager.addTx({ id: '2', status: 'confirmed' })
- configManager.updateTx({ id: '1', status: 'blah', hash: 'foo' })
- var result = configManager.getTx('1')
- assert.equal(result.hash, 'foo')
- })
- })
-
- describe('#unconfirmedTxs', function() {
- it('returns unconfirmed txs in a hash', function() {
- configManager.addTx({ id: '1', status: 'unconfirmed' })
- configManager.addTx({ id: '2', status: 'confirmed' })
- let result = configManager.unconfirmedTxs()
- assert.equal(typeof result, 'object')
- assert.equal(result['1'].status, 'unconfirmed')
- assert.equal(result['0'], undefined)
- assert.equal(result['2'], undefined)
- })
- })
-
- describe('#getTx', function() {
- it('returns a tx with the requested id', function() {
- configManager.addTx({ id: '1', status: 'unconfirmed' })
- configManager.addTx({ id: '2', status: 'confirmed' })
- assert.equal(configManager.getTx('1').status, 'unconfirmed')
- assert.equal(configManager.getTx('2').status, 'confirmed')
- })
- })
})
})
diff --git a/test/unit/idStore-migration-test.js b/test/unit/idStore-migration-test.js
index ad4ce2096..54f38fb2f 100644
--- a/test/unit/idStore-migration-test.js
+++ b/test/unit/idStore-migration-test.js
@@ -68,6 +68,10 @@ describe('IdentityStore to KeyringController migration', function() {
addAccount(acct) { newAccounts.push(ethUtil.addHexPrefix(acct)) },
del(acct) { delete newAccounts[acct] },
},
+ txManager: {
+ getTxList: () => [],
+ getUnapprovedTxList: () => []
+ },
})
// Stub out the browser crypto for a mock encryptor.
diff --git a/test/unit/idStore-test.js b/test/unit/idStore-test.js
index 3ca89cd38..000c58a82 100644
--- a/test/unit/idStore-test.js
+++ b/test/unit/idStore-test.js
@@ -139,54 +139,4 @@ describe('IdentityStore', function() {
})
})
})
-
- describe('#addGasBuffer', function() {
- it('formats the result correctly', function() {
- const idStore = new IdentityStore({
- configManager: configManagerGen(),
- ethStore: {
- addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
- },
- })
-
- const gas = '0x01'
- const bnGas = new BN(gas, 16)
- const bnResult = idStore.addGasBuffer(bnGas)
-
- assert.ok(bnResult.gt(gas), 'added more gas as buffer.')
- })
-
- it('buffers 20%', function() {
- const idStore = new IdentityStore({
- configManager: configManagerGen(),
- ethStore: {
- addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
- },
- })
-
- const gas = '0x04ee59' // Actual estimated gas example
- const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
- const five = new BN('5', 10)
- const correctBuffer = bnGas.div(five)
- const correct = bnGas.add(correctBuffer)
-
- const bnResult = idStore.addGasBuffer(bnGas)
-
- assert(bnResult.gt(bnGas), 'Estimate increased in value.')
- assert.equal(bnResult.sub(bnGas).toString(10), correctBuffer.toString(10), 'added 20% gas')
- })
- })
-
- describe('#checkForDelegateCall', function() {
- const idStore = new IdentityStore({
- configManager: configManagerGen(),
- ethStore: {
- addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
- },
- })
-
- var result = idStore.checkForDelegateCall(delegateCallCode)
- assert.equal(result, true, 'no delegate call in provided code')
- })
-
})
diff --git a/test/unit/keyring-controller-test.js b/test/unit/keyring-controller-test.js
index 8bb1126fa..37fd7175e 100644
--- a/test/unit/keyring-controller-test.js
+++ b/test/unit/keyring-controller-test.js
@@ -23,6 +23,10 @@ describe('KeyringController', function() {
keyringController = new KeyringController({
configManager: configManagerGen(),
+ txManager: {
+ getTxList: () => [],
+ getUnapprovedTxList: () => []
+ },
ethStore: {
addAccount(acct) { accounts.push(ethUtil.addHexPrefix(acct)) },
},
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js
index b87169ca2..414610404 100644
--- a/test/unit/metamask-controller-test.js
+++ b/test/unit/metamask-controller-test.js
@@ -9,7 +9,7 @@ describe('MetaMaskController', function() {
let controller = new MetaMaskController({
showUnconfirmedMessage: noop,
unlockAccountMessage: noop,
- showUnconfirmedTx: noop,
+ showUnapprovedTx: noop,
setData,
loadData,
})
diff --git a/test/unit/tx-manager-test.js b/test/unit/tx-manager-test.js
new file mode 100644
index 000000000..be16facad
--- /dev/null
+++ b/test/unit/tx-manager-test.js
@@ -0,0 +1,190 @@
+const assert = require('assert')
+const extend = require('xtend')
+const EventEmitter = require('events')
+const STORAGE_KEY = 'metamask-persistance-key'
+const TransactionManager = require('../../app/scripts/transaction-manager')
+
+describe('Transaction Manager', function() {
+ let txManager
+
+ const onTxDoneCb = () => true
+ beforeEach(function() {
+ txManager = new TransactionManager ({
+ txList: [],
+ setTxList: () => {},
+ provider: "testnet",
+ txHistoryLimit: 10,
+ blockTracker: new EventEmitter(),
+ })
+ })
+
+ describe('#getTxList', function() {
+ it('when new should return empty array', function() {
+ var result = txManager.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 0)
+ })
+ it('should also return transactions from local storage if any', function() {
+
+ })
+ })
+
+ describe('#_saveTxList', function() {
+ it('saves the submitted data to the tx list', function() {
+ var target = [{ foo: 'bar' }]
+ txManager._saveTxList(target)
+ var result = txManager.getTxList()
+ assert.equal(result[0].foo, 'bar')
+ })
+ })
+
+ describe('#addTx', function() {
+ it('adds a tx returned in getTxList', function() {
+ var tx = { id: 1, status: 'confirmed',}
+ txManager.addTx(tx, onTxDoneCb)
+ var result = txManager.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 1)
+ assert.equal(result[0].id, 1)
+ })
+
+ 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'}
+ txManager.addTx(tx, onTxDoneCb)
+ }
+ var result = txManager.getTxList()
+ assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
+ assert.equal(result[0].id, 1, 'early txs truncted')
+ })
+
+ it('cuts off early txs beyond a limit weather 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'}
+ txManager.addTx(tx, onTxDoneCb)
+ }
+ var result = txManager.getTxList()
+ assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
+ assert.equal(result[0].id, 1, 'early txs truncted')
+ })
+
+ it('cuts off early txs beyond a limit but does not cut unapproved txs', function() {
+ var unconfirmedTx = { id: 0, time: new Date(), status: 'unapproved'}
+ txManager.addTx(unconfirmedTx, onTxDoneCb)
+ const limit = txManager.txHistoryLimit
+ for (let i = 1; i < limit + 1; i++) {
+ let tx = { id: i, time: new Date(), status: 'confirmed'}
+ txManager.addTx(tx, onTxDoneCb)
+ }
+ var result = txManager.getTxList()
+ assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
+ assert.equal(result[0].id, 0, 'first tx should still be there')
+ assert.equal(result[0].status, 'unapproved', 'first tx should be unapproved')
+ assert.equal(result[1].id, 2, 'early txs truncted')
+ })
+ })
+
+ describe('#setTxStatusSigned', function() {
+ it('sets the tx status to signed', function() {
+ var tx = { id: 1, status: 'unapproved' }
+ txManager.addTx(tx, onTxDoneCb)
+ txManager.setTxStatusSigned(1)
+ var result = txManager.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 1)
+ assert.equal(result[0].status, 'signed')
+ })
+
+ it('should emit a signed event to signal the exciton of callback', (done) => {
+ this.timeout(10000)
+ var tx = { id: 1, status: 'unapproved' }
+ let onTxDoneCb = function (err, txId) {
+ assert(true, 'event listener has been triggered and onTxDoneCb executed')
+ done()
+ }
+ txManager.addTx(tx, onTxDoneCb)
+ txManager.setTxStatusSigned(1)
+ })
+ })
+
+ describe('#setTxStatusRejected', function() {
+ it('sets the tx status to rejected', function() {
+ var tx = { id: 1, status: 'unapproved' }
+ txManager.addTx(tx, onTxDoneCb)
+ txManager.setTxStatusRejected(1)
+ var result = txManager.getTxList()
+ assert.ok(Array.isArray(result))
+ assert.equal(result.length, 1)
+ assert.equal(result[0].status, 'rejected')
+ })
+
+ it('should emit a rejected event to signal the exciton of callback', (done) => {
+ this.timeout(10000)
+ var tx = { id: 1, status: 'unapproved' }
+ let onTxDoneCb = function (err, txId) {
+ assert(true, 'event listener has been triggered and onTxDoneCb executed')
+ done()
+ }
+ txManager.addTx(tx, onTxDoneCb)
+ txManager.setTxStatusRejected(1)
+ })
+
+ })
+
+ describe('#updateTx', function() {
+ it('replaces the tx with the same id', function() {
+ txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb)
+ txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb)
+ txManager.updateTx({ id: '1', status: 'blah', hash: 'foo' })
+ var result = txManager.getTx('1')
+ assert.equal(result.hash, 'foo')
+ })
+ })
+
+ describe('#getUnapprovedTxList', function() {
+ it('returns unapproved txs in a hash', function() {
+ txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb)
+ txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb)
+ let result = txManager.getUnapprovedTxList()
+ assert.equal(typeof result, 'object')
+ assert.equal(result['1'].status, 'unapproved')
+ assert.equal(result['2'], undefined)
+ })
+ })
+
+ describe('#getTx', function() {
+ it('returns a tx with the requested id', function() {
+ txManager.addTx({ id: '1', status: 'unapproved' }, onTxDoneCb)
+ txManager.addTx({ id: '2', status: 'confirmed' }, onTxDoneCb)
+ assert.equal(txManager.getTx('1').status, 'unapproved')
+ assert.equal(txManager.getTx('2').status, 'confirmed')
+ })
+ })
+
+ describe('#getFilteredTxList', function() {
+ it('returns a tx with the requested data', function() {
+ var foop = 0
+ var zoop = 0
+ for (let i = 0; i < 10; ++i ){
+ let everyOther = i % 2
+ txManager.addTx({ id: i,
+ status: everyOther ? 'unapproved' : 'confirmed',
+ txParams: {
+ from: everyOther ? 'foop' : 'zoop',
+ to: everyOther ? 'zoop' : 'foop',
+ }
+ }, onTxDoneCb)
+ everyOther ? ++foop : ++zoop
+ }
+ assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'zoop'}).length, zoop)
+ assert.equal(txManager.getFilteredTxList({status: 'confirmed', to: 'foop'}).length, zoop)
+ assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'foop'}).length, 0)
+ assert.equal(txManager.getFilteredTxList({status: 'confirmed'}).length, zoop)
+ assert.equal(txManager.getFilteredTxList({from: 'foop'}).length, foop)
+ assert.equal(txManager.getFilteredTxList({from: 'zoop'}).length, zoop)
+ })
+ })
+
+})