aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-03 06:58:05 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-03 06:59:34 +0800
commitb80c7e417bfa3adf338170472ba4c4c6733e8402 (patch)
tree82ed6f3930cdea74edcd8b081112298b8acf613c /test/unit
parent25bc15ba175091513f6d281e9a16f3643fe4b18d (diff)
downloadtangerine-wallet-browser-b80c7e417bfa3adf338170472ba4c4c6733e8402.tar
tangerine-wallet-browser-b80c7e417bfa3adf338170472ba4c4c6733e8402.tar.gz
tangerine-wallet-browser-b80c7e417bfa3adf338170472ba4c4c6733e8402.tar.bz2
tangerine-wallet-browser-b80c7e417bfa3adf338170472ba4c4c6733e8402.tar.lz
tangerine-wallet-browser-b80c7e417bfa3adf338170472ba4c4c6733e8402.tar.xz
tangerine-wallet-browser-b80c7e417bfa3adf338170472ba4c4c6733e8402.tar.zst
tangerine-wallet-browser-b80c7e417bfa3adf338170472ba4c4c6733e8402.zip
move newUnapprovedTransaction to transactions.js
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/tx-controller-test.js69
1 files changed, 66 insertions, 3 deletions
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index fc70da9a2..c7743a7c6 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -42,6 +42,70 @@ describe('Transaction Controller', function () {
txController.txProviderUtils = new TxProvideUtils(txController.query)
})
+ describe('#newUnapprovedTransaction', function () {
+ let stub, txMeta, txParams
+ beforeEach(function () {
+ txParams = {
+ 'from':'0xc684832530fcbddae4b4230a47e991ddcec2831d',
+ 'to':'0xc684832530fcbddae4b4230a47e991ddcec2831d',
+ },
+ txMeta = {
+ status: 'unapproved',
+ id: 1,
+ metamaskNetworkId: currentNetworkId,
+ txParams,
+ }
+ txController._saveTxList([txMeta])
+ stub = sinon.stub(txController, 'addUnapprovedTransaction').returns(Promise.resolve(txMeta))
+ })
+
+ afterEach(function () {
+ stub.restore()
+ })
+
+ it('should emit newUnaprovedTx event and pass txMeta as the first argument', function (done) {
+ txController.once('newUnaprovedTx', (txMetaFromEmit) => {
+ assert(txMetaFromEmit, 'txMeta is falsey')
+ assert.equal(txMetaFromEmit.id, 1, 'the right txMeta was passed')
+ done()
+ })
+ txController.newUnapprovedTransaction(txParams)
+ .catch(done)
+ })
+
+ it('should resolve when finished and status is submitted and resolve with the hash', function (done) {
+ txController.once('newUnaprovedTx', (txMetaFromEmit) => {
+ setTimeout(() => {
+ console.log('HELLLO')
+ txController.setTxHash(txMetaFromEmit.id, '0x0')
+ txController.setTxStatusSubmitted(txMetaFromEmit.id)
+ }, 10)
+ })
+
+ txController.newUnapprovedTransaction(txParams)
+ .then((hash) => {
+ assert(hash, 'newUnapprovedTransaction needs to return the hash')
+ done()
+ })
+ .catch(done)
+ })
+
+ it('should reject when finished and status is rejected', function (done) {
+ txController.once('newUnaprovedTx', (txMetaFromEmit) => {
+ setTimeout(() => {
+ console.log('HELLLO')
+ txController.setTxStatusRejected(txMetaFromEmit.id)
+ }, 10)
+ })
+
+ txController.newUnapprovedTransaction(txParams)
+ .catch((err) => {
+ if (err.message === 'MetaMask Tx Signature: User denied transaction signature.') done()
+ else done(err)
+ })
+ })
+ })
+
describe('#addUnapprovedTransaction', function () {
it('should add an unapproved transaction and return a valid txMeta', function (done) {
const addTxDefaultsStub = sinon.stub(txController, 'addTxDefaults').callsFake(() => Promise.resolve)
@@ -92,7 +156,7 @@ describe('Transaction Controller', function () {
}
txController.txProviderUtils.validateTxParams(sample).then(() => {
done()
- })
+ }).catch(done)
})
it('returns error for negative values', function (done) {
@@ -407,5 +471,4 @@ describe('Transaction Controller', function () {
})
})
})
-})
-
+}) \ No newline at end of file