Skip to content

Commit b26694b

Browse files
authored
Merge pull request #386 from NEMStudios/task/g381_repositoryInterfacesAndFactory
Added RepositoryFactory
2 parents dd7ad3b + 51c2392 commit b26694b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2871
-4036
lines changed

e2e/conf/network.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"apiUrl": "http://localhost:3000",
3-
"generationHash": "5E34C898234E17E8553359D4DEAA123742C323F4C42758C511E6CC805934853E",
43
"testAccount": {
54
"privateKey": "C422CC3C9257A1568036E1726E64EB5923C8363A13D4344F9E66CD89C8789BC7",
65
"address": "SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN",

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 99 additions & 199 deletions
Large diffs are not rendered by default.

e2e/infrastructure/BlockHttp.spec.ts

Lines changed: 73 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -14,100 +14,90 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {assert, expect} from 'chai';
17+
import { expect } from 'chai';
1818
import { mergeMap } from 'rxjs/operators';
19-
import {BlockHttp} from '../../src/infrastructure/BlockHttp';
20-
import { Listener, ReceiptHttp, TransactionHttp } from '../../src/infrastructure/infrastructure';
21-
import {QueryParams} from '../../src/infrastructure/QueryParams';
19+
import { BlockHttp } from '../../src/infrastructure/BlockHttp';
20+
import { QueryParams } from '../../src/infrastructure/QueryParams';
2221
import { Account } from '../../src/model/account/Account';
2322
import { NetworkType } from '../../src/model/blockchain/NetworkType';
2423
import { PlainMessage } from '../../src/model/message/PlainMessage';
2524
import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic';
2625
import { Deadline } from '../../src/model/transaction/Deadline';
27-
import { Transaction } from '../../src/model/transaction/Transaction';
2826
import { TransactionInfo } from '../../src/model/transaction/TransactionInfo';
2927
import { TransferTransaction } from '../../src/model/transaction/TransferTransaction';
28+
import { IntegrationTestHelper } from "./IntegrationTestHelper";
29+
import { BlockRepository } from "../../src/infrastructure/BlockRepository";
30+
import { ReceiptRepository } from "../../src/infrastructure/ReceiptRepository";
3031

3132
describe('BlockHttp', () => {
33+
let helper = new IntegrationTestHelper();
3234
let account: Account;
3335
let account2: Account;
34-
let blockHttp: BlockHttp;
35-
let receiptHttp: ReceiptHttp;
36-
let transactionHttp: TransactionHttp;
36+
let blockRepository: BlockRepository;
37+
let receiptRepository: ReceiptRepository;
3738
let blockReceiptHash = '';
3839
let blockTransactionHash = '';
39-
let config;
4040
let chainHeight;
4141
let generationHash: string;
42-
before((done) => {
43-
const path = require('path');
44-
require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => {
45-
if (err) {
46-
throw err;
47-
}
48-
const json = JSON.parse(data);
49-
config = json;
50-
account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST);
51-
account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST);
52-
blockHttp = new BlockHttp(json.apiUrl);
53-
transactionHttp = new TransactionHttp(json.apiUrl);
54-
receiptHttp = new ReceiptHttp(json.apiUrl);
55-
generationHash = json.generationHash;
56-
done();
42+
let networkType: NetworkType;
43+
44+
before(() => {
45+
return helper.start().then(() => {
46+
account = helper.account;
47+
account2 = helper.account2;
48+
generationHash = helper.generationHash;
49+
networkType = helper.networkType;
50+
blockRepository = helper.repositoryFactory.createBlockRepository();
51+
receiptRepository = helper.repositoryFactory.createReceiptRepository();
5752
});
5853
});
5954

55+
before(() => {
56+
return helper.listener.open();
57+
});
58+
59+
after(() => {
60+
helper.listener.close();
61+
});
62+
6063
/**
6164
* =========================
6265
* Setup Test Data
6366
* =========================
6467
*/
6568

6669
describe('Setup Test Data', () => {
67-
let listener: Listener;
68-
before (() => {
69-
listener = new Listener(config.apiUrl);
70-
return listener.open();
71-
});
72-
after(() => {
73-
return listener.close();
74-
});
70+
7571

7672
it('Announce TransferTransaction', (done) => {
7773
const transferTransaction = TransferTransaction.create(
7874
Deadline.create(),
7975
account2.address,
8076
[NetworkCurrencyMosaic.createAbsolute(1)],
8177
PlainMessage.create('test-message'),
82-
NetworkType.MIJIN_TEST,
78+
networkType,
79+
helper.maxFee
8380
);
8481
const signedTransaction = transferTransaction.signWith(account, generationHash);
85-
86-
listener.confirmed(account.address).subscribe((transaction: Transaction) => {
82+
helper.announce(signedTransaction).then(transaction => {
8783
chainHeight = transaction.transactionInfo!.height.toString();
88-
done();
89-
});
90-
listener.status(account.address).subscribe((error) => {
91-
console.log('Error:', error);
92-
assert(false);
93-
done();
84+
return transaction;
9485
});
95-
transactionHttp.announce(signedTransaction);
9686
});
9787
});
9888

9989
describe('getBlockByHeight', () => {
10090
it('should return block info given height', (done) => {
101-
blockHttp.getBlockByHeight('1')
102-
.subscribe((blockInfo) => {
103-
blockReceiptHash = blockInfo.blockReceiptsHash;
104-
blockTransactionHash = blockInfo.blockTransactionsHash;
105-
expect(blockInfo.height.lower).to.be.equal(1);
106-
expect(blockInfo.height.higher).to.be.equal(0);
107-
expect(blockInfo.timestamp.lower).to.be.equal(0);
108-
expect(blockInfo.timestamp.higher).to.be.equal(0);
109-
done();
110-
});
91+
blockRepository.getBlockByHeight('1')
92+
.subscribe((blockInfo) => {
93+
blockReceiptHash = blockInfo.blockReceiptsHash;
94+
blockTransactionHash = blockInfo.blockTransactionsHash;
95+
expect(blockInfo.height.lower).to.be.equal(1);
96+
expect(blockInfo.height.higher).to.be.equal(0);
97+
expect(blockInfo.timestamp.lower).to.be.equal(0);
98+
expect(blockInfo.timestamp.higher).to.be.equal(0);
99+
done();
100+
});
111101
});
112102
});
113103

@@ -116,39 +106,39 @@ describe('BlockHttp', () => {
116106
let firstId: string;
117107

118108
it('should return block transactions data given height', (done) => {
119-
blockHttp.getBlockTransactions('1')
120-
.subscribe((transactions) => {
121-
nextId = transactions[0].transactionInfo!.id;
122-
firstId = transactions[1].transactionInfo!.id;
123-
expect(transactions.length).to.be.greaterThan(0);
124-
done();
125-
});
109+
blockRepository.getBlockTransactions('1')
110+
.subscribe((transactions) => {
111+
nextId = transactions[0].transactionInfo!.id;
112+
firstId = transactions[1].transactionInfo!.id;
113+
expect(transactions.length).to.be.greaterThan(0);
114+
done();
115+
});
126116
});
127117

128118
it('should return block transactions data given height with paginated transactionId', (done) => {
129-
blockHttp.getBlockTransactions('1', new QueryParams(10, nextId))
130-
.subscribe((transactions) => {
131-
expect(transactions[0].transactionInfo!.id).to.be.equal(firstId);
132-
expect(transactions.length).to.be.greaterThan(0);
133-
done();
134-
});
119+
blockRepository.getBlockTransactions('1', new QueryParams(10, nextId))
120+
.subscribe((transactions) => {
121+
expect(transactions[0].transactionInfo!.id).to.be.equal(firstId);
122+
expect(transactions.length).to.be.greaterThan(0);
123+
done();
124+
});
135125
});
136126
});
137127

138128
describe('getBlocksByHeightWithLimit', () => {
139129
it('should return block info given height and limit', (done) => {
140-
blockHttp.getBlocksByHeightWithLimit(chainHeight, 50)
141-
.subscribe((blocksInfo) => {
142-
expect(blocksInfo.length).to.be.greaterThan(0);
143-
done();
144-
});
130+
blockRepository.getBlocksByHeightWithLimit(chainHeight, 50)
131+
.subscribe((blocksInfo) => {
132+
expect(blocksInfo.length).to.be.greaterThan(0);
133+
done();
134+
});
145135
});
146136
});
147137
describe('getMerkleReceipts', () => {
148138
it('should return Merkle Receipts', (done) => {
149-
receiptHttp.getBlockReceipts(chainHeight).pipe(
139+
receiptRepository.getBlockReceipts(chainHeight).pipe(
150140
mergeMap((_) => {
151-
return receiptHttp.getMerkleReceipts(chainHeight, _.transactionStatements[0].generateHash());
141+
return receiptRepository.getMerkleReceipts(chainHeight, _.transactionStatements[0].generateHash());
152142
}))
153143
.subscribe((merkleReceipts) => {
154144
expect(merkleReceipts.merklePath).not.to.be.null;
@@ -158,30 +148,30 @@ describe('BlockHttp', () => {
158148
});
159149
describe('getMerkleTransaction', () => {
160150
it('should return Merkle Transaction', (done) => {
161-
blockHttp.getBlockTransactions(chainHeight).pipe(
151+
blockRepository.getBlockTransactions(chainHeight).pipe(
162152
mergeMap((_) => {
163153
const hash = (_[0].transactionInfo as TransactionInfo).hash;
164154
if (hash) {
165-
return blockHttp.getMerkleTransaction(chainHeight, hash);
155+
return blockRepository.getMerkleTransaction(chainHeight, hash);
166156
}
167157
// If reaching this line, something is not right
168158
throw new Error('Tansacation hash is undefined');
169159
}))
170160
.subscribe((merkleTransactionss) => {
171-
expect(merkleTransactionss.merklePath).not.to.be.null;
172-
done();
173-
});
161+
expect(merkleTransactionss.merklePath).not.to.be.null;
162+
done();
163+
});
174164
});
175165
});
176166

177167
describe('getBlockReceipts', () => {
178168
it('should return block receipts', (done) => {
179-
receiptHttp.getBlockReceipts(chainHeight)
180-
.subscribe((statement) => {
181-
expect(statement.transactionStatements).not.to.be.null;
182-
expect(statement.transactionStatements.length).to.be.greaterThan(0);
183-
done();
184-
});
169+
receiptRepository.getBlockReceipts(chainHeight)
170+
.subscribe((statement) => {
171+
expect(statement.transactionStatements).not.to.be.null;
172+
expect(statement.transactionStatements.length).to.be.greaterThan(0);
173+
done();
174+
});
185175
});
186176
});
187177
});

e2e/infrastructure/ChainHttp.spec.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,40 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {expect} from 'chai';
18-
import {ChainHttp} from '../../src/infrastructure/ChainHttp';
19-
import {QueryParams} from '../../src/infrastructure/QueryParams';
17+
import { expect } from 'chai';
18+
import { ChainHttp } from '../../src/infrastructure/ChainHttp';
19+
import { IntegrationTestHelper } from "./IntegrationTestHelper";
20+
import { ChainRepository } from "../../src/infrastructure/ChainRepository";
21+
2022
describe('ChainHttp', () => {
21-
let chainHttp: ChainHttp;
22-
before((done) => {
23-
const path = require('path');
24-
require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => {
25-
if (err) {
26-
throw err;
27-
}
28-
const json = JSON.parse(data);
29-
chainHttp = new ChainHttp(json.apiUrl);
30-
done();
23+
let helper = new IntegrationTestHelper();
24+
let chainRepository: ChainRepository;
25+
26+
before(() => {
27+
return helper.start().then(() => {
28+
chainRepository = helper.repositoryFactory.createChainRepository();
3129
});
3230
});
3331

3432
describe('getBlockchainHeight', () => {
3533
it('should return blockchain height', (done) => {
36-
chainHttp.getBlockchainHeight()
37-
.subscribe((height) => {
38-
expect(height.lower).to.be.greaterThan(0);
39-
done();
40-
});
34+
chainRepository.getBlockchainHeight()
35+
.subscribe((height) => {
36+
expect(height.lower).to.be.greaterThan(0);
37+
done();
38+
});
4139
});
4240
});
4341

4442
describe('getBlockchainScore', () => {
4543
it('should return blockchain score', (done) => {
46-
chainHttp.getChainScore()
47-
.subscribe((blockchainScore) => {
48-
expect(blockchainScore.scoreLow).to.not.be.equal(undefined);
49-
expect(blockchainScore.scoreHigh.lower).to.be.equal(0);
50-
expect(blockchainScore.scoreHigh.higher).to.be.equal(0);
51-
done();
52-
});
44+
chainRepository.getChainScore()
45+
.subscribe((blockchainScore) => {
46+
expect(blockchainScore.scoreLow).to.not.be.equal(undefined);
47+
expect(blockchainScore.scoreHigh.lower).to.be.equal(0);
48+
expect(blockchainScore.scoreHigh.higher).to.be.equal(0);
49+
done();
50+
});
5351
});
5452
});
5553
});

e2e/infrastructure/DiagnosticHttp.spec.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,41 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {expect} from 'chai';
18-
import {DiagnosticHttp} from '../../src/infrastructure/DiagnosticHttp';
17+
import { expect } from 'chai';
18+
import { DiagnosticHttp } from '../../src/infrastructure/DiagnosticHttp';
19+
import { IntegrationTestHelper } from "./IntegrationTestHelper";
20+
import { DiagnosticRepository } from "../../src/infrastructure/DiagnosticRepository";
21+
1922
describe('DiagnosticHttp', () => {
20-
let diagnosticHttp: DiagnosticHttp;
21-
before((done) => {
22-
const path = require('path');
23-
require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => {
24-
if (err) {
25-
throw err;
26-
}
27-
const json = JSON.parse(data);
28-
diagnosticHttp = new DiagnosticHttp(json.apiUrl);
29-
done();
23+
let helper = new IntegrationTestHelper();
24+
let diagnosticRepository: DiagnosticRepository;
25+
26+
before(() => {
27+
return helper.start().then(() => {
28+
diagnosticRepository = helper.repositoryFactory.createDiagnosticRepository();
3029
});
3130
});
3231

3332
describe('getDiagnosticStorage', () => {
3433
it('should return diagnostic storage', (done) => {
35-
diagnosticHttp.getDiagnosticStorage()
36-
.subscribe((blockchainStorageInfo) => {
37-
expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0);
38-
expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0);
39-
expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0);
40-
done();
41-
});
34+
diagnosticRepository.getDiagnosticStorage()
35+
.subscribe((blockchainStorageInfo) => {
36+
expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0);
37+
expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0);
38+
expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0);
39+
done();
40+
});
4241
});
4342
});
4443

4544
describe('getServerInfo', () => {
4645
it('should return diagnostic storage', (done) => {
47-
diagnosticHttp.getServerInfo()
48-
.subscribe((serverInfo) => {
49-
expect(serverInfo.restVersion).not.to.be.null;
50-
expect(serverInfo.sdkVersion).not.to.be.null;
51-
done();
52-
});
46+
diagnosticRepository.getServerInfo()
47+
.subscribe((serverInfo) => {
48+
expect(serverInfo.restVersion).not.to.be.null;
49+
expect(serverInfo.sdkVersion).not.to.be.null;
50+
done();
51+
});
5352
});
5453
});
5554
});

0 commit comments

Comments
 (0)