Skip to content

Commit

Permalink
V0.15.0 (#251)
Browse files Browse the repository at this point in the history
* upgrade to 0.15.0
* fix failing browser tests: they failed because packages imported in test files are technically a separate instance from those called from StellarSdk directly.
  • Loading branch information
morleyzhi authored Mar 19, 2019
1 parent cf63c2e commit 11d76f1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 105 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
As this project is pre 1.0, breaking changes may happen for minor version bumps.
A breaking change will get clearly marked in this log.

## In master
## [v0.15.0](https://github.com/stellar/js-stellar-sdk/compare/v0.14.0...v0.15.0)

- **Breaking change**: `stellar-sdk` no longer ships with an `EventSource`
polyfill. If you plan to support IE11 / Edge, please use
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-sdk",
"version": "0.14.0",
"version": "0.15.0",
"description": "stellar-sdk is a library for working with the Stellar Horizon server.",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -114,7 +114,7 @@
"es6-promise": "^4.2.4",
"eventsource": "^1.0.7",
"lodash": "^4.17.11",
"stellar-base": "^0.12.0",
"stellar-base": "^0.13.0",
"toml": "^2.3.0",
"urijs": "^1.19.1"
}
Expand Down
12 changes: 10 additions & 2 deletions test/unit/horizon_axios_client_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('getCurrentServerTime', () => {

beforeEach(() => {
// set it to 50 seconds
clock = sinon.useFakeTimers(50000);
clock = sinon.useFakeTimers(5050000);
});

afterEach(() => {
Expand All @@ -24,11 +24,19 @@ describe('getCurrentServerTime', () => {
expect(getCurrentServerTime('host')).to.be.null;
});

it('returns the delta between then and now', () => {
it('returns null when the old time is too old', () => {
SERVER_TIME_MAP.host = {
serverTime: 10,
localTimeRecorded: 5
};
expect(getCurrentServerTime('host')).to.be.null;
});

it('returns the delta between then and now', () => {
SERVER_TIME_MAP.host = {
serverTime: 10,
localTimeRecorded: 5005
};
expect(getCurrentServerTime('host')).to.equal(55);
});
});
130 changes: 34 additions & 96 deletions test/unit/server_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const MockAdapter = require('axios-mock-adapter');

const SERVER_TIME_MAP = require('../../src/horizon_axios_client')
.SERVER_TIME_MAP;

describe('server.js non-transaction tests', function() {
beforeEach(function() {
this.server = new StellarSdk.Server(
Expand Down Expand Up @@ -48,119 +45,60 @@ describe('server.js non-transaction tests', function() {
beforeEach(function() {
// set now to 10050 seconds
clock = sinon.useFakeTimers(10050 * 1000);
// use MockAdapter instead of this.axiosMock
// because we don't want to replace the get function
// we need to use axios's one so interceptors run!!
this.axiosMockAdapter = new MockAdapter(HorizonAxiosClient);
});

afterEach(function() {
clock.restore();
this.axiosMockAdapter.restore();
});

it('uses SERVER_TIME_MAP if theres a recorded thing', function(done) {
SERVER_TIME_MAP['horizon-live.stellar.org'] = {
serverTime: 10,
localTimeRecorded: 10000
};
// the next two tests are run in a deliberate order!!
// don't change the order!!
it('fetches falls back to local time if fetch is bad', function(done) {
this.axiosMockAdapter
.onGet('https://horizon-live.stellar.org:1337/')
.reply(200, {}, {});

this.server
.fetchTimebounds(20)
.then((serverTime) => {
expect(serverTime).to.eql({ minTime: 0, maxTime: 80 });
expect(serverTime).to.eql({ minTime: 0, maxTime: 10070 });
done();
})
.catch((e) => {
done(e);
});
});

describe('with MockAdapter mocks', function() {
beforeEach(function() {
// use MockAdapter instead of this.axiosMock
// because we don't want to replace the get function
// we need to use axios's one so interceptors run!!
this.axiosMockAdapter = new MockAdapter(HorizonAxiosClient);
});

afterEach(function() {
this.axiosMockAdapter.restore();
});

it('fetches if nothing is recorded', function(done) {
this.axiosMockAdapter
.onGet('https://horizon-live.stellar.org:1337/')
.reply(
200,
{},
{
Date: 'Wed, 13 Mar 2019 22:15:07 GMT'
}
);

SERVER_TIME_MAP['horizon-live.stellar.org'] = undefined;

this.server
.fetchTimebounds(20)
.then((serverTime) => {
expect(serverTime).to.eql({
minTime: 0,
// this is server time 1552515307 plus 20
maxTime: 1552515327
});

done();
})
.catch((e) => {
done(e);
});
});

it('fetches if the old time is too old', function(done) {
this.axiosMockAdapter
.onGet('https://horizon-live.stellar.org:1337/')
.reply(
200,
{},
{
Date: 'Wed, 13 Mar 2019 22:15:07 GMT'
}
);

SERVER_TIME_MAP['horizon-live.stellar.org'] = {
serverTime: 'Wed, 13 Mar 2010 22:15:07 GMT',
localTimeRecorded: 50
};

this.server
.fetchTimebounds(20)
.then((serverTime) => {
expect(serverTime).to.eql({
minTime: 0,
// this is server time 1552515307 plus 20
maxTime: 1552515327
});
it('fetches if nothing is recorded', function(done) {
this.axiosMockAdapter
.onGet('https://horizon-live.stellar.org:1337/')
.reply(
200,
{},
{
Date: 'Wed, 13 Mar 2019 22:15:07 GMT'
}
);

done();
})
.catch((e) => {
done(e);
this.server
.fetchTimebounds(20)
.then((serverTime) => {
expect(serverTime).to.eql({
minTime: 0,
// this is server time 1552515307 plus 20
maxTime: 1552515327
});
});

it('fetches falls back to local time if fetch is bad', function(done) {
this.axiosMockAdapter
.onGet('https://horizon-live.stellar.org:1337/')
.reply(200, {}, {});

SERVER_TIME_MAP['horizon-live.stellar.org'] = undefined;

this.server
.fetchTimebounds(20)
.then((serverTime) => {
expect(serverTime).to.eql({ minTime: 0, maxTime: 10070 });
done();
})
.catch((e) => {
done(e);
});
});
done();
})
.catch((e) => {
done(e);
});
});
});

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6954,10 +6954,10 @@ statuses@~1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087"

stellar-base@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-0.12.0.tgz#674d2df88fb354458129b68f79a31715dd136f1f"
integrity sha512-Q002doIAWIe3YXm6Y2W+ta4Yh8Yy9rGZC0WzuF5eZLc8mO+jj1FfamOMs+oE4jeGh/YvO0Y4Jfb9acFCatiQ7Q==
stellar-base@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-0.13.0.tgz#95844584d50ba8e70cfad5335c35fa81532bdec8"
integrity sha512-PZMVOmo+UdBgMx4AfsKIieHKsMM+Cj9zD1FpfYWWiUspNZETldXf+hNKbXPj1HT0ygRZfnT9mOEqKSdz1At95Q==
dependencies:
base32.js "^0.1.0"
bignumber.js "^4.0.0"
Expand Down

0 comments on commit 11d76f1

Please sign in to comment.