aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-12-28 09:45:03 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-12-28 09:45:03 +0800
commit8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7 (patch)
treede66e91bb0c1b0565d73142c4bce6b733de75592
parent5efb0044d8e334d6c4ec2b5d68e830932eb96ed7 (diff)
downloadtangerine-wallet-browser-8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7.tar
tangerine-wallet-browser-8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7.tar.gz
tangerine-wallet-browser-8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7.tar.bz2
tangerine-wallet-browser-8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7.tar.lz
tangerine-wallet-browser-8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7.tar.xz
tangerine-wallet-browser-8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7.tar.zst
tangerine-wallet-browser-8bd942d40629d8d68dd98b0bb8d10bf60d3e92c7.zip
add tests for #_checkIfNonceIsTaken
-rw-r--r--test/unit/pending-tx-test.js63
1 files changed, 61 insertions, 2 deletions
diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js
index 393601a57..0b557f055 100644
--- a/test/unit/pending-tx-test.js
+++ b/test/unit/pending-tx-test.js
@@ -328,7 +328,7 @@ describe('PendingTransactionTracker', function () {
it('should publish the transaction if the number of blocks since last retry exceeds the last set limit', function (done) {
const enoughBalance = '0x100000'
const mockLatestBlockNumber = '0x11'
-
+
pendingTxTracker._resubmitTx(txMetaToTestExponentialBackoff, mockLatestBlockNumber)
.then(() => done())
.catch((err) => {
@@ -338,5 +338,64 @@ describe('PendingTransactionTracker', function () {
assert.equal(pendingTxTracker.publishTransaction.callCount, 1, 'Should call publish transaction')
})
- })
+ })
+
+ describe('#_checkIfNonceIsTaken', function () {
+ beforeEach ( function () {
+ let confirmedTxList = [{
+ id: 1,
+ hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
+ status: 'confirmed',
+ txParams: {
+ from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
+ nonce: '0x1',
+ value: '0xfffff',
+ },
+ rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
+ }, {
+ id: 2,
+ hash: '0x0593ee121b92e10d63150ad08b4b8f9c7857d1bd160195ee648fb9a0f8d00eeb',
+ status: 'confirmed',
+ txParams: {
+ from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
+ nonce: '0x2',
+ value: '0xfffff',
+ },
+ rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
+ }]
+ pendingTxTracker.getCompletedTransactions = (address) => {
+ if (!address) throw new Error('unless behavior has changed #_checkIfNonceIsTaken needs a filtered list of transactions to see if the nonce is taken')
+ return confirmedTxList
+ }
+ })
+
+ it('should return false', function (done) {
+ pendingTxTracker._checkIfNonceIsTaken({
+ txParams: {
+ from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
+ nonce: '0x3',
+ value: '0xfffff',
+ },
+ })
+ .then((taken) => {
+ assert.ok(!taken)
+ done()
+ })
+ .catch(done)
+ })
+
+ it('should return true', function (done) {
+ pendingTxTracker._checkIfNonceIsTaken({
+ txParams: {
+ from: '0x1678a085c290ebd122dc42cba69373b5953b831d',
+ nonce: '0x2',
+ value: '0xfffff',
+ },
+ }).then((taken) => {
+ assert.ok(taken)
+ done()
+ })
+ .catch(done)
+ })
+ })
})