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

Commit

Permalink
Merge pull request #1032 from LiskHQ/341-update-lisk-core-to-1-0-0
Browse files Browse the repository at this point in the history
Update to Lisk Core 1.0.0 API - Closes #341
  • Loading branch information
yasharAyari authored May 15, 2018
2 parents 0dd5219 + 46f448e commit 0173d0a
Show file tree
Hide file tree
Showing 75 changed files with 511 additions and 448 deletions.
51 changes: 20 additions & 31 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,6 @@ node('lisk-nano') {
echo "Error: ${err}"
fail('Stopping build: checkout failed')
}

try {
sh '''
N=${EXECUTOR_NUMBER:-0}; N=$((N+1))
cd ~/lisk-Linux-x86_64
# work around core bug: config.json gets overwritten; use backup
cp .config.json config_$N.json
# change core port, listen only on 127.0.0.1
sed -i -r -e "s/^(.*ort\\":) 4000,/\\1 400$N,/" config_$N.json
sed -i -r -e "s/^(.*\\"address\\":) \\"0.0.0.0\\",/\\1 \\"127.0.0.1\\",/" config_$N.json
# disable redis
sed -i -r -e "s/^(\\s*\\"cacheEnabled\\":) true/\\1 false/" config_$N.json
# change postgres databse
sed -i -r -e "s/^(\\s*\\"database\\": \\"lisk_test)\\",/\\1_$N\\",/" config_$N.json
cp etc/pm2-lisk.json etc/pm2-lisk_$N.json
sed -i -r -e "s/config.json/config_$N.json/" etc/pm2-lisk_$N.json
sed -i -r -e "s/(lisk.app)/\\1_$N/" etc/pm2-lisk_$N.json
# logs
sed -i -r -e "s/lisk.log/lisk_${JOB_BASE_NAME}_${BUILD_ID}.log/" config_$N.json
sed -i -r -e "s/lisk.app_$N/lisk.app_$N_${JOB_BASE_NAME}_${BUILD_ID}/" etc/pm2-lisk_$N.json
#
JENKINS_NODE_COOKIE=dontKillMe bash lisk.sh start_db -p etc/pm2-lisk_$N.json
bash lisk.sh rebuild -p etc/pm2-lisk_$N.json -f blockchain_explorer.db.gz
'''
} catch (err) {
echo "Error: ${err}"
fail('Stopping build: Lisk Core failed to start')
}
}

stage ('Install npm dependencies') {
Expand Down Expand Up @@ -142,6 +114,13 @@ node('lisk-nano') {
export DISPLAY=:1$N
Xvfb :1$N -ac -screen 0 1280x1024x24 &
cp -r ~/lisk-docker/examples/development $WORKSPACE/$BRANCH_NAME
cd $WORKSPACE/$BRANCH_NAME
cp /home/lisk/blockchain_explorer.db.gz ./blockchain.db.gz
LISK_VERSION=1.0.0-beta.7.1 make coldstart
LISK_PORT=$( docker-compose port lisk 4000 |cut -d ":" -f 2 )
cd -
# Run end-to-end tests
npm run serve -- $WORKSPACE/app/build -p 300$N -a 127.0.0.1 &>server.log &
Expand All @@ -150,7 +129,7 @@ node('lisk-nano') {
else
echo "Skipping @testnet end-to-end tests because we're not on 'development' branch"
fi
npm run --silent e2e-test -- --params.baseURL http://127.0.0.1:300$N --params.liskCoreURL http://127.0.0.1:400$N
npm run --silent e2e-test -- --params.baseURL http://127.0.0.1:300$N --params.liskCoreURL http://127.0.0.1:$LISK_PORT
if [ -z $CHANGE_BRANCH ]; then
npm run --silent e2e-test -- --params.baseURL http://127.0.0.1:300$N --cucumberOpts.tags @testnet --params.useTestnetPassphrase true --params.network testnet
else
Expand All @@ -166,11 +145,21 @@ node('lisk-nano') {
}
} catch(err) {
echo "Error: ${err}"
ansiColor('xterm') {
sh '''
cd $WORKSPACE/$BRANCH_NAME
docker-compose logs
'''
}
} finally {
ansiColor('xterm') {
sh '''
cd $WORKSPACE/$BRANCH_NAME
make mrproper
'''
}
sh '''
N=${EXECUTOR_NUMBER:-0}; N=$((N+1))
curl --verbose http://127.0.0.1:400$N/api/blocks/getNethash || true
( cd ~/lisk-Linux-x86_64 && bash lisk.sh stop_node -p etc/pm2-lisk_$N.json ) || true
pgrep --list-full -f "Xvfb :1$N" || true
pkill --echo -f "Xvfb :1$N" -9 || echo "pkill returned code $?"
Expand Down
4 changes: 3 additions & 1 deletion i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"Message decryption failed": "Message decryption failed",
"Message encryption failed": "Message encryption failed",
"Message is decrypted successfully": "Message is decrypted successfully",
"Message not verified": "Message not verified",
"Message verified": "Message verified",
"Minimize": "Minimize",
"Move your mouse to generate random bytes": "Move your mouse to generate random bytes",
"Multisignature Creation": "Multisignature Creation",
Expand All @@ -96,7 +98,6 @@
"Note: After the registration is complete, your second passphrase will be required for all outgoing transactions from this account.": "Note: After the registration is complete, your second passphrase will be required for all outgoing transactions from this account.",
"Note: Digital Signatures and signed messages are not encrypted!": "Note: Digital Signatures and signed messages are not encrypted!",
"Ok": "Ok",
"Original Message": "Original Message",
"Passphrase": "Passphrase",
"Passphrase contains extra whitespace between words": "Passphrase contains extra whitespace between words",
"Passphrase contains unnecessary whitespace at the beginning": "Passphrase contains unnecessary whitespace at the beginning",
Expand Down Expand Up @@ -155,6 +156,7 @@
"Sign message": "Sign message",
"Signature": "Signature",
"Signing a message with this tool indicates ownership of a privateKey (secret) and provides a level of proof that you are the owner of the key. Its important to bear in mind that this is not a 100% proof as computer systems can be compromised, but is still an effective tool for proving ownership of a particular publicKey/address pair.": "Signing a message with this tool indicates ownership of a privateKey (secret) and provides a level of proof that you are the owner of the key. Its important to bear in mind that this is not a 100% proof as computer systems can be compromised, but is still an effective tool for proving ownership of a particular publicKey/address pair.",
"Status": "Status",
"Submit": "Submit",
"Success": "Success",
"Switch": "Switch",
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"i18next": "=10.0.3",
"i18next-localstorage-cache": "=1.1.1",
"i18next-xhr-backend": "=1.4.2",
"lisk-js": "0.5.1",
"lisk-js": "1.0.0-beta.1",
"moment": "2.20.1",
"numeral": "=2.0.6",
"postcss": "6.0.12",
Expand Down Expand Up @@ -106,8 +106,10 @@
"extract-text-webpack-plugin": "3.0.0",
"file-loader": "1.1.0",
"glob": "=7.1.2",
"http-server": "0.11.1",
"i18next-scanner": "=2.0.0",
"imports-loader": "0.7.1",
"install": "0.11.0",
"js-nacl": "=1.2.2",
"json-loader": "0.5.7",
"karma": "1.7.1",
Expand All @@ -120,8 +122,10 @@
"karma-sourcemap-loader": "=0.3.7",
"karma-verbose-reporter": "=0.0.6",
"karma-webpack": "2.0.4",
"lolex": "=2.3.2",
"mocha": "3.5.3",
"mocha-steps": "1.1.0",
"npm": "6.0.1",
"postcss-for": "=2.1.1",
"postcss-loader": "=2.0.6",
"postcss-partial-import": "=4.1.0",
Expand All @@ -144,8 +148,7 @@
"url-loader": "0.5.9",
"webpack": "3.6.0",
"webpack-bundle-analyzer": "2.9.0",
"webpack-dev-server": "2.8.2",
"http-server": "0.11.1"
"webpack-dev-server": "2.8.2"
},
"build": {
"appId": "io.lisk.nano",
Expand Down
2 changes: 1 addition & 1 deletion protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.config = {
params: {
screenshotFolder: 'e2e-test-screenshots',
baseURL: 'http://localhost:8080/',
liskCoreURL: 'http://localhost:4000/',
liskCoreURL: 'http://localhost:4000',
testnetPassphrase: process.env.TESTNET_PASSPHRASE,
useTestnetPassphrase: false,
network: 'customNode',
Expand Down
16 changes: 13 additions & 3 deletions src/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { errorAlertDialogDisplayed } from './dialog';
import Fees from '../constants/fees';
import { toRawLsk } from '../utils/lsk';
import transactionTypes from '../constants/transactionTypes';
import { loadingStarted, loadingFinished } from '../utils/loading';

/**
* Trigger this action to update the account object
Expand Down Expand Up @@ -52,17 +53,20 @@ export const passphraseUsed = data => ({
*/
export const secondPassphraseRegistered = ({ activePeer, secondPassphrase, account }) =>
(dispatch) => {
loadingStarted('secondPassphraseRegistered');
setSecondPassphrase(activePeer, secondPassphrase, account.publicKey, account.passphrase)
.then((data) => {
loadingFinished('secondPassphraseRegistered');
dispatch(transactionAdded({
id: data.transactionId,
id: data.id,
senderPublicKey: account.publicKey,
senderId: account.address,
amount: 0,
fee: Fees.setSecondPassphrase,
type: transactionTypes.setSecondPassphrase,
}));
}).catch((error) => {
loadingFinished('secondPassphraseRegistered');
const text = (error && error.message) ? error.message : i18next.t('An error occurred while registering your second passphrase. Please try again.');
dispatch(errorAlertDialogDisplayed({ text }));
});
Expand All @@ -75,11 +79,13 @@ export const secondPassphraseRegistered = ({ activePeer, secondPassphrase, accou
export const delegateRegistered = ({
activePeer, account, passphrase, username, secondPassphrase }) =>
(dispatch) => {
loadingStarted('delegateRegistered');
registerDelegate(activePeer, username, passphrase, secondPassphrase)
.then((data) => {
loadingFinished('delegateRegistered');
// dispatch to add to pending transaction
dispatch(transactionAdded({
id: data.transactionId,
id: data.id,
senderPublicKey: account.publicKey,
senderId: account.address,
username,
Expand All @@ -89,6 +95,7 @@ export const delegateRegistered = ({
}));
})
.catch((error) => {
loadingFinished('delegateRegistered');
const text = error && error.message ? `${error.message}.` : i18next.t('An error occurred while registering as delegate.');
const actionObj = errorAlertDialogDisplayed({ text });
dispatch(actionObj);
Expand All @@ -101,10 +108,12 @@ export const delegateRegistered = ({
*/
export const sent = ({ activePeer, account, recipientId, amount, passphrase, secondPassphrase }) =>
(dispatch) => {
loadingStarted('sent');
send(activePeer, recipientId, toRawLsk(amount), passphrase, secondPassphrase)
.then((data) => {
loadingFinished('sent');
dispatch(transactionAdded({
id: data.transactionId,
id: data.id,
senderPublicKey: account.publicKey,
senderId: account.address,
recipientId,
Expand All @@ -114,6 +123,7 @@ export const sent = ({ activePeer, account, recipientId, amount, passphrase, sec
}));
})
.catch((error) => {
loadingFinished('sent');
const text = error && error.message ? `${error.message}.` : i18next.t('An error occurred while creating the transaction.');
dispatch(errorAlertDialogDisplayed({ text }));
});
Expand Down
6 changes: 3 additions & 3 deletions src/actions/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('actions: account', () => {
});

it('should dispatch transactionAdded action if resolved', () => {
accountApiMock.returnsPromise().resolves({ transactionId: '15626650747375562521' });
accountApiMock.returnsPromise().resolves({ id: '15626650747375562521' });
const expectedAction = {
id: '15626650747375562521',
senderPublicKey: 'test_public-key',
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('actions: account', () => {
});

it('should dispatch transactionAdded action if resolved', () => {
delegateApiMock.returnsPromise().resolves({ transactionId: '15626650747375562521' });
delegateApiMock.returnsPromise().resolves({ id: '15626650747375562521' });
const expectedAction = {
id: '15626650747375562521',
senderPublicKey: 'test_public-key',
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('actions: account', () => {
});

it('should dispatch transactionAdded action if resolved', () => {
accountApiMock.returnsPromise().resolves({ transactionId: '15626650747375562521' });
accountApiMock.returnsPromise().resolves({ id: '15626650747375562521' });
const expectedAction = {
id: '15626650747375562521',
senderPublicKey: 'test_public-key',
Expand Down
19 changes: 13 additions & 6 deletions src/actions/forging.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import actionTypes from '../constants/actions';
import { getForgedBlocks, getForgedStats } from '../utils/api/forging';
import { errorAlertDialogDisplayed } from './dialog';
import { loadingStarted, loadingFinished } from '../utils/loading';

export const forgedBlocksUpdated = data => ({
data,
Expand All @@ -9,11 +10,14 @@ export const forgedBlocksUpdated = data => ({

export const fetchAndUpdateForgedBlocks = ({ activePeer, limit, offset, generatorPublicKey }) =>
(dispatch) => {
loadingStarted('fetchAndUpdateForgedBlocks');
getForgedBlocks(activePeer, limit, offset, generatorPublicKey)
.then(response =>
dispatch(forgedBlocksUpdated(response.blocks)),
)
.then((response) => {
loadingFinished('fetchAndUpdateForgedBlocks');
return dispatch(forgedBlocksUpdated(response.data));
})
.catch((error) => {
loadingFinished('fetchAndUpdateForgedBlocks');
dispatch(errorAlertDialogDisplayed({ text: error.message }));
});
};
Expand All @@ -25,11 +29,14 @@ export const forgingStatsUpdated = data => ({

export const fetchAndUpdateForgedStats = ({ activePeer, key, startMoment, generatorPublicKey }) =>
(dispatch) => {
loadingStarted('fetchAndUpdateForgedStats');
getForgedStats(activePeer, startMoment, generatorPublicKey)
.then(response =>
dispatch(forgingStatsUpdated({ [key]: response.forged })),
)
.then((response) => {
loadingFinished('fetchAndUpdateForgedStats');
return dispatch(forgingStatsUpdated({ [key]: response.data.forged }));
})
.catch((error) => {
loadingFinished('fetchAndUpdateForgedStats');
dispatch(errorAlertDialogDisplayed({ text: error.message }));
});
};
4 changes: 2 additions & 2 deletions src/actions/forging.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('actions', () => {
});

it('should dispatch forgedBlocksUpdated action if resolved', () => {
forgingApiMock.returnsPromise().resolves({ blocks: 'value' });
forgingApiMock.returnsPromise().resolves({ data: 'value' });

actionFunction(dispatch);
expect(dispatch).to.have.been.calledWith(forgedBlocksUpdated('value'));
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('actions', () => {
});

it('should dispatch forgingStatsUpdated action if resolved', () => {
forgingApiMock.returnsPromise().resolves({ forged: 'value' });
forgingApiMock.returnsPromise().resolves({ data: { forged: 'value' } });

actionFunction(dispatch);
expect(dispatch).to.have.been.calledWith(forgingStatsUpdated({ [key]: 'value' }));
Expand Down
19 changes: 13 additions & 6 deletions src/actions/peers.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import i18next from 'i18next';
import Lisk from 'lisk-js';
import actionTypes from '../constants/actions';
import { getNethash } from './../utils/api/nethash';
// import { getNethash } from './../utils/api/nethash';
import { errorToastDisplayed } from './toaster';
import netHashes from '../constants/netHashes';
import { loadingStarted, loadingFinished } from '../utils/loading';

const peerSet = (data, config) => ({
data: Object.assign({
passphrase: data.passphrase,
publicKey: data.publicKey,
activePeer: Lisk.api(config),
activePeer: new Lisk.APIClient(config.nodes, config.nethash, {}),
options: config,
}),
type: actionTypes.activePeerSet,
});
Expand All @@ -36,18 +38,23 @@ export const activePeerSet = data =>
config.node = hostname;
config.ssl = protocol === 'https:';
config.port = port || (config.ssl ? 443 : 80);
config.nodes = [`${protocol}//${hostname}:${port}`];
}
if (config.testnet === undefined && config.port !== undefined) {
config.testnet = config.port === '7000';
}
if (config.custom) {
getNethash(Lisk.api(config)).then((response) => {
config.testnet = response.nethash === netHashes.testnet;
if (!config.testnet && response.nethash !== netHashes.mainnet) {
config.nethash = response.nethash;
const getNethash = new Lisk.APIClient(config.nodes, config.nethash, {});
loadingStarted('getConstants');
getNethash.node.getConstants().then((response) => {
loadingFinished('getConstants');
config.testnet = response.data.nethash === netHashes.testnet;
if (!config.testnet && response.data.nethash !== netHashes.mainnet) {
config.nethash = response.data.nethash;
}
dispatch(peerSet(data, config));
}).catch(() => {
loadingFinished('getConstants');
dispatch(errorToastDisplayed({ label: i18next.t('Unable to connect to the node') }));
});
} else {
Expand Down
Loading

0 comments on commit 0173d0a

Please sign in to comment.