aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2017-10-04 07:02:58 +0800
committerGitHub <noreply@github.com>2017-10-04 07:02:58 +0800
commitbd99bc2e88b44b13ca818fbba478bd74eef222e3 (patch)
tree8a653f7015c89305d5c1d35ffc70ab52a30ddb0c /test
parentac4868170f4c61d13291389d01bf1002fe240ed4 (diff)
parentf12504cd09f136fb5ac0d4dd2a6afab8fa6e6524 (diff)
downloadtangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar.gz
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar.bz2
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar.lz
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar.xz
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.tar.zst
tangerine-wallet-browser-bd99bc2e88b44b13ca818fbba478bd74eef222e3.zip
Merge branch 'master' into NewUI-flat
Diffstat (limited to 'test')
-rw-r--r--test/unit/pending-tx-test.js44
-rw-r--r--test/unit/tx-controller-test.js25
-rw-r--r--test/unit/tx-state-history-helper.js23
3 files changed, 36 insertions, 56 deletions
diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js
index 1af464656..6b62bb5b1 100644
--- a/test/unit/pending-tx-test.js
+++ b/test/unit/pending-tx-test.js
@@ -40,14 +40,12 @@ describe('PendingTransactionTracker', function () {
pendingTxTracker = new PendingTransactionTracker({
provider,
- getBalance: () => {},
nonceTracker: {
getGlobalLock: async () => {
return { releaseLock: () => {} }
}
},
getPendingTransactions: () => {return []},
- sufficientBalance: () => {},
publishTransaction: () => {},
})
})
@@ -59,7 +57,7 @@ describe('PendingTransactionTracker', function () {
const block = Proxy.revocable({}, {}).revoke()
pendingTxTracker.checkForTxInBlock(block)
})
- it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) {
+ it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) {
const block = Proxy.revocable({}, {}).revoke()
pendingTxTracker.getPendingTransactions = () => [txMetaNoHash]
pendingTxTracker.once('tx:failed', (txId, err) => {
@@ -107,7 +105,7 @@ describe('PendingTransactionTracker', function () {
})
describe('#_checkPendingTx', function () {
- it('should emit \'txFailed\' if the txMeta does not have a hash', function (done) {
+ it('should emit \'tx:failed\' if the txMeta does not have a hash', function (done) {
pendingTxTracker.once('tx:failed', (txId, err) => {
assert(txId, txMetaNoHash.id, 'should pass txId')
done()
@@ -174,7 +172,7 @@ describe('PendingTransactionTracker', function () {
.catch(done)
pendingTxTracker.resubmitPendingTxs()
})
- it('should not emit \'txFailed\' if the txMeta throws a known txError', function (done) {
+ it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) {
knownErrors =[
// geth
' Replacement transaction Underpriced ',
@@ -201,8 +199,15 @@ describe('PendingTransactionTracker', function () {
pendingTxTracker.resubmitPendingTxs()
})
- it('should emit \'txFailed\' if it encountered a real error', function (done) {
- pendingTxTracker.once('tx:failed', (id, err) => err.message === 'im some real error' ? txList[id - 1].resolve() : done(err))
+ it('should emit \'tx:warning\' if it encountered a real error', function (done) {
+ pendingTxTracker.once('tx:warning', (txMeta, err) => {
+ if (err.message === 'im some real error') {
+ const matchingTx = txList.find(tx => tx.id === txMeta.id)
+ matchingTx.resolve()
+ } else {
+ done(err)
+ }
+ })
pendingTxTracker.getPendingTransactions = () => txList
pendingTxTracker._resubmitTx = async (tx) => { throw new TypeError('im some real error') }
@@ -213,30 +218,7 @@ describe('PendingTransactionTracker', function () {
pendingTxTracker.resubmitPendingTxs()
})
})
- describe('#_resubmitTx with a too-low balance', function () {
- it('should return before publishing the transaction because to low of balance', function (done) {
- const lowBalance = '0x0'
- pendingTxTracker.getBalance = (address) => {
- assert.equal(address, txMeta.txParams.from, 'Should pass the address')
- return lowBalance
- }
- pendingTxTracker.publishTransaction = async (rawTx) => {
- done(new Error('tried to publish transaction'))
- }
-
- // Stubbing out current account state:
- // Adding the fake tx:
- pendingTxTracker.once('tx:failed', (txId, err) => {
- assert(err, 'Should have a error')
- done()
- })
- pendingTxTracker._resubmitTx(txMeta)
- .catch((err) => {
- assert.ifError(err, 'should not throw an error')
- done(err)
- })
- })
-
+ describe('#_resubmitTx', function () {
it('should publishing the transaction', function (done) {
const enoughBalance = '0x100000'
pendingTxTracker.getBalance = (address) => {
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index 66772ff88..bb51ab01f 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -25,7 +25,6 @@ describe('Transaction Controller', function () {
networkStore: new ObservableStore(currentNetworkId),
txHistoryLimit: 10,
blockTracker: { getCurrentBlock: noop, on: noop, once: noop },
- accountTracker: { store: { getState: noop } },
signTransaction: (ethTx) => new Promise((resolve) => {
ethTx.sign(privKey)
resolve()
@@ -383,30 +382,6 @@ describe('Transaction Controller', function () {
})
})
- describe('#getBalance', function () {
- it('gets balance', function () {
- sinon.stub(txController.accountTracker.store, 'getState').callsFake(() => {
- return {
- accounts: {
- '0x1678a085c290ebd122dc42cba69373b5953b831d': {
- address: '0x1678a085c290ebd122dc42cba69373b5953b831d',
- balance: '0x00000000000000056bc75e2d63100000',
- code: '0x',
- nonce: '0x0',
- },
- '0xc684832530fcbddae4b4230a47e991ddcec2831d': {
- address: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
- balance: '0x0',
- code: '0x',
- nonce: '0x0',
- },
- },
- }
- })
- assert.equal(txController.pendingTxTracker.getBalance('0x1678a085c290ebd122dc42cba69373b5953b831d'), '0x00000000000000056bc75e2d63100000')
- assert.equal(txController.pendingTxTracker.getBalance('0xc684832530fcbddae4b4230a47e991ddcec2831d'), '0x0')
- })
- })
describe('#getPendingTransactions', function () {
beforeEach(function () {
diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js
index 5bb6c9bee..79ee26d6e 100644
--- a/test/unit/tx-state-history-helper.js
+++ b/test/unit/tx-state-history-helper.js
@@ -20,4 +20,27 @@ describe('tx-state-history-helper', function () {
})
})
})
+
+ it('replaying history does not mutate the original obj', function () {
+ const initialState = { test: true, message: 'hello', value: 1 }
+ const diff1 = [{
+ "op": "replace",
+ "path": "/message",
+ "value": "haay",
+ }]
+ const diff2 = [{
+ "op": "replace",
+ "path": "/value",
+ "value": 2,
+ }]
+ const history = [initialState, diff1, diff2]
+
+ const beforeStateSnapshot = JSON.stringify(initialState)
+ const latestState = txStateHistoryHelper.replayHistory(history)
+ const afterStateSnapshot = JSON.stringify(initialState)
+
+ assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state')
+ assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run')
+ })
+
})