aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-07-14 03:48:50 +0800
committerGitHub <noreply@github.com>2017-07-14 03:48:50 +0800
commit9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc (patch)
tree7fcde7cce82116803a9df3586ad5d91fe812d870 /test
parent43b7d5f0ebd420d39eb9257b1edc235d58b0099d (diff)
parent7eccf5905a830853bbb1932dde9a7f4536d43f55 (diff)
downloadtangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar.gz
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.tar.zst
tangerine-wallet-browser-9d3207fb7302e74d3d2f8ffad12d50dfd3885fdc.zip
Merge pull request #1617 from MetaMask/nonce-tracker
transaction controller - use nonce-tracker
Diffstat (limited to 'test')
-rw-r--r--test/unit/nodeify-test.js2
-rw-r--r--test/unit/nonce-tracker-test.js40
-rw-r--r--test/unit/tx-controller-test.js37
3 files changed, 55 insertions, 24 deletions
diff --git a/test/unit/nodeify-test.js b/test/unit/nodeify-test.js
index 5aed758fa..06241334d 100644
--- a/test/unit/nodeify-test.js
+++ b/test/unit/nodeify-test.js
@@ -11,7 +11,7 @@ describe('nodeify', function () {
}
it('should retain original context', function (done) {
- var nodified = nodeify(obj.promiseFunc).bind(obj)
+ var nodified = nodeify(obj.promiseFunc, obj)
nodified('baz', function (err, res) {
assert.equal(res, 'barbaz')
done()
diff --git a/test/unit/nonce-tracker-test.js b/test/unit/nonce-tracker-test.js
new file mode 100644
index 000000000..16cd6d008
--- /dev/null
+++ b/test/unit/nonce-tracker-test.js
@@ -0,0 +1,40 @@
+const assert = require('assert')
+const NonceTracker = require('../../app/scripts/lib/nonce-tracker')
+
+describe('Nonce Tracker', function () {
+ let nonceTracker, provider, getPendingTransactions, pendingTxs
+
+
+ beforeEach(function () {
+ pendingTxs = [{
+ 'status': 'submitted',
+ 'txParams': {
+ 'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
+ 'gas': '0x30d40',
+ 'value': '0x0',
+ 'nonce': '0x0',
+ },
+ }]
+
+
+ getPendingTransactions = () => pendingTxs
+ provider = { sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) } }
+ nonceTracker = new NonceTracker({
+ blockTracker: {
+ getCurrentBlock: () => '0x11b568',
+ },
+ provider,
+ getPendingTransactions,
+ })
+ })
+
+ describe('#getNonceLock', function () {
+ it('should work', async function (done) {
+ this.timeout(15000)
+ const nonceLock = await nonceTracker.getNonceLock('0x7d3517b0d011698406d6e0aed8453f0be2697926')
+ assert.equal(nonceLock.nextNonce, '1', 'nonce should be 1')
+ await nonceLock.releaseLock()
+ done()
+ })
+ })
+})
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index 01a498820..7b86cfe14 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -1,5 +1,4 @@
const assert = require('assert')
-const EventEmitter = require('events')
const ethUtil = require('ethereumjs-util')
const EthTx = require('ethereumjs-tx')
const EthQuery = require('eth-query')
@@ -19,15 +18,16 @@ describe('Transaction Controller', function () {
txController = new TransactionController({
networkStore: new ObservableStore(currentNetworkId),
txHistoryLimit: 10,
+ blockTracker: { getCurrentBlock: noop, on: noop, once: noop },
+ provider: { sendAsync: noop },
+ ethQuery: new EthQuery({ sendAsync: noop }),
ethStore: { getState: noop },
- provider: { _blockTracker: new EventEmitter()},
- blockTracker: new EventEmitter(),
- ethQuery: new EthQuery(new EventEmitter()),
signTransaction: (ethTx) => new Promise((resolve) => {
ethTx.sign(privKey)
resolve()
}),
})
+ txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop })
})
describe('#validateTxParams', function () {
@@ -271,56 +271,47 @@ describe('Transaction Controller', function () {
it('does not overwrite set values', function (done) {
+ this.timeout(15000)
const wrongValue = '0x05'
txController.addTx(txMeta)
const estimateStub = sinon.stub(txController.txProviderUtils.query, 'estimateGas')
- .callsArgWith(1, null, wrongValue)
+ .callsArgWithAsync(1, null, wrongValue)
const priceStub = sinon.stub(txController.txProviderUtils.query, 'gasPrice')
- .callsArgWith(0, null, wrongValue)
+ .callsArgWithAsync(0, null, wrongValue)
- const nonceStub = sinon.stub(txController.txProviderUtils.query, 'getTransactionCount')
- .callsArgWith(2, null, wrongValue)
- const signStub = sinon.stub(txController, 'signTransaction')
- .callsArgWith(1, null, noop)
+ const signStub = sinon.stub(txController, 'signTransaction', () => Promise.resolve())
- const pubStub = sinon.stub(txController.txProviderUtils, 'publishTransaction')
- .callsArgWith(1, null, originalValue)
-
- txController.approveTransaction(txMeta.id, (err) => {
- assert.ifError(err, 'should not error')
+ const pubStub = sinon.stub(txController.txProviderUtils, 'publishTransaction', () => Promise.resolve(originalValue))
+ txController.approveTransaction(txMeta.id).then(() => {
const result = txController.getTx(txMeta.id)
const params = result.txParams
assert.equal(params.gas, originalValue, 'gas unmodified')
assert.equal(params.gasPrice, originalValue, 'gas price unmodified')
- assert.equal(params.nonce, originalValue, 'nonce unmodified')
- assert.equal(result.hash, originalValue, 'hash was set')
+ assert.equal(result.hash, originalValue, `hash was set \n got: ${result.hash} \n expected: ${originalValue}`)
estimateStub.restore()
priceStub.restore()
signStub.restore()
- nonceStub.restore()
pubStub.restore()
-
done()
- })
+ }).catch(done)
})
})
describe('#sign replay-protected tx', function () {
it('prepares a tx with the chainId set', function (done) {
txController.addTx({ id: '1', status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, noop)
- txController.signTransaction('1', (err, rawTx) => {
- if (err) return done('it should not fail')
+ txController.signTransaction('1').then((rawTx) => {
const ethTx = new EthTx(ethUtil.toBuffer(rawTx))
assert.equal(ethTx.getChainId(), currentNetworkId)
done()
- })
+ }).catch(done)
})
})