Skip to content

Commit cb691b3

Browse files
rg911fboucquez
andauthored
Merged ChainHttp endpoints and added finalized block (#671)
* Fixed #650 - Merged ChainHttp endpoints * e2e tests (#663) * Fixed #650 - Merged ChainHttp endpoints * Fixed e2e test with symbol-bootstrap * Fixed #650 - Merged ChainHttp endpoints * Fixed some e2e tests * Fixed listner test * fixed metadata test * Fixed more e2e test issues * Fixed #669 node role type * Removed redundant node role types * Removed finalizedHeight from chainInfo Co-authored-by: fboucquez <fboucquez@gmail.com>
1 parent 08d954e commit cb691b3

File tree

17 files changed

+205
-144
lines changed

17 files changed

+205
-144
lines changed

e2e/infrastructure/ChainHttp.spec.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,12 @@ describe('ChainHttp', () => {
3232
return helper.close();
3333
});
3434

35-
describe('getBlockchainHeight', () => {
36-
it('should return blockchain height', async () => {
37-
const height = await chainRepository.getBlockchainHeight().toPromise();
38-
expect(height.lower).to.be.greaterThan(0);
39-
});
40-
});
41-
42-
describe('getBlockchainScore', () => {
35+
describe('getChainInfo', () => {
4336
it('should return blockchain score', async () => {
44-
const blockchainScore = await chainRepository.getChainScore().toPromise();
45-
expect(blockchainScore.scoreLow).to.not.be.equal(undefined);
46-
expect(blockchainScore.scoreHigh.lower).to.be.equal(0);
47-
expect(blockchainScore.scoreHigh.higher).to.be.equal(0);
37+
const info = await chainRepository.getChainInfo().toPromise();
38+
expect(info.scoreLow).to.not.be.equal(undefined);
39+
expect(info.scoreHigh.lower).to.be.equal(0);
40+
expect(info.scoreHigh.higher).to.be.equal(0);
4841
});
4942
});
5043
});

e2e/infrastructure/HashLockHttp.spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('HashLockHttp', () => {
9090
signedAggregatedTransaction: SignedTransaction,
9191
signer: Account,
9292
mosaicId: UnresolvedMosaicId,
93-
): void => {
93+
): any => {
9494
const lockFundsTransaction = LockFundsTransaction.create(
9595
Deadline.create(),
9696
new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))),
@@ -100,8 +100,7 @@ describe('HashLockHttp', () => {
100100
helper.maxFee,
101101
);
102102
const signedLockFundsTransaction = signer.sign(lockFundsTransaction, generationHash);
103-
hash = signedLockFundsTransaction.hash;
104-
helper.announce(signedLockFundsTransaction);
103+
return helper.announce(signedLockFundsTransaction);
105104
};
106105

107106
/**
@@ -152,17 +151,11 @@ describe('HashLockHttp', () => {
152151
* =========================
153152
*/
154153

155-
describe('getHashLock', () => {
156-
it('should return hash lock info given hash', async () => {
157-
const info = await hashLockRepo.getHashLock(hash).toPromise();
158-
expect(info.ownerAddress.plain()).to.be.equal(account.address.plain());
159-
expect(info.amount.toString()).to.be.equal('1000');
160-
});
161-
});
162-
163154
describe('searchHashLock', () => {
164155
it('should return hash lock page info', async () => {
156+
await new Promise((resolve) => setTimeout(resolve, 3000));
165157
const info = await hashLockRepo.search({ address: account.address }).toPromise();
158+
hash = info.data[0].hash;
166159
expect(info.data.length).to.be.greaterThan(0);
167160
});
168161
});
@@ -180,6 +173,14 @@ describe('HashLockHttp', () => {
180173
});
181174
});
182175

176+
describe('getHashLock', () => {
177+
it('should return hash lock info given hash', async () => {
178+
const info = await hashLockRepo.getHashLock(hash).toPromise();
179+
expect(info.ownerAddress.plain()).to.be.equal(account.address.plain());
180+
expect(info.amount.toString()).to.be.equal('10000000');
181+
});
182+
});
183+
183184
/**
184185
* =========================
185186
* House Keeping

e2e/infrastructure/Listener.spec.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ describe('Listener', () => {
379379
throw new Error('Transaction should have failed!!');
380380
},
381381
(error) => {
382-
expect(error.code).to.be.equal('Failure_Core_Insufficient_Balance');
382+
expect(error.message).to.be.equal('Failure_Core_Insufficient_Balance');
383383
},
384384
);
385385
});
@@ -390,16 +390,6 @@ describe('Listener', () => {
390390
helper.listener.newBlock().subscribe(() => {
391391
done();
392392
});
393-
const transferTransaction = TransferTransaction.create(
394-
Deadline.create(),
395-
account2.address,
396-
[],
397-
PlainMessage.create('test-message'),
398-
networkType,
399-
helper.maxFee,
400-
);
401-
402-
helper.announce(transferTransaction.signWith(account, generationHash));
403393
});
404394
});
405395

@@ -408,16 +398,6 @@ describe('Listener', () => {
408398
helper.listener.finalizedBlock().subscribe(() => {
409399
done();
410400
});
411-
const transferTransaction = TransferTransaction.create(
412-
Deadline.create(),
413-
account2.address,
414-
[],
415-
PlainMessage.create('test-message'),
416-
networkType,
417-
helper.maxFee,
418-
);
419-
420-
helper.announce(transferTransaction.signWith(account, generationHash));
421401
});
422402
});
423403
});

e2e/infrastructure/MetadataHttp.spec.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,6 @@ describe('MetadataHttp', () => {
126126
});
127127
});
128128

129-
describe('AccountMetadataTransaction', () => {
130-
it('aggregate', () => {
131-
const accountMetadataTransaction = AccountMetadataTransaction.create(
132-
Deadline.create(),
133-
account.address,
134-
UInt64.fromUint(6),
135-
0,
136-
`Test account mett value`,
137-
networkType,
138-
helper.maxFee,
139-
);
140-
141-
const aggregateTransaction = AggregateTransaction.createComplete(
142-
Deadline.create(),
143-
[accountMetadataTransaction.toAggregate(account.publicAccount)],
144-
networkType,
145-
[],
146-
helper.maxFee,
147-
);
148-
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
149-
return helper.announce(signedTransaction);
150-
});
151-
});
152-
153129
describe('MosaicMetadataTransaction', () => {
154130
it('aggregate', () => {
155131
const mosaicMetadataTransaction = MosaicMetadataTransaction.create(

e2e/infrastructure/SecretLockHttp.spec.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('SecretLockHttp', () => {
4343
account = helper.account;
4444
account2 = helper.account2;
4545
networkType = helper.networkType;
46+
generationHash = helper.generationHash;
4647
SecretLockRepo = helper.repositoryFactory.createSecretLockRepository();
4748
secret = sha3_256.create().update(Crypto.randomBytes(20)).hex();
4849
});
@@ -71,13 +72,7 @@ describe('SecretLockHttp', () => {
7172
helper.maxFee,
7273
);
7374
const signedTransaction = secretLockTransaction.signWith(account, generationHash);
74-
return helper.announce(signedTransaction).then((transaction: SecretLockTransaction) => {
75-
expect(transaction.mosaic, 'Mosaic').not.to.be.undefined;
76-
expect(transaction.duration, 'Duration').not.to.be.undefined;
77-
expect(transaction.hashAlgorithm, 'HashAlgorithm').not.to.be.undefined;
78-
expect(transaction.secret, 'Secret').not.to.be.undefined;
79-
expect(transaction.recipientAddress, 'RecipientAddress').not.to.be.undefined;
80-
});
75+
return helper.announce(signedTransaction);
8176
});
8277
});
8378

@@ -89,10 +84,11 @@ describe('SecretLockHttp', () => {
8984

9085
describe('getSecretLock', () => {
9186
it('should return hash lock info given hash', async () => {
87+
await new Promise((resolve) => setTimeout(resolve, 3000));
9288
const info = await SecretLockRepo.getSecretLock(secret).toPromise();
9389
expect(info.ownerAddress.plain()).to.be.equal(account.address.plain());
9490
expect(info.recipientAddress.plain()).to.be.equal(account2.address.plain());
95-
expect(info.amount.toString()).to.be.equal('100');
91+
expect(info.amount.toString()).to.be.equal('10');
9692
});
9793
});
9894

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"ripemd160": "^2.0.2",
109109
"rxjs": "^6.5.3",
110110
"rxjs-compat": "^6.5.3",
111-
"symbol-openapi-typescript-fetch-client": "0.9.7-SNAPSHOT.202009110940",
111+
"symbol-openapi-typescript-fetch-client": "0.9.7-SNAPSHOT.202009141633",
112112
"tweetnacl": "^1.0.3",
113113
"utf8": "^3.0.0",
114114
"ws": "^7.2.3"

src/infrastructure/ChainHttp.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
*/
1616

1717
import { Observable } from 'rxjs';
18-
import { ChainRoutesApi } from 'symbol-openapi-typescript-fetch-client';
19-
import { BlockchainScore } from '../model/blockchain/BlockchainScore';
18+
import { ChainRoutesApi, ChainInfoDTO } from 'symbol-openapi-typescript-fetch-client';
19+
import { ChainInfo } from '../model/blockchain/ChainInfo';
2020
import { UInt64 } from '../model/UInt64';
2121
import { ChainRepository } from './ChainRepository';
2222
import { Http } from './Http';
23+
import { FinalizedBlock } from '../model/blockchain/FinalizedBlock';
2324

2425
/**
2526
* Chian http repository.
@@ -44,21 +45,24 @@ export class ChainHttp extends Http implements ChainRepository {
4445
}
4546

4647
/**
47-
* Gets current blockchain height
48-
* @returns Observable<UInt64>
48+
* Gets current blockchain info
49+
* @returns Observable<ChainInfo>
4950
*/
50-
public getBlockchainHeight(): Observable<UInt64> {
51-
return this.call(this.chainRoutesApi.getChainHeight(), (body) => UInt64.fromNumericString(body.height));
52-
}
53-
54-
/**
55-
* Gets current blockchain score
56-
* @returns Observable<BlockchainScore>
57-
*/
58-
public getChainScore(): Observable<BlockchainScore> {
51+
public getChainInfo(): Observable<ChainInfo> {
5952
return this.call(
60-
this.chainRoutesApi.getChainScore(),
61-
(body) => new BlockchainScore(UInt64.fromNumericString(body.scoreLow), UInt64.fromNumericString(body.scoreHigh)),
53+
this.chainRoutesApi.getChainInfo(),
54+
(body: ChainInfoDTO) =>
55+
new ChainInfo(
56+
UInt64.fromNumericString(body.height),
57+
UInt64.fromNumericString(body.scoreLow),
58+
UInt64.fromNumericString(body.scoreHigh),
59+
new FinalizedBlock(
60+
UInt64.fromNumericString(body.latestFinalizedBlock.height),
61+
body.latestFinalizedBlock.hash,
62+
body.latestFinalizedBlock.finalizationPoint,
63+
body.latestFinalizedBlock.finalizationPoint,
64+
),
65+
),
6266
);
6367
}
6468
}

src/infrastructure/ChainRepository.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616

1717
import { Observable } from 'rxjs';
18-
import { BlockchainScore } from '../model/blockchain/BlockchainScore';
19-
import { UInt64 } from '../model/UInt64';
18+
import { ChainInfo } from '../model/blockchain/ChainInfo';
2019

2120
/**
2221
* Chain interface repository.
@@ -25,14 +24,8 @@ import { UInt64 } from '../model/UInt64';
2524
*/
2625
export interface ChainRepository {
2726
/**
28-
* Gets current blockchain height
29-
* @returns Observable<UInt64>
30-
*/
31-
getBlockchainHeight(): Observable<UInt64>;
32-
33-
/**
34-
* Gets current blockchain score
27+
* Gets current blockchain infomation
3528
* @returns Observable<BlockchainScore>
3629
*/
37-
getChainScore(): Observable<BlockchainScore>;
30+
getChainInfo(): Observable<ChainInfo>;
3831
}

src/infrastructure/NodeHttp.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { StorageInfo } from '../model/blockchain/StorageInfo';
2020
import { NodeHealth } from '../model/node/NodeHealth';
2121
import { NodeInfo } from '../model/node/NodeInfo';
2222
import { NodeTime } from '../model/node/NodeTime';
23+
import { RoleType } from '../model/node/RoleType';
2324
import { ServerInfo } from '../model/node/ServerInfo';
2425
import { UInt64 } from '../model/UInt64';
2526
import { Http } from './Http';
@@ -123,9 +124,27 @@ export class NodeHttp extends Http implements NodeRepository {
123124
nodeInfo.port,
124125
nodeInfo.networkIdentifier,
125126
nodeInfo.version,
126-
nodeInfo.roles as number,
127+
this.getNodeRoles(nodeInfo.roles.valueOf()),
127128
nodeInfo.host,
128129
nodeInfo.friendlyName,
129130
);
130131
}
132+
133+
/**
134+
* Return user friendly role type list
135+
* @param roleType combined node role types
136+
*/
137+
public getNodeRoles(roleType: number): RoleType[] {
138+
const roles: RoleType[] = [];
139+
if ((RoleType.ApiNode.valueOf() & roleType) != 0) {
140+
roles.push(RoleType.ApiNode);
141+
}
142+
if ((RoleType.PeerNode.valueOf() & roleType) != 0) {
143+
roles.push(RoleType.PeerNode);
144+
}
145+
if ((RoleType.VotingNode.valueOf() & roleType) != 0) {
146+
roles.push(RoleType.VotingNode);
147+
}
148+
return roles;
149+
}
131150
}

0 commit comments

Comments
 (0)