|
| 1 | +if (process.browser) { |
| 2 | + throw new Error('bitgo express tests not supported in browser'); |
| 3 | +} |
| 4 | + |
| 5 | +const request = require('supertest-as-promised'); |
| 6 | +const Promise = require('bluebird'); |
| 7 | +const co = Promise.coroutine; |
| 8 | +const BN = require('ethereumjs-util').BN; |
| 9 | + |
| 10 | +const expressApp = require('../src/expressApp'); |
| 11 | +const TestBitGo = require('./lib/test_bitgo'); |
| 12 | +const testUtil = require('./testutil'); |
| 13 | + |
| 14 | + |
| 15 | +// this should exist on the test env hand have some eth funding |
| 16 | +const testWalletId = '598f606cd8fc24710d2ebadb1d9459bb'; |
| 17 | +const testWalletPassphrase = 'moon'; |
| 18 | + |
| 19 | +// this address belongs to the test wallet |
| 20 | +const testWalletFirstAddress = '0xdf07117705a9f8dc4c2a78de66b7f1797dba9d4e'; |
| 21 | + |
| 22 | +describe('Bitgo Express TETH v2', function () { |
| 23 | + let agent; |
| 24 | + |
| 25 | + const authHeader = { |
| 26 | + Authorization: 'Bearer ' + TestBitGo.TEST_ACCESSTOKEN |
| 27 | + }; |
| 28 | + |
| 29 | + before(co(function *() { |
| 30 | + let args = { |
| 31 | + debug: false, |
| 32 | + env: 'test', |
| 33 | + logfile: '/dev/null', |
| 34 | + }; |
| 35 | + let bitgo = new TestBitGo(); |
| 36 | + bitgo.initializeTestVars(); |
| 37 | + let app = expressApp(args); |
| 38 | + agent = request.agent(app); |
| 39 | + yield testUtil.unlockToken(agent, TestBitGo.TEST_ACCESSTOKEN, 15); |
| 40 | + })); |
| 41 | + |
| 42 | + it('can create new wallet and delete it', co(function *() { |
| 43 | + const label = 'bitgoExpressEth.js temporary test wallet'; |
| 44 | + let res = yield agent |
| 45 | + .post('/api/v2/teth/wallet/generate') |
| 46 | + .set(authHeader) |
| 47 | + .send({ passphrase: testWalletPassphrase, label }); |
| 48 | + res.statusCode.should.equal(200); |
| 49 | + |
| 50 | + res = yield agent |
| 51 | + .delete(`/api/v2/teth/wallet/${res.body.id}`) |
| 52 | + .set(authHeader) |
| 53 | + .send({ passphrase: testWalletPassphrase }); |
| 54 | + res.statusCode.should.equal(200); |
| 55 | + })); |
| 56 | + |
| 57 | + it('can list wallets', co(function *() { |
| 58 | + let res = yield agent |
| 59 | + .get('/api/v2/teth/wallet') |
| 60 | + .set(authHeader); |
| 61 | + res.statusCode.should.equal(200); |
| 62 | + res.body.wallets.length.should.not.equal(0); |
| 63 | + })); |
| 64 | + |
| 65 | + it('can fetch testWallet', co(function *() { |
| 66 | + let res = yield agent |
| 67 | + .get(`/api/v2/teth/wallet/${testWalletId}`) |
| 68 | + .set(authHeader); |
| 69 | + res.statusCode.should.equal(200); |
| 70 | + res.body.id.should.equal(testWalletId); |
| 71 | + |
| 72 | + ((new BN(res.body.spendableBalanceString)).gt(0)).should.equal(true); |
| 73 | + })); |
| 74 | + |
| 75 | + it('can list deposit addresses', co(function *() { |
| 76 | + let res = yield agent |
| 77 | + .get(`/api/v2/teth/wallet/${testWalletId}/addresses`) |
| 78 | + .set(authHeader); |
| 79 | + res.statusCode.should.equal(200); |
| 80 | + res.body.addresses |
| 81 | + .filter(({ address }) => address === testWalletFirstAddress).length |
| 82 | + .should.equal(1); |
| 83 | + })); |
| 84 | + |
| 85 | + it('can create new address', co(function *() { |
| 86 | + let res = yield agent |
| 87 | + .post(`/api/v2/teth/wallet/${testWalletId}/address`) |
| 88 | + .set(authHeader); |
| 89 | + res.statusCode.should.equal(200); |
| 90 | + })); |
| 91 | + |
| 92 | + it('can do sendcoins', co(function *() { |
| 93 | + // fetch one new address |
| 94 | + let res = yield agent |
| 95 | + .post(`/api/v2/teth/wallet/${testWalletId}/address`) |
| 96 | + .set(authHeader); |
| 97 | + res.statusCode.should.equal(200); |
| 98 | + let { address } = res.body; |
| 99 | + |
| 100 | + res = yield agent |
| 101 | + .post(`/api/v2/teth/wallet/${testWalletId}/sendcoins`) |
| 102 | + .set(authHeader) |
| 103 | + .send({ |
| 104 | + walletPassphrase: testWalletPassphrase, |
| 105 | + address: address, |
| 106 | + amount: '10000' |
| 107 | + }); |
| 108 | + res.statusCode.should.equal(200); |
| 109 | + })); |
| 110 | + |
| 111 | + // Disabled, see JIRA BG-994 |
| 112 | + xit('can do sendmany', co(function *() { |
| 113 | + // fetch two new address |
| 114 | + let res, address1, address2; |
| 115 | + res = yield agent.post(`/api/v2/teth/wallet/${testWalletId}/address`).set(authHeader); |
| 116 | + address1 = res.body.address; |
| 117 | + res = yield agent.post(`/api/v2/teth/wallet/${testWalletId}/address`).set(authHeader); |
| 118 | + address2 = res.body.address; |
| 119 | + |
| 120 | + res = yield agent |
| 121 | + .post(`/api/v2/teth/wallet/${testWalletId}/sendmany`) |
| 122 | + .set(authHeader) |
| 123 | + .send({ |
| 124 | + recipients: [ |
| 125 | + { address: address1, amount: '10000' }, |
| 126 | + { address: address2, amount: '20000' }, |
| 127 | + ] |
| 128 | + }); |
| 129 | + res.statusCode.should.equal(200); |
| 130 | + })); |
| 131 | +}); |
0 commit comments