aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAkshit Kr Nagpal <nagpalkrakshit@gmail.com>2019-06-29 06:51:51 +0800
committerFrankie <frankie.diamond@gmail.com>2019-06-29 06:51:51 +0800
commitd16d6f483c28c07aedcaa0bc69228109fa5fbade (patch)
tree007c42ba91000b13dcf590c0cca564e4ea0fbbd4 /test
parent90eb5c44406aaf0be68a1bb366cf98023a2214b2 (diff)
downloadtangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar.gz
tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.tar.zst
tangerine-wallet-browser-d16d6f483c28c07aedcaa0bc69228109fa5fbade.zip
Validate txParams in TransactionStateManager.addTx (#6713)
* Normalize and Validate txParams in TransactionStateManager.addTx too * Added Tests * Updated normalizeAndValidateParams to return the new txParams
Diffstat (limited to 'test')
-rw-r--r--test/unit/app/controllers/transactions/tx-state-manager-test.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/unit/app/controllers/transactions/tx-state-manager-test.js b/test/unit/app/controllers/transactions/tx-state-manager-test.js
index 4ccade2aa..72dbbc4a1 100644
--- a/test/unit/app/controllers/transactions/tx-state-manager-test.js
+++ b/test/unit/app/controllers/transactions/tx-state-manager-test.js
@@ -93,6 +93,37 @@ describe('TransactionStateManager', function () {
assert.equal(result[0].id, 1)
})
+ it('throws error and does not add tx if txParams are invalid', function () {
+ const validTxParams = {
+ from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
+ to: '0x0039f22efb07a647557c7c5d17854cfd6d489ef3',
+ nonce: '0x3',
+ gas: '0x77359400',
+ gasPrice: '0x77359400',
+ value: '0x0',
+ data: '0x0',
+ }
+ const invalidValues = [1, true, {}, Symbol('1')]
+
+ for (const key in validTxParams) {
+ for (const value of invalidValues) {
+ const tx = {
+ id: 1,
+ status: 'unapproved',
+ metamaskNetworkId: currentNetworkId,
+ txParams: {
+ ...validTxParams,
+ [key]: value,
+ },
+ }
+ assert.throws(txStateManager.addTx.bind(txStateManager, tx), 'addTx should throw error')
+ const result = txStateManager.getTxList()
+ assert.ok(Array.isArray(result), 'txList should be an array')
+ assert.equal(result.length, 0, 'txList should be empty')
+ }
+ }
+ })
+
it('does not override txs from other networks', function () {
const tx = { id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} }
const tx2 = { id: 2, status: 'confirmed', metamaskNetworkId: otherNetworkId, txParams: {} }
@@ -153,6 +184,37 @@ describe('TransactionStateManager', function () {
assert.equal(result.hash, 'foo')
})
+ it('throws error and does not update tx if txParams are invalid', function () {
+ const validTxParams = {
+ from: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
+ to: '0x0039f22efb07a647557c7c5d17854cfd6d489ef3',
+ nonce: '0x3',
+ gas: '0x77359400',
+ gasPrice: '0x77359400',
+ value: '0x0',
+ data: '0x0',
+ }
+ const invalidValues = [1, true, {}, Symbol('1')]
+
+ txStateManager.addTx({ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: validTxParams })
+
+ for (const key in validTxParams) {
+ for (const value of invalidValues) {
+ const originalTx = txStateManager.getTx(1)
+ const newTx = {
+ ...originalTx,
+ txParams: {
+ ...originalTx.txParams,
+ [key]: value,
+ },
+ }
+ assert.throws(txStateManager.updateTx.bind(txStateManager, newTx), 'updateTx should throw an error')
+ const result = txStateManager.getTx(1)
+ assert.deepEqual(result, originalTx, 'tx should not be updated')
+ }
+ }
+ })
+
it('updates gas price and adds history items', function () {
const originalGasPrice = '0x01'
const desiredGasPrice = '0x02'