Skip to content

Commit

Permalink
add integration tests for hd endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Thore3 committed May 31, 2017
1 parent 19bbec9 commit a39ff7f
Showing 1 changed file with 92 additions and 43 deletions.
135 changes: 92 additions & 43 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,90 +4,139 @@ let request = require('request-promise')
let chai = require('chai')
let expect = chai.expect

before(function (done) {
clientservice.start({ port: config.port }).then(function () {
before((done) => {
clientservice.start({ port: config.port }).then(() => {
done()
})
})

describe('service-integration-testing', function () {
config.testWallets.forEach(function (wallet) {
var address
var url = 'http://localhost:' + config.port + '/merchant/' + wallet.guid
describe('service-integration-testing', () => {
let randString = () => Math.random().toString(36).slice(2)

describe('testing: ' + wallet.guid, function () {
it('should login', function (done) {
makeRequest('/login', { password: wallet.password, api_code: wallet.api_code })
.then(function (result) {
config.testWallets.forEach((wallet) => {
let address
let url = 'http://localhost:' + config.port + '/merchant/' + wallet.guid

let makeRequest = (api, qs = {}) => request({
url: url + api,
method: 'GET',
qs: Object.assign({}, wallet, qs),
json: true
})

describe('testing: ' + wallet.guid, () => {
it('should login', (done) => {
makeRequest('/login')
.then((result) => {
expect(result.success).to.equal(true)
expect(result.message).to.not.be.undefined
done()
})
})

it('should get the balance', function (done) {
makeRequest('/balance', { password: wallet.password, api_code: wallet.api_code })
.then(function (result) {
it('should get the balance', (done) => {
makeRequest('/balance')
.then((result) => {
expect(result.balance).to.be.at.least(0)
done()
})
})

it('should list the addresses', function (done) {
makeRequest('/list', { password: wallet.password, api_code: wallet.api_code })
.then(function (result) {
console.log(result)
it('should generate a new address', (done) => {
makeRequest('/new_address', { label: 'new_address_label' })
.then((result) => {
expect(result.address).to.not.be.undefined
expect(result.label).to.equal('new_address_label')
done()
})
})

it('should list the addresses', (done) => {
makeRequest('/list')
.then((result) => {
expect(result.addresses).to.have.length.above(0)
address = result.addresses[0].address
done()
})
})

it('should get the balance of an address', function (done) {
makeRequest('/address_balance', { password: wallet.password, address: address, api_code: wallet.api_code })
.then(function (result) {
it('should get the balance of an address', (done) => {
makeRequest('/address_balance', { address: address })
.then((result) => {
expect(result.balance).to.be.at.least(0)
expect(result.total_received).to.be.at.least(0)
expect(result.address).to.equal(address)
done()
})
})

it('should generate a new address', function (done) {
makeRequest('/new_address', { password: wallet.password, label: 'new_address_label', api_code: wallet.api_code })
.then(function (result) {
console.log(result)
expect(result.address).to.not.be.undefined
expect(result.label).to.equal('new_address_label')
it('should archive an address', (done) => {
makeRequest('/archive_address', { address: address })
.then((result) => {
expect(result.archived).to.not.be.undefined
done()
})
})

it('should archive an address', function (done) {
makeRequest('/archive_address', { password: wallet.password, address: address, api_code: wallet.api_code })
.then(function (result) {
expect(result.archived).to.not.be.undefined
it('should unarchive an address', (done) => {
makeRequest('/unarchive_address', { address: address })
.then((result) => {
expect(result.active).to.not.be.undefined
done()
})
})

it('should unarchive an address', function (done) {
makeRequest('/unarchive_address', { password: wallet.password, address: address, api_code: wallet.api_code })
.then(function (result) {
expect(result.active).to.not.be.undefined
it('should list hd accounts', (done) => {
makeRequest('/accounts')
.then((result) => {
expect(result).to.have.length.above(0)
expect(result[0]).to.not.be.undefined
done()
})
})

it('should list hd xpubs', (done) => {
makeRequest('/accounts/xpubs')
.then((result) => {
expect(result).to.have.length.above(0)
expect(result[0]).to.not.be.undefined
done()
})
})
})

// Helper functions
function makeRequest (api, qs) {
return request({
url: url + api,
method: 'GET',
qs: qs,
json: true
it('should create a new hd account', (done) => {
let label = randString()
makeRequest('/accounts/create', { label })
.then((result) => {
expect(result.label).to.equal(label)
expect(result.archived).to.equal(false)
expect(result.address_labels).to.have.length.of(0)
done()
})
})
}

it('should get account by index', (done) => {
makeRequest('/accounts/0')
.then((result) => {
expect(result.balance).to.be.at.least(0)
expect(result.index).to.equal(0)
expect(result.archived).to.not.be.undefined
expect(result.extendedPublicKey).to.not.be.undefined
expect(result.extendedPrivateKey).to.not.be.undefined
expect(result.receiveIndex).to.not.be.undefined
expect(result.lastUsedReceiveIndex).to.not.be.undefined
expect(result.receiveAddress).to.not.be.undefined
done()
})
})

it('should get account balance by index', (done) => {
makeRequest('/accounts/0/balance')
.then((result) => {
expect(result.balance).to.be.at.least(0)
done()
})
})
})
})
})

0 comments on commit a39ff7f

Please sign in to comment.