Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Fix transaction and port bug on custom node - Closes #910 #921

Merged
merged 2 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/actions/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Lisk from 'lisk-js';
import actionTypes from '../constants/actions';
import { getNethash } from './../utils/api/nethash';
import { errorToastDisplayed } from './toaster';
import netHashes from '../constants/netHashes';

const peerSet = (data, config) => ({
data: Object.assign({
Expand Down Expand Up @@ -33,15 +34,18 @@ export const activePeerSet = data =>
const { hostname, port, protocol } = new URL(addHttp(config.address));

config.node = hostname;
config.port = port;
config.ssl = protocol === 'https';
config.ssl = protocol === 'https:';
config.port = port || (config.ssl ? 443 : 80);
}
if (config.testnet === undefined && config.port !== undefined) {
config.testnet = config.port === '7000';
}
if (config.custom) {
getNethash(Lisk.api(config)).then((response) => {
config.nethash = response.nethash;
config.testnet = response.nethash === netHashes.testnet;
if (!config.testnet && response.nethash !== netHashes.mainnet) {
config.nethash = response.nethash;
}
dispatch(peerSet(data, config));
}).catch(() => {
dispatch(errorToastDisplayed({ label: i18next.t('Unable to connect to the node') }));
Expand Down
20 changes: 17 additions & 3 deletions src/actions/peers.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { spy, stub, match } from 'sinon';
import actionTypes from '../constants/actions';
import netHashes from '../constants/netHashes';
import { activePeerSet, activePeerUpdate } from './peers';
import * as nethashApi from './../utils/api/nethash';

Expand Down Expand Up @@ -63,17 +64,30 @@ describe('actions: peers', () => {
expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.options.address', 'localhost:8000'));
});

it('dispatch activePeerSet with nethash from response when the network is a custom node', () => {
it('dispatch activePeerSet with testnet config set to true when the network is a custom node and nethash is testnet', () => {
getNetHash.returnsPromise();
const network = {
address: 'http://localhost:4000',
custom: true,
};

activePeerSet({ passphrase, network })(dispatch);
getNetHash.resolves({ nethash: 'nethash from response' });
getNetHash.resolves({ nethash: netHashes.testnet });

expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.nethash.nethash', 'nethash from response'));
expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.testnet', true));
});

it('dispatch activePeerSet with testnet config set to false when the network is a custom node and nethash is testnet', () => {
getNetHash.returnsPromise();
const network = {
address: 'http://localhost:4000',
custom: true,
};

activePeerSet({ passphrase, network })(dispatch);
getNetHash.resolves({ nethash: 'some other nethash' });

expect(dispatch).to.have.been.calledWith(match.hasNested('data.activePeer.testnet', false));
});

it('dispatch activePeerSet action even if network is undefined', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/constants/netHashes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const netHash = {
testnet: 'da3ed6a45429278bac2666961289ca17ad86595d33b31037615d4b8e8f158bba',
mainnet: 'ed14889723f24ecc54871d058d98ce91ff2f973192075c0155ba2b7b70ad2511',
};

export default netHash;