stellar-sdk
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -35,3 +35,3 @@ 'use strict'; | ||
gulp.task('test', function(done) { | ||
runSequence('clean', 'test:run-server', 'test:node', 'test:browser', function (err) { | ||
runSequence('clean', 'test:node', 'test:browser', function (err) { | ||
server.kill(); | ||
@@ -61,7 +61,7 @@ done(); | ||
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader'} | ||
] | ||
], | ||
}, | ||
plugins: [ | ||
// Ignore native modules (ex. ed25519) | ||
new webpack.IgnorePlugin(/\.node/) | ||
// Ignore native modules (ed25519) | ||
new webpack.IgnorePlugin(/ed25519/) | ||
] | ||
@@ -77,7 +77,5 @@ })) | ||
gulp.task('test:node', ['build:node'], function() { | ||
require("babel/register", { | ||
ignore: /node_modules/ | ||
}); | ||
return gulp.src(["test/setup/node.js", "test/unit/**/*.js"]) | ||
return gulp.src(["test/unit/**/*.js"]) | ||
.pipe(plugins.mocha({ | ||
require: ['./test/test-helper.js'], | ||
reporter: ['dot'] | ||
@@ -88,11 +86,15 @@ })); | ||
gulp.task('test:browser', ["build:browser"], function (done) { | ||
var karma = require('karma').server; | ||
karma.start({ configFile: __dirname + '/karma.conf.js' }, function() { | ||
done(); | ||
}); | ||
var Server = require('karma').Server; | ||
var server = new Server({ configFile: __dirname + '/karma.conf.js' }); | ||
server.start(function() { | ||
done(); | ||
}); | ||
}); | ||
gulp.task('test:run-server', function(done) { | ||
server.listen({ path: './test/server.js' }, done); | ||
gulp.task('test:sauce', ["build:browser"], function (done) { | ||
var Server = require('karma').Server; | ||
var server = new Server({ configFile: __dirname + '/karma-sauce.conf.js' }); | ||
server.start(function() { | ||
done(); | ||
}); | ||
}); | ||
@@ -99,0 +101,0 @@ |
module.exports = function(config) { | ||
config.set({ | ||
frameworks: ['mocha', 'sinon-chai'], | ||
frameworks: ['mocha', 'chai', 'sinon'], | ||
browsers : ["Firefox"], | ||
@@ -8,3 +8,3 @@ | ||
'dist/stellar-sdk.js', | ||
'test/setup/browser.js', | ||
'test/test-helper.js', | ||
'test/unit/**/*.js' | ||
@@ -14,4 +14,3 @@ ], | ||
preprocessors: { | ||
'test/unit/**/*.js': ['webpack'], | ||
'test/setup/fixtures.js': ['webpack'] | ||
'test/**/*.js': ['webpack'] | ||
}, | ||
@@ -33,4 +32,4 @@ | ||
reporters: ['dots'], | ||
reporters: ['dots'] | ||
}); | ||
}; |
{ | ||
"name": "stellar-sdk", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"description": "stellar-sdk is a library for working with the Stellar Horizon server.", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"author": "Stellar Development Foundation <hello@stellar.org>", | ||
"license": "Apache 2.0", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
@@ -52,2 +52,3 @@ "url": "https://github.com/stellar/js-stellar-sdk/issues" | ||
"karma": "^0.13.2", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^0.1.7", | ||
@@ -57,2 +58,4 @@ "karma-firefox-launcher": "^0.1.4", | ||
"karma-phantomjs-launcher": "^0.1.4", | ||
"karma-sauce-launcher": "^0.2.14", | ||
"karma-sinon": "^1.0.4", | ||
"karma-sinon-chai": "^0.3.0", | ||
@@ -59,0 +62,0 @@ "karma-webpack": "^1.7.0", |
describe("server.js tests", function () { | ||
var DEV_SERVER_FIXTURES_ENDPOINT = "http://localhost:1337/fixtures"; | ||
var DEV_SERVER_CLEAR_FIXTURES_ENDPOINT = "http://localhost:1337/clear"; | ||
var toBluebird = bluebird.resolve; | ||
var makeFakePage = function(nextUrl) { | ||
return { | ||
_links: { | ||
next: { href: nextUrl }, | ||
}, | ||
_embedded: { | ||
records: [] | ||
}, | ||
} | ||
} | ||
var FAKE_COLLECTION_RESPONSE = makeFakePage('accounts/gspbxqXqEUZkiCCEFFCN9Vu4FLucdjLLdLcsV6E82Qc1T7ehsTC/transactions?after=55834578944&limit=1&order=asc'); | ||
var server; | ||
beforeEach(function () { | ||
server = new StellarSdk.Server({port: 1337}); | ||
// sets the request the dev server should expect and the response it should send | ||
this.setFixtures = function (fixtures, done) { | ||
// instruct the dev server to except the correct request | ||
return axios.post(DEV_SERVER_FIXTURES_ENDPOINT, fixtures); | ||
} | ||
this.server = new StellarSdk.Server({secure: true, hostname: 'horizon-live.stellar.org', port: 1337}); | ||
this.axiosMock = sinon.mock(axios); | ||
}); | ||
afterEach(function (done) { | ||
return toBluebird(axios.post(DEV_SERVER_CLEAR_FIXTURES_ENDPOINT)) | ||
.then(function () { done() }); | ||
}) | ||
afterEach(function () { | ||
this.axiosMock.verify(); | ||
this.axiosMock.restore(); | ||
}); | ||
@@ -40,16 +15,58 @@ describe('Server._sendResourceRequest', function () { | ||
describe("requests all ledgers", function () { | ||
let ledgersResponse = { | ||
"_embedded": { | ||
"records": [ | ||
{ | ||
"_links": { | ||
"effects": { | ||
"href": "/ledgers/1/effects{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"operations": { | ||
"href": "/ledgers/1/operations{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"self": { | ||
"href": "/ledgers/1" | ||
}, | ||
"transactions": { | ||
"href": "/ledgers/1/transactions{?cursor,limit,order}", | ||
"templated": true | ||
} | ||
}, | ||
"id": "63d98f536ee68d1b27b5b89f23af5311b7569a24faf1403ad0b52b633b07be99", | ||
"paging_token": "4294967296", | ||
"hash": "63d98f536ee68d1b27b5b89f23af5311b7569a24faf1403ad0b52b633b07be99", | ||
"sequence": 1, | ||
"transaction_count": 0, | ||
"operation_count": 0, | ||
"closed_at": "1970-01-01T00:00:00Z" | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"next": { | ||
"href": "/ledgers?order=asc\u0026limit=1\u0026cursor=4294967296" | ||
}, | ||
"prev": { | ||
"href": "/ledgers?order=desc\u0026limit=1\u0026cursor=4294967296" | ||
}, | ||
"self": { | ||
"href": "/ledgers?order=asc\u0026limit=1\u0026cursor=" | ||
} | ||
} | ||
}; | ||
describe("without options", function () { | ||
it("requests the correct endpoint", function (done) { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers')) | ||
.returns(Promise.resolve({data: ledgersResponse})); | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
it("requests the correct endpoint", function (done) { | ||
server.ledgers() | ||
this.server.ledgers() | ||
.call() | ||
.then(function () { | ||
.then(response => { | ||
expect(response.records).to.be.deep.equal(ledgersResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
@@ -59,26 +76,33 @@ }) | ||
done(err); | ||
}) | ||
}); | ||
}) | ||
}) | ||
}); | ||
describe("with options", function () { | ||
beforeEach(function (done) { | ||
var url = "/ledgers?limit=1&after=b&order=asc" | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: url, | ||
response: {status: 200, body: makeFakePage(url)} | ||
}).then(function () { done(); }); | ||
beforeEach(function() { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers?limit=1&after=b&order=asc')) | ||
.returns(Promise.resolve({data: ledgersResponse})); | ||
}); | ||
it("requests the correct endpoint", function () { | ||
return server.ledgers() | ||
it("requests the correct endpoint", function (done) { | ||
this.server.ledgers() | ||
.limit("1") | ||
.after("b") | ||
.order("asc") | ||
.call(); | ||
.call() | ||
.then(response => { | ||
expect(response.records).to.be.deep.equal(ledgersResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
}) | ||
}); | ||
it("can call .next() on the result to retrieve the next page", function () { | ||
return server | ||
it("can call .next() on the result to retrieve the next page", function (done) { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers?order=asc&limit=1&cursor=4294967296')) | ||
.returns(Promise.resolve(({data: ledgersResponse}))); | ||
this.server | ||
.ledgers() | ||
@@ -90,3 +114,8 @@ .limit("1") | ||
.then(function(page) { | ||
return page.next() | ||
page.next().then(function(response) { | ||
expect(response.records).to.be.deep.equal(ledgersResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
}); | ||
}); | ||
@@ -97,19 +126,13 @@ }); | ||
describe("as stream", function () { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers", | ||
response: {status: 200, body: "{\"test\":\"body\"}"}, | ||
stream: true | ||
}).then(function () { done() }); | ||
}); | ||
it("attaches onmessage handler to an EventSource", function (done) { | ||
var es = server.ledgers() | ||
.stream( | ||
{ onmessage: function (res) { | ||
expect(res.test).to.be.equal("body"); | ||
done(); | ||
let eventSource = this.server.ledgers() | ||
.stream({ | ||
onmessage: function (res) { | ||
eventSource.close(); | ||
expect(res.test).to.be.equal("body"); | ||
done(); | ||
} | ||
}) | ||
}); | ||
eventSource.onmessage({data: '{"test": "body"}'}); | ||
}); | ||
@@ -120,13 +143,36 @@ }); | ||
describe("requests a single ledger", function () { | ||
let singleLedgerResponse = { | ||
"_links": { | ||
"effects": { | ||
"href": "/ledgers/1/effects{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"operations": { | ||
"href": "/ledgers/1/operations{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"self": { | ||
"href": "/ledgers/1" | ||
}, | ||
"transactions": { | ||
"href": "/ledgers/1/transactions{?cursor,limit,order}", | ||
"templated": true | ||
} | ||
}, | ||
"id": "63d98f536ee68d1b27b5b89f23af5311b7569a24faf1403ad0b52b633b07be99", | ||
"paging_token": "4294967296", | ||
"hash": "63d98f536ee68d1b27b5b89f23af5311b7569a24faf1403ad0b52b633b07be99", | ||
"sequence": 1, | ||
"transaction_count": 0, | ||
"operation_count": 0, | ||
"closed_at": "1970-01-01T00:00:00Z" | ||
}; | ||
describe("for a non existent ledger", function () { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers/1", | ||
response: {status: 404, body: "{\"test\":\"body\"}"} | ||
}).then(function () { done() }); | ||
}); | ||
it("throws a NotFoundError", function (done) { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers/1')) | ||
.returns(Promise.reject({status: 404, data: {}})); | ||
it("throws a NotFoundError", function (done) { | ||
server.ledgers() | ||
this.server.ledgers() | ||
.ledger("1") | ||
@@ -146,15 +192,12 @@ .call() | ||
describe("without options", function () { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers/1", | ||
response: {status: 200, body: "{\"test\":\"body\"}"} | ||
}).then(function () { done() }); | ||
}); | ||
it("requests the correct endpoint", function (done) { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers/1')) | ||
.returns(Promise.resolve({data: singleLedgerResponse})); | ||
it("requests the correct endpoint", function (done) { | ||
server.ledgers() | ||
this.server.ledgers() | ||
.ledger("1") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response).to.be.deep.equal(singleLedgerResponse); | ||
done(); | ||
@@ -167,13 +210,10 @@ }) | ||
}); | ||
describe("with options", function () { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers/1?limit=1&after=b&order=asc", | ||
response: {status: 200, body: "{\"test\":\"body\"}"} | ||
}).then(function () { done() }); | ||
}); | ||
it("requests the correct endpoint", function (done) { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers/1?limit=1&after=b&order=asc')) | ||
.returns(Promise.resolve({data: singleLedgerResponse})); | ||
it("requests the correct endpoint", function (done) { | ||
server.ledgers() | ||
this.server.ledgers() | ||
.ledger("1") | ||
@@ -184,3 +224,4 @@ .limit("1") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response).to.be.deep.equal(singleLedgerResponse); | ||
done(); | ||
@@ -196,16 +237,75 @@ }) | ||
describe("requests a sub resource", function (done) { | ||
let transactionsResponse = { | ||
"_embedded": { | ||
"records": [ | ||
{ | ||
"_links": { | ||
"account": { | ||
"href": "/accounts/GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H" | ||
}, | ||
"effects": { | ||
"href": "/transactions/991534d902063b7715cd74207bef4e7bd7aa2f108f62d3eba837ce6023b2d4f3/effects{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"ledger": { | ||
"href": "/ledgers/34" | ||
}, | ||
"operations": { | ||
"href": "/transactions/991534d902063b7715cd74207bef4e7bd7aa2f108f62d3eba837ce6023b2d4f3/operations{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"precedes": { | ||
"href": "/transactions?cursor=146028892160\u0026order=asc" | ||
}, | ||
"self": { | ||
"href": "/transactions/991534d902063b7715cd74207bef4e7bd7aa2f108f62d3eba837ce6023b2d4f3" | ||
}, | ||
"succeeds": { | ||
"href": "/transactions?cursor=146028892160\u0026order=desc" | ||
} | ||
}, | ||
"id": "991534d902063b7715cd74207bef4e7bd7aa2f108f62d3eba837ce6023b2d4f3", | ||
"paging_token": "146028892160", | ||
"hash": "991534d902063b7715cd74207bef4e7bd7aa2f108f62d3eba837ce6023b2d4f3", | ||
"ledger": 34, | ||
"created_at": "2015-09-29T23:38:10Z", | ||
"account": "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H", | ||
"account_sequence": 1, | ||
"max_fee": 0, | ||
"fee_paid": 0, | ||
"operation_count": 1, | ||
"result_code": 0, | ||
"result_code_s": "tx_success", | ||
"envelope_xdr": "AAAAAGL8HQvQkbK2HA3WVjRrKmjX00fG8sLI7m0ERwJW/AX3AAAAZAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAZc2EuuEa2W1PAKmaqVquHuzUMHaEiRs//+ODOfgWiz8AAFrzEHpAAAAAAAAAAAABVvwF9wAAAECdBs6M1RCYGMBFKqFb4hmJ3wafkfSE8oXELydY/U1VBmfHcr6QtHmRPgAhkf5dUBwHigKhNKcpvb6v66ClyGoN", | ||
"result_xdr": "AAAAAAAAAGQAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAA=", | ||
"result_meta_xdr": "AAAAAAAAAAEAAAACAAAAAAAAACIAAAAAAAAAAGXNhLrhGtltTwCpmqlarh7s1DB2hIkbP//jgzn4Fos/AABa8xB6QAAAAAAiAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAQAAACIAAAAAAAAAAGL8HQvQkbK2HA3WVjRrKmjX00fG8sLI7m0ERwJW/AX3DeBbwJbpv5wAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAA" | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"next": { | ||
"href": "/transactions?order=asc\u0026limit=1\u0026cursor=146028892160" | ||
}, | ||
"prev": { | ||
"href": "/transactions?order=desc\u0026limit=1\u0026cursor=146028892160" | ||
}, | ||
"self": { | ||
"href": "/transactions?order=asc\u0026limit=1\u0026cursor=" | ||
} | ||
} | ||
}; | ||
describe("without options", function () { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers/1/transactions", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
it("requests the correct endpoint", function (done) { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers/1/transactions')) | ||
.returns(Promise.resolve({data: transactionsResponse})); | ||
it("requests the correct endpoint", function (done) { | ||
server.transactions() | ||
this.server.transactions() | ||
.forLedger("1") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response.records).to.be.deep.equal(transactionsResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
@@ -219,12 +319,8 @@ }) | ||
describe("with options", function () { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers/1/transactions?limit=1&after=b&order=asc", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
it("requests the correct endpoint", function (done) { | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/ledgers/1/transactions?after=b&limit=1&order=asc')) | ||
.returns(Promise.resolve({data: transactionsResponse})); | ||
it("requests the correct endpoint", function (done) { | ||
server.transactions() | ||
this.server.transactions() | ||
.forLedger("1") | ||
@@ -235,3 +331,6 @@ .after("b") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response.records).to.be.deep.equal(transactionsResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
@@ -245,21 +344,14 @@ }) | ||
describe("as stream", function () { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/ledgers/1/transactions", | ||
response: {status: 200, body: "{\"test\":\"body\"}"}, | ||
stream: true | ||
}).then(function () { done() }); | ||
}); | ||
it("attaches onmessage handler to an EventSource", function (done) { | ||
var es = server.transactions() | ||
var eventSource = this.server.transactions() | ||
.forLedger("1") | ||
.stream({ | ||
onmessage: function (res) { | ||
eventSource.close(); | ||
expect(res.test).to.be.equal("body"); | ||
es.close(); | ||
done(); | ||
} | ||
}); | ||
eventSource.onmessage({data: '{"test": "body"}'}); | ||
}); | ||
@@ -270,6 +362,22 @@ }); | ||
describe('Server.sendTransaction', function() { | ||
/*it("sends a transaction", function() { | ||
server.submitTransaction({blob: global.fixtures.TEST_TRANSACTION_BLOB}) | ||
.then(function (res) { | ||
describe('Server.submitTransaction', function() { | ||
it("sends a transaction", function(done) { | ||
let keypair = StellarSdk.Keypair.random(); | ||
let account = new StellarSdk.Account(keypair.address(), 56199647068161); | ||
let transaction = new StellarSdk.TransactionBuilder(account) | ||
.addOperation(StellarSdk.Operation.payment({ | ||
destination: "GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", | ||
asset: StellarSdk.Asset.native(), | ||
amount: "100.50" | ||
})) | ||
.addSigner(keypair) | ||
.build(); | ||
let blob = encodeURIComponent(transaction.toEnvelope().toXDR().toString("base64")); | ||
this.axiosMock.expects('post') | ||
.withArgs('https://horizon-live.stellar.org:1337/transactions', `tx=${blob}`) | ||
.returns(Promise.resolve({data: {}})); | ||
this.server.submitTransaction(transaction) | ||
.then(function() { | ||
done(); | ||
@@ -280,3 +388,3 @@ }) | ||
}) | ||
});*/ | ||
}); | ||
}); | ||
@@ -286,3 +394,3 @@ | ||
it("creates link functions", function () { | ||
var callBuilder = server.ledgers(); | ||
var callBuilder = this.server.ledgers(); | ||
var json = callBuilder._parseResponse({ | ||
@@ -301,16 +409,64 @@ "_links": { | ||
describe("AccountCallBuilder", function() { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/accounts/GSDEF?limit=4", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
let singleAccountResponse = { | ||
"_links": { | ||
"effects": { | ||
"href": "/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K/effects{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"offers": { | ||
"href": "/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K/offers{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"operations": { | ||
"href": "/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K/operations{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"self": { | ||
"href": "/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K" | ||
}, | ||
"transactions": { | ||
"href": "/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K/transactions{?cursor,limit,order}", | ||
"templated": true | ||
} | ||
}, | ||
"id": "GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K", | ||
"paging_token": "146028892161", | ||
"address": "GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K", | ||
"sequence": 146028888090, | ||
"subentry_count": 0, | ||
"inflation_destination": null, | ||
"home_domain": "", | ||
"thresholds": { | ||
"low_threshold": 0, | ||
"med_threshold": 0, | ||
"high_threshold": 0 | ||
}, | ||
"flags": { | ||
"auth_required": false, | ||
"auth_revocable": false | ||
}, | ||
"balances": [ | ||
{ | ||
"asset_type": "native", | ||
"balance": "9760000.3997400" | ||
} | ||
], | ||
"signers": [ | ||
{ | ||
"address": "GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K", | ||
"weight": 1 | ||
} | ||
] | ||
}; | ||
it("requests the correct endpoint", function (done) { | ||
server.accounts() | ||
.address("GSDEF") | ||
.limit("4") | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K')) | ||
.returns(Promise.resolve({data: singleAccountResponse})); | ||
this.server.accounts() | ||
.address("GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response).to.be.deep.equal(singleAccountResponse); | ||
done(); | ||
@@ -325,15 +481,31 @@ }) | ||
describe("OfferCallBuilder", function() { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/accounts/GSDEF/offers?order=asc", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
let offersResponse = { | ||
"_embedded": { | ||
"records": [] | ||
}, | ||
"_links": { | ||
"next": { | ||
"href": "/accounts/GBCR5OVQ54S2EKHLBZMK6VYMTXZHXN3T45Y6PRX4PX4FXDMJJGY4FD42/offers?order=asc\u0026limit=10\u0026cursor=" | ||
}, | ||
"prev": { | ||
"href": "/accounts/GBCR5OVQ54S2EKHLBZMK6VYMTXZHXN3T45Y6PRX4PX4FXDMJJGY4FD42/offers?order=desc\u0026limit=10\u0026cursor=" | ||
}, | ||
"self": { | ||
"href": "/accounts/GBCR5OVQ54S2EKHLBZMK6VYMTXZHXN3T45Y6PRX4PX4FXDMJJGY4FD42/offers?order=asc\u0026limit=10\u0026cursor=" | ||
} | ||
} | ||
}; | ||
it("requests the correct endpoint", function (done) { | ||
server.offers('accounts', "GSDEF") | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K/offers?order=asc')) | ||
.returns(Promise.resolve({data: offersResponse})); | ||
this.server.offers('accounts', "GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K") | ||
.order("asc") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response.records).to.be.deep.equal(offersResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
@@ -347,3 +519,3 @@ }) | ||
it("rejects the wrong resource", function(done) { | ||
expect(() => server.offers('ledgers', '123').call()).to.throw(/Bad resource specified/); | ||
expect(() => this.server.offers('ledgers', '123').call()).to.throw(/Bad resource specified/); | ||
done(); | ||
@@ -354,14 +526,26 @@ }); | ||
describe("OrderbookCallBuilder", function() { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/order_book?selling_asset_type=native&buying_asset_type=credit_alphanum4&buying_asset_code=USD&buying_asset_issuer=GDVDKQFP665JAO7A2LSHNLQIUNYNAAIGJ6FYJVMG4DT3YJQQJSRBLQDG", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
let orderBookResponse = { | ||
"bids": [], | ||
"asks": [], | ||
"base": { | ||
"asset_type": "native", | ||
"asset_code": "", | ||
"asset_issuer": "" | ||
}, | ||
"counter": { | ||
"asset_type": "credit_alphanum4", | ||
"asset_code": "USD", | ||
"asset_issuer": "GDVDKQFP665JAO7A2LSHNLQIUNYNAAIGJ6FYJVMG4DT3YJQQJSRBLQDG" | ||
} | ||
}; | ||
it("requests the correct endpoint", function (done) { | ||
server.orderbook(new StellarSdk.Asset.native(), new StellarSdk.Asset('USD', "GDVDKQFP665JAO7A2LSHNLQIUNYNAAIGJ6FYJVMG4DT3YJQQJSRBLQDG")) | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/order_book?selling_asset_type=native&buying_asset_type=credit_alphanum4&buying_asset_code=USD&buying_asset_issuer=GDVDKQFP665JAO7A2LSHNLQIUNYNAAIGJ6FYJVMG4DT3YJQQJSRBLQDG')) | ||
.returns(Promise.resolve({data: orderBookResponse})); | ||
this.server.orderbook(new StellarSdk.Asset.native(), new StellarSdk.Asset('USD', "GDVDKQFP665JAO7A2LSHNLQIUNYNAAIGJ6FYJVMG4DT3YJQQJSRBLQDG")) | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response).to.be.deep.equal(orderBookResponse); | ||
done(); | ||
@@ -376,15 +560,50 @@ }) | ||
describe("EffectCallBuilder", function() { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/effects?after=b", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
let effectsResponse = { | ||
"_embedded": { | ||
"records": [ | ||
{ | ||
"_links": { | ||
"operation": { | ||
"href": "/operations/146028892161" | ||
}, | ||
"precedes": { | ||
"href": "/effects?cursor=146028892161-1\u0026order=asc" | ||
}, | ||
"succeeds": { | ||
"href": "/effects?cursor=146028892161-1\u0026order=desc" | ||
} | ||
}, | ||
"account": "GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K", | ||
"paging_token": "146028892161-1", | ||
"starting_balance": "10000000.0", | ||
"type": 0, | ||
"type_s": "account_created" | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"next": { | ||
"href": "/effects?order=asc\u0026limit=1\u0026cursor=146028892161-1" | ||
}, | ||
"prev": { | ||
"href": "/effects?order=desc\u0026limit=1\u0026cursor=146028892161-1" | ||
}, | ||
"self": { | ||
"href": "/effects?order=asc\u0026limit=1\u0026cursor=" | ||
} | ||
} | ||
}; | ||
it("requests the correct endpoint", function (done) { | ||
server.effects() | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/effects?after=b')) | ||
.returns(Promise.resolve({data: effectsResponse})); | ||
this.server.effects() | ||
.after("b") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response.records).to.be.deep.equal(effectsResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
@@ -398,3 +617,3 @@ }) | ||
it("rejects two filters", function (done) { | ||
expect(() => server.effects().forOperation("blah").forLedger('234').call()).to.throw(/Too many filters/); | ||
expect(() => this.server.effects().forOperation("blah").forLedger('234').call()).to.throw(/Too many filters/); | ||
done(); | ||
@@ -405,15 +624,59 @@ }); | ||
describe("OperationCallBuilder", function() { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/transactions/blah/operations", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
let operationsResponse = { | ||
"_embedded": { | ||
"records": [ | ||
{ | ||
"_links": { | ||
"effects": { | ||
"href": "/operations/146028892161/effects{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"precedes": { | ||
"href": "/operations?cursor=146028892161\u0026order=asc" | ||
}, | ||
"self": { | ||
"href": "/operations/146028892161" | ||
}, | ||
"succeeds": { | ||
"href": "/operations?cursor=146028892161\u0026order=desc" | ||
}, | ||
"transaction": { | ||
"href": "/transactions/991534d902063b7715cd74207bef4e7bd7aa2f108f62d3eba837ce6023b2d4f3" | ||
} | ||
}, | ||
"account": "GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K", | ||
"funder": "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H", | ||
"id": 146028892161, | ||
"paging_token": "146028892161", | ||
"starting_balance": "10000000.0", | ||
"type": 0, | ||
"type_s": "create_account" | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"next": { | ||
"href": "/operations?order=asc\u0026limit=1\u0026cursor=146028892161" | ||
}, | ||
"prev": { | ||
"href": "/operations?order=desc\u0026limit=1\u0026cursor=146028892161" | ||
}, | ||
"self": { | ||
"href": "/operations?order=asc\u0026limit=1\u0026cursor=" | ||
} | ||
} | ||
}; | ||
it("requests the correct endpoint", function (done) { | ||
server.operations() | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/transactions/blah/operations')) | ||
.returns(Promise.resolve({data: operationsResponse})); | ||
this.server.operations() | ||
.forTransaction("blah") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response.records).to.be.deep.equal(operationsResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
@@ -428,15 +691,59 @@ }) | ||
describe("PaymentCallBuilder", function() { | ||
beforeEach(function (done) { | ||
// instruct the dev server to except the correct request | ||
return this.setFixtures({ | ||
request: "/accounts/GDEFS/payments", | ||
response: {status: 200, body: FAKE_COLLECTION_RESPONSE} | ||
}).then(function () { done() }); | ||
}); | ||
let paymentsResponse = { | ||
"_embedded": { | ||
"records": [ | ||
{ | ||
"_links": { | ||
"effects": { | ||
"href": "/operations/146028892161/effects{?cursor,limit,order}", | ||
"templated": true | ||
}, | ||
"precedes": { | ||
"href": "/operations?cursor=146028892161\u0026order=asc" | ||
}, | ||
"self": { | ||
"href": "/operations/146028892161" | ||
}, | ||
"succeeds": { | ||
"href": "/operations?cursor=146028892161\u0026order=desc" | ||
}, | ||
"transaction": { | ||
"href": "/transactions/991534d902063b7715cd74207bef4e7bd7aa2f108f62d3eba837ce6023b2d4f3" | ||
} | ||
}, | ||
"account": "GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K", | ||
"funder": "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H", | ||
"id": 146028892161, | ||
"paging_token": "146028892161", | ||
"starting_balance": "10000000.0", | ||
"type": 0, | ||
"type_s": "create_account" | ||
} | ||
] | ||
}, | ||
"_links": { | ||
"next": { | ||
"href": "/payments?order=asc\u0026limit=1\u0026cursor=146028892161" | ||
}, | ||
"prev": { | ||
"href": "/payments?order=desc\u0026limit=1\u0026cursor=146028892161" | ||
}, | ||
"self": { | ||
"href": "/payments?order=asc\u0026limit=1\u0026cursor=" | ||
} | ||
} | ||
}; | ||
it("requests the correct endpoint", function (done) { | ||
server.payments() | ||
.forAccount("GDEFS") | ||
this.axiosMock.expects('get') | ||
.withArgs(sinon.match('https://horizon-live.stellar.org:1337/accounts/GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K/payments')) | ||
.returns(Promise.resolve({data: paymentsResponse})); | ||
this.server.payments() | ||
.forAccount("GBS43BF24ENNS3KPACUZVKK2VYPOZVBQO2CISGZ777RYGOPYC2FT6S3K") | ||
.call() | ||
.then(function () { | ||
.then(function (response) { | ||
expect(response.records).to.be.deep.equal(paymentsResponse._embedded.records); | ||
expect(response.next).to.be.function; | ||
expect(response.prev).to.be.function; | ||
done(); | ||
@@ -443,0 +750,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2402333
38
50972