Skip to content

Commit 40053d1

Browse files
authored
Merge pull request #490 from NEMStudios/travis-releases
Ts doc versioning in github and travis release branch
2 parents 12687dc + 53fd8e1 commit 40053d1

File tree

6 files changed

+249
-30
lines changed

6 files changed

+249
-30
lines changed

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@ before_script:
1010
- npm run build
1111
script:
1212
- npm run test:cov
13-
- npm run coveralls-report
1413
- npm install --global typedoc
15-
- typedoc --out ts-docs src
14+
- CURRENT_VERSION=$(npm run version --silent)
15+
- typedoc --out "ts-docs/$CURRENT_VERSION" src
1616
- touch ./ts-docs/.nojekyll
17+
- if [ "$TRAVIS_NODE_VERSION" = "8" ]; then npm run coveralls-report; fi
1718
deploy:
1819
- provider: pages
1920
skip_cleanup: true
2021
local_dir: ts-docs
22+
keep_history: true
2123
github_token: $GITHUB_TOKEN
2224
on:
2325
branch: master
26+
node_js: "8"
2427
- provider: script
2528
skip_cleanup: true
2629
script: /bin/sh travis/uploadArchives.sh
2730
on:
2831
branch: master
2932
node_js: "8"
33+
- provider: script
34+
skip_cleanup: true
35+
script: /bin/sh travis/release.sh
36+
on:
37+
branch: $RELEASE_BRANCH
38+
node_js: "8"

src/infrastructure/BlockHttp.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { from as observableFrom, Observable, throwError } from 'rxjs';
18-
import { catchError, map } from 'rxjs/operators';
17+
import { Observable } from 'rxjs';
1918
import { BlockInfoDTO, BlockRoutesApi } from 'symbol-openapi-typescript-node-client';
2019
import { PublicAccount } from '../model/account/PublicAccount';
2120
import { BlockInfo } from '../model/blockchain/BlockInfo';
@@ -55,10 +54,7 @@ export class BlockHttp extends Http implements BlockRepository {
5554
* @returns Observable<BlockInfo>
5655
*/
5756
public getBlockByHeight(height: UInt64): Observable<BlockInfo> {
58-
return observableFrom(this.blockRoutesApi.getBlockByHeight(height.toString())).pipe(
59-
map(({body}) => this.toBlockInfo(body)),
60-
catchError((error) => throwError(this.errorHandling(error))),
61-
);
57+
return this.call(this.blockRoutesApi.getBlockByHeight(height.toString()), (body) => this.toBlockInfo(body));
6258
}
6359

6460
/**
@@ -69,15 +65,12 @@ export class BlockHttp extends Http implements BlockRepository {
6965
*/
7066
public getBlockTransactions(height: UInt64,
7167
queryParams?: QueryParams): Observable<Transaction[]> {
72-
return observableFrom(
73-
this.blockRoutesApi.getBlockTransactions(height.toString(),
74-
this.queryParams(queryParams).pageSize,
75-
this.queryParams(queryParams).id,
76-
this.queryParams(queryParams).ordering))
77-
.pipe(map(({body}) => body.map((transactionDTO) => {
78-
return CreateTransactionFromDTO(transactionDTO);
79-
})),
80-
catchError((error) => throwError(this.errorHandling(error))),
68+
return this.call(this.blockRoutesApi.getBlockTransactions(height.toString(),
69+
this.queryParams(queryParams).pageSize,
70+
this.queryParams(queryParams).id,
71+
this.queryParams(queryParams).ordering), (body) => body.map((transactionDTO) => {
72+
return CreateTransactionFromDTO(transactionDTO);
73+
}),
8174
);
8275
}
8376

@@ -88,11 +81,8 @@ export class BlockHttp extends Http implements BlockRepository {
8881
* @returns Observable<BlockInfo[]>
8982
*/
9083
public getBlocksByHeightWithLimit(height: UInt64, limit: number): Observable<BlockInfo[]> {
91-
return observableFrom(
92-
this.blockRoutesApi.getBlocksByHeightWithLimit(height.toString(), limit)).pipe(
93-
map(({body}) => body.map((blockDTO) => this.toBlockInfo(blockDTO))),
94-
catchError((error) => throwError(this.errorHandling(error))),
95-
);
84+
return this.call(this.blockRoutesApi.getBlocksByHeightWithLimit(height.toString(), limit), (body) =>
85+
body.map((blockDTO) => this.toBlockInfo(blockDTO)));
9686
}
9787

9888
/**
@@ -138,12 +128,10 @@ export class BlockHttp extends Http implements BlockRepository {
138128
* @return Observable<MerkleProofInfo>
139129
*/
140130
public getMerkleTransaction(height: UInt64, hash: string): Observable<MerkleProofInfo> {
141-
return observableFrom(
142-
this.blockRoutesApi.getMerkleTransaction(height.toString(), hash)).pipe(
143-
map(({body}) => new MerkleProofInfo(
144-
body.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash)),
145-
)),
146-
catchError((error) => throwError(this.errorHandling(error))),
147-
);
131+
return this.call(
132+
this.blockRoutesApi.getMerkleTransaction(height.toString(), hash), (body) => new MerkleProofInfo(
133+
body.merklePath!.map((payload) => new MerklePathItem(payload.position, payload.hash)),
134+
));
148135
}
136+
149137
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
* Copyright 2020 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { expect } from 'chai';
17+
import * as http from 'http';
18+
import {
19+
BlockDTO,
20+
BlockInfoDTO,
21+
BlockMetaDTO,
22+
BlockRoutesApi,
23+
MerklePathItemDTO,
24+
MerkleProofInfoDTO,
25+
NetworkTypeEnum,
26+
PositionEnum,
27+
} from 'symbol-openapi-typescript-node-client';
28+
import { instance, mock, reset, when } from 'ts-mockito';
29+
import { DtoMapping } from '../../src/core/utils/DtoMapping';
30+
import { BlockHttp } from '../../src/infrastructure/BlockHttp';
31+
import { BlockRepository } from '../../src/infrastructure/BlockRepository';
32+
import { BlockInfo } from '../../src/model/blockchain/BlockInfo';
33+
import { MerklePathItem } from '../../src/model/blockchain/MerklePathItem';
34+
import { Transaction } from '../../src/model/transaction/Transaction';
35+
import { UInt64 } from '../../src/model/UInt64';
36+
37+
describe('BlockHttp', () => {
38+
39+
const blockDTO = new BlockDTO();
40+
blockDTO.version = 1;
41+
blockDTO.network = NetworkTypeEnum.NUMBER_152;
42+
blockDTO.beneficiaryPublicKey = 'a';
43+
blockDTO.difficulty = '2';
44+
blockDTO.feeMultiplier = 3;
45+
blockDTO.height = '4';
46+
blockDTO.previousBlockHash = '5';
47+
blockDTO.type = 6;
48+
blockDTO.signerPublicKey = '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A7';
49+
blockDTO.timestamp = '7';
50+
blockDTO.beneficiaryPublicKey = '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A8';
51+
52+
const blockMetaDTO = new BlockMetaDTO();
53+
blockMetaDTO.generationHash = 'abc';
54+
blockMetaDTO.hash = 'aHash';
55+
blockMetaDTO.numStatements = 10;
56+
blockMetaDTO.numTransactions = 20;
57+
blockMetaDTO.totalFee = '30';
58+
blockMetaDTO.stateHashSubCacheMerkleRoots = ['a', 'b', 'c'];
59+
60+
const blockInfoDto = new BlockInfoDTO();
61+
blockInfoDto.block = blockDTO;
62+
blockInfoDto.meta = blockMetaDTO;
63+
64+
const url = 'http://someHost';
65+
const response: http.IncomingMessage = mock();
66+
const blockRoutesApi: BlockRoutesApi = mock();
67+
const blockRepository: BlockRepository = DtoMapping.assign(new BlockHttp(url), {blockRoutesApi: instance(blockRoutesApi)});
68+
69+
const transactionInfoDTO = {
70+
meta: {
71+
hash: '671653C94E2254F2A23EFEDB15D67C38332AED1FBD24B063C0A8E675582B6A96',
72+
height: '18160',
73+
id: '5A0069D83F17CF0001777E55',
74+
index: 0,
75+
merkleComponentHash: '81E5E7AE49998802DABC816EC10158D3A7879702FF29084C2C992CD1289877A7',
76+
},
77+
transaction: {
78+
deadline: '1000',
79+
maxFee: '0',
80+
signature: '939673209A13FF82397578D22CC96EB8516A6760C894D9B7535E3A1E0680' +
81+
'07B9255CFA9A914C97142A7AE18533E381C846B69D2AE0D60D1DC8A55AD120E2B606',
82+
signerPublicKey: '7681ED5023141D9CDCF184E5A7B60B7D466739918ED5DA30F7E71EA7B86EFF2D',
83+
minApprovalDelta: 1,
84+
minRemovalDelta: 1,
85+
modifications: [
86+
{
87+
cosignatoryPublicKey: '589B73FBC22063E9AE6FBAC67CB9C6EA865EF556E5' +
88+
'FB8B7310D45F77C1250B97',
89+
modificationAction: 0,
90+
},
91+
],
92+
type: 16725,
93+
version: 1,
94+
network: 144,
95+
},
96+
};
97+
98+
before(() => {
99+
reset(response);
100+
reset(blockRoutesApi);
101+
});
102+
103+
function assertBlockInfo(blockInfo: BlockInfo) {
104+
expect(blockInfo).to.be.not.null;
105+
expect(blockInfo.type).to.be.equals(blockInfoDto.block.type);
106+
expect(blockInfo.previousBlockHash).to.be.equals(blockInfoDto.block.previousBlockHash);
107+
expect(blockInfo.height.toString()).to.be.equals(blockInfoDto.block.height);
108+
expect(blockInfo.feeMultiplier).to.be.equals(blockInfoDto.block.feeMultiplier);
109+
expect(blockInfo.networkType).to.be.equals(blockInfoDto.block.network);
110+
expect(blockInfo.version).to.be.equals(blockInfoDto.block.version);
111+
expect(blockInfo.beneficiaryPublicKey!.publicKey).to.be.equals(blockInfoDto.block.beneficiaryPublicKey);
112+
expect(blockInfo.difficulty.toString()).to.be.equals(blockInfoDto.block.difficulty);
113+
expect(blockInfo.feeMultiplier).to.be.equals(blockInfoDto.block.feeMultiplier);
114+
expect(blockInfo.signer!.publicKey).to.be.equals(blockInfoDto.block.signerPublicKey);
115+
expect(blockInfo.signature).to.be.equals(blockInfoDto.block.signature);
116+
117+
expect(blockInfo.generationHash).to.be.equals(blockInfoDto.meta.generationHash);
118+
expect(blockInfo.hash).to.be.equals(blockInfoDto.meta.hash);
119+
expect(blockInfo.numStatements).to.be.equals(blockInfoDto.meta.numStatements);
120+
expect(blockInfo.numTransactions).to.be.equals(blockInfoDto.meta.numTransactions);
121+
expect(blockInfo.totalFee.toString()).to.be.equals(blockInfoDto.meta.totalFee);
122+
}
123+
124+
function assertTransaction(transaction: Transaction) {
125+
expect(transaction).to.be.not.null;
126+
expect(transaction.type).to.be.equals(transactionInfoDTO.transaction.type);
127+
expect(transaction.deadline.toString()).to.be.equals(transactionInfoDTO.transaction.deadline);
128+
}
129+
130+
it('getBlockInfo', async () => {
131+
when(blockRoutesApi.getBlockByHeight('1')).thenReturn(Promise.resolve({response, body: blockInfoDto}));
132+
const blockInfo = await blockRepository.getBlockByHeight(UInt64.fromUint(1)).toPromise();
133+
assertBlockInfo(blockInfo);
134+
});
135+
136+
it('getBlocksByHeightWithLimit', async () => {
137+
when(blockRoutesApi.getBlocksByHeightWithLimit('2', 10)).thenReturn(Promise.resolve({
138+
response,
139+
body: [blockInfoDto],
140+
}));
141+
const blockInfos = await blockRepository.getBlocksByHeightWithLimit(UInt64.fromUint(2), 10).toPromise();
142+
assertBlockInfo(blockInfos[0]);
143+
});
144+
145+
it('getBlockTransactions', async () => {
146+
when(blockRoutesApi.getBlockTransactions('2', undefined, undefined, undefined)).thenReturn(Promise.resolve({
147+
response,
148+
body: [transactionInfoDTO],
149+
}));
150+
const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(2)).toPromise();
151+
assertTransaction(transactions[0]);
152+
});
153+
154+
it('getMerkleTransaction', async () => {
155+
const merkleProofInfoDTO = new MerkleProofInfoDTO();
156+
const merklePathItemDTO = new MerklePathItemDTO();
157+
merklePathItemDTO.hash = 'bbb';
158+
merklePathItemDTO.position = PositionEnum.Left;
159+
merkleProofInfoDTO.merklePath = [merklePathItemDTO];
160+
161+
when(blockRoutesApi.getMerkleTransaction('2', 'abc')).thenReturn(Promise.resolve({
162+
response,
163+
body: merkleProofInfoDTO,
164+
}));
165+
const merkleProofInfo = await blockRepository.getMerkleTransaction(UInt64.fromUint(2), 'abc').toPromise();
166+
expect(merkleProofInfo).to.be.not.null;
167+
expect(merkleProofInfo.merklePath).to.deep.equals([new MerklePathItem(PositionEnum.Left, 'bbb')]);
168+
});
169+
170+
});
File renamed without changes.

travis/release.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
if [ "$TRAVIS_BRANCH" = "$RELEASE_BRANCH" ]; then
5+
6+
REMOTE_NAME="origin"
7+
POST_RELEASE_BRANCH="post-$RELEASE_BRANCH"
8+
9+
git remote rm $REMOTE_NAME
10+
11+
echo "Setting remote url https://github.com/${TRAVIS_REPO_SLUG}.git"
12+
git remote add $REMOTE_NAME "https://${GRGIT_USER}@github.com/${TRAVIS_REPO_SLUG}.git" > /dev/null 2>&1
13+
14+
echo "Checking out $RELEASE_BRANCH as travis leaves the head detached."
15+
git checkout $RELEASE_BRANCH
16+
17+
CURRENT_VERSION=$(npm run version --silent)
18+
19+
echo "Current Version"
20+
cat "$CURRENT_VERSION"
21+
echo ""
22+
23+
echo "Testing git remote"
24+
git branch -vv
25+
echo ""
26+
27+
echo "Creating tag v$CURRENT_VERSION"
28+
git tag "v$CURRENT_VERSION"
29+
echo ""
30+
31+
cp travis/.npmrc $HOME/.npmrc
32+
33+
echo "Releasing sdk artifacts"
34+
npm publish
35+
echo ""
36+
37+
echo "Increasing sdk version"
38+
npm version patch -m "Increasing version to %s" --git-tag-version false
39+
40+
CURRENT_VERSION=$(npm run version --silent)
41+
42+
echo "New Version"
43+
cat "$CURRENT_VERSION"
44+
echo ""
45+
46+
echo "Pushing code to $REMOTE_NAME $POST_RELEASE_BRANCH"
47+
git push --set-upstream $REMOTE_NAME $RELEASE_BRANCH:$POST_RELEASE_BRANCH
48+
echo "Pushing tags to $REMOTE_NAME"
49+
git push --tags $REMOTE_NAME
50+
else
51+
echo "Release is disabled"
52+
fi

travis/uploadArchives.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CURRENT_VERSION=$(npm run version --silent)
55
NEW_VERSION="$CURRENT_VERSION-alpha-$(date +%Y%m%d%H%M)"
66

77
echo "Uploading npm package version $NEW_VERSION"
8-
cp .npmrc.template $HOME/.npmrc
8+
cp travis/.npmrc $HOME/.npmrc
99

1010
npm version "$NEW_VERSION" --commit-hooks false --git-tag-version false
1111

0 commit comments

Comments
 (0)