Skip to content

Commit c92f39d

Browse files
authored
Merge pull request #406 from NEMStudios/catbuffer-library
TransactionHelper deserialization
2 parents 3526679 + 39bbb21 commit c92f39d

File tree

55 files changed

+1077
-1180
lines changed

Some content is hidden

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

55 files changed

+1077
-1180
lines changed

e2e/infrastructure/AccountHttp.spec.ts

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

17-
import { assert, expect } from 'chai';
17+
import { expect } from 'chai';
1818
import { AccountRepository } from '../../src/infrastructure/AccountRepository';
1919
import { MultisigRepository } from '../../src/infrastructure/MultisigRepository';
2020
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository';
@@ -171,59 +171,42 @@ describe('AccountHttp', () => {
171171
*/
172172

173173
describe('getAccountInfo', () => {
174-
it('should return account data given a NEM Address', (done) => {
175-
accountRepository.getAccountInfo(accountAddress)
176-
.subscribe((accountInfo) => {
177-
expect(accountInfo.publicKey).to.be.equal(accountPublicKey);
178-
done();
179-
});
174+
it('should return account data given a NEM Address', async () => {
175+
const accountInfo = await accountRepository.getAccountInfo(accountAddress).toPromise();
176+
expect(accountInfo.publicKey).to.be.equal(accountPublicKey);
180177
});
181178
});
182179

183180
describe('getAccountsInfo', () => {
184-
it('should return account data given a NEM Address', (done) => {
185-
accountRepository.getAccountsInfo([accountAddress])
186-
.subscribe((accountsInfo) => {
187-
expect(accountsInfo[0].publicKey).to.be.equal(accountPublicKey);
188-
done();
189-
});
181+
it('should return account data given a NEM Address', async () => {
182+
const accountsInfo = await accountRepository.getAccountsInfo([accountAddress]).toPromise();
183+
expect(accountsInfo[0].publicKey).to.be.equal(accountPublicKey);
190184
});
191185
});
192186

193187
describe('getMultisigAccountGraphInfo', () => {
194-
it('should call getMultisigAccountGraphInfo successfully', (done) => {
195-
multisigRepository.getMultisigAccountGraphInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountGraphInfo) => {
196-
expect(multisigAccountGraphInfo.multisigAccounts.get(0)![0].account.publicKey).to.be.equal(multisigAccount.publicKey);
197-
done();
198-
});
188+
it('should call getMultisigAccountGraphInfo successfully', async () => {
189+
const multisigAccountGraphInfo = await multisigRepository.getMultisigAccountGraphInfo(multisigAccount.publicAccount.address).toPromise();
190+
expect(multisigAccountGraphInfo.multisigAccounts.get(0)![0].account.publicKey).to.be.equal(multisigAccount.publicKey);
199191
});
200192
});
201193
describe('getMultisigAccountInfo', () => {
202-
it('should call getMultisigAccountInfo successfully', (done) => {
203-
multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).subscribe((multisigAccountInfo) => {
204-
expect(multisigAccountInfo.account.publicKey).to.be.equal(multisigAccount.publicKey);
205-
done();
206-
});
194+
it('should call getMultisigAccountInfo successfully', async () => {
195+
const multisigAccountInfo = await multisigRepository.getMultisigAccountInfo(multisigAccount.publicAccount.address).toPromise();
196+
expect(multisigAccountInfo.account.publicKey).to.be.equal(multisigAccount.publicKey);
207197
});
208198
});
209199

210200
describe('outgoingTransactions', () => {
211-
it('should call outgoingTransactions successfully', (done) => {
212-
accountRepository.getAccountOutgoingTransactions(publicAccount.address).subscribe((transactions) => {
213-
expect(transactions.length).to.be.greaterThan(0);
214-
done();
215-
});
201+
it('should call outgoingTransactions successfully', async () => {
202+
const transactions = await accountRepository.getAccountOutgoingTransactions(publicAccount.address).toPromise();
203+
expect(transactions.length).to.be.greaterThan(0);
216204
});
217205
});
218206

219207
describe('aggregateBondedTransactions', () => {
220-
it('should call aggregateBondedTransactions successfully', (done) => {
221-
accountRepository.getAccountPartialTransactions(publicAccount.address).subscribe(() => {
222-
done();
223-
}, (error) => {
224-
console.log('Error:', error);
225-
assert(false);
226-
});
208+
it('should call aggregateBondedTransactions successfully', async () => {
209+
await accountRepository.getAccountPartialTransactions(publicAccount.address).toPromise();
227210
});
228211
});
229212

@@ -243,7 +226,6 @@ describe('AccountHttp', () => {
243226
describe('transactions', () => {
244227
it('should call transactions successfully by type', async () => {
245228
const transactions = await accountRepository.getAccountTransactions(publicAccount.address, {transactionType: TransactionType.TRANSFER} as QueryParams).toPromise();
246-
247229
expect(transactions.length).to.be.greaterThan(0);
248230
transactions.forEach((t) => {
249231
expect(t.type).to.be.eq(TransactionType.TRANSFER);
@@ -252,29 +234,23 @@ describe('AccountHttp', () => {
252234
});
253235

254236
describe('transactions', () => {
255-
it('should call transactions successfully', (done) => {
256-
accountRepository.getAccountTransactions(publicAccount.address).subscribe((transactions) => {
257-
expect(transactions.length).to.be.greaterThan(0);
258-
done();
259-
});
237+
it('should call transactions successfully', async () => {
238+
const transactions = await accountRepository.getAccountTransactions(publicAccount.address).toPromise();
239+
expect(transactions.length).to.be.greaterThan(0);
260240
});
261241
});
262242

263243
describe('unconfirmedTransactions', () => {
264-
it('should call unconfirmedTransactions successfully', (done) => {
265-
accountRepository.getAccountUnconfirmedTransactions(publicAccount.address).subscribe((transactions) => {
266-
expect(transactions.length).to.be.equal(0);
267-
done();
268-
});
244+
it('should call unconfirmedTransactions successfully', async () => {
245+
const transactions = await accountRepository.getAccountUnconfirmedTransactions(publicAccount.address).toPromise();
246+
expect(transactions.length).to.be.equal(0);
269247
});
270248
});
271249

272250
describe('getAddressNames', () => {
273-
it('should call getAddressNames successfully', (done) => {
274-
namespaceRepository.getAccountsNames([accountAddress]).subscribe((addressNames) => {
275-
expect(addressNames.length).to.be.greaterThan(0);
276-
done();
277-
});
251+
it('should call getAddressNames successfully', async () => {
252+
const addressNames = await namespaceRepository.getAccountsNames([accountAddress]).toPromise();
253+
expect(addressNames.length).to.be.greaterThan(0);
278254
});
279255
});
280256

e2e/infrastructure/BlockHttp.spec.ts

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMos
2727
import { Deadline } from '../../src/model/transaction/Deadline';
2828
import { TransactionInfo } from '../../src/model/transaction/TransactionInfo';
2929
import { TransferTransaction } from '../../src/model/transaction/TransferTransaction';
30-
import { IntegrationTestHelper } from './IntegrationTestHelper';
3130
import { UInt64 } from '../../src/model/UInt64';
31+
import { IntegrationTestHelper } from './IntegrationTestHelper';
3232

3333
describe('BlockHttp', () => {
3434
const helper = new IntegrationTestHelper();
@@ -69,7 +69,7 @@ describe('BlockHttp', () => {
6969

7070
describe('Setup Test Data', () => {
7171

72-
it('Announce TransferTransaction', (done) => {
72+
it('Announce TransferTransaction', () => {
7373
const transferTransaction = TransferTransaction.create(
7474
Deadline.create(),
7575
account2.address,
@@ -79,99 +79,79 @@ describe('BlockHttp', () => {
7979
helper.maxFee,
8080
);
8181
const signedTransaction = transferTransaction.signWith(account, generationHash);
82-
helper.announce(signedTransaction).then((transaction) => {
82+
return helper.announce(signedTransaction).then((transaction) => {
8383
chainHeight = transaction.transactionInfo!.height.toString();
84-
done();
84+
return chainHeight;
8585
});
8686
});
8787
});
8888

8989
describe('getBlockByHeight', () => {
90-
it('should return block info given height', (done) => {
91-
blockRepository.getBlockByHeight(UInt64.fromUint(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-
});
90+
it('should return block info given height', async () => {
91+
const blockInfo = await blockRepository.getBlockByHeight(UInt64.fromUint(1)).toPromise();
92+
blockReceiptHash = blockInfo.blockReceiptsHash;
93+
blockTransactionHash = blockInfo.blockTransactionsHash;
94+
expect(blockInfo.height.lower).to.be.equal(1);
95+
expect(blockInfo.height.higher).to.be.equal(0);
96+
expect(blockInfo.timestamp.lower).to.be.equal(0);
97+
expect(blockInfo.timestamp.higher).to.be.equal(0);
98+
10199
});
102100
});
103101

104102
describe('getBlockTransactions', () => {
105103
let nextId: string;
106104
let firstId: string;
107105

108-
it('should return block transactions data given height', (done) => {
109-
blockRepository.getBlockTransactions(UInt64.fromUint(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-
});
106+
it('should return block transactions data given height', async () => {
107+
const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1)).toPromise();
108+
nextId = transactions[0].transactionInfo!.id;
109+
firstId = transactions[1].transactionInfo!.id;
110+
expect(transactions.length).to.be.greaterThan(0);
116111
});
117112

118-
it('should return block transactions data given height with paginated transactionId', (done) => {
119-
blockRepository.getBlockTransactions(UInt64.fromUint(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-
});
113+
it('should return block transactions data given height with paginated transactionId', async () => {
114+
const transactions = await blockRepository.getBlockTransactions(UInt64.fromUint(1), new QueryParams(10, nextId)).toPromise();
115+
expect(transactions[0].transactionInfo!.id).to.be.equal(firstId);
116+
expect(transactions.length).to.be.greaterThan(0);
125117
});
126118
});
127119

128120
describe('getBlocksByHeightWithLimit', () => {
129-
it('should return block info given height and limit', (done) => {
130-
blockRepository.getBlocksByHeightWithLimit(chainHeight, 50)
131-
.subscribe((blocksInfo) => {
132-
expect(blocksInfo.length).to.be.greaterThan(0);
133-
done();
134-
});
121+
it('should return block info given height and limit', async () => {
122+
const blocksInfo = await blockRepository.getBlocksByHeightWithLimit(chainHeight, 50).toPromise();
123+
expect(blocksInfo.length).to.be.greaterThan(0);
135124
});
136125
});
137126
describe('getMerkleReceipts', () => {
138-
it('should return Merkle Receipts', (done) => {
139-
receiptRepository.getBlockReceipts(chainHeight).pipe(
127+
it('should return Merkle Receipts', async () => {
128+
const merkleReceipts = await receiptRepository.getBlockReceipts(chainHeight).pipe(
140129
mergeMap((_) => {
141130
return receiptRepository.getMerkleReceipts(chainHeight, _.transactionStatements[0].generateHash());
142-
}))
143-
.subscribe((merkleReceipts) => {
144-
expect(merkleReceipts.merklePath).not.to.be.null;
145-
done();
146-
});
131+
})).toPromise();
132+
expect(merkleReceipts.merklePath).not.to.be.null;
147133
});
148134
});
149135
describe('getMerkleTransaction', () => {
150-
it('should return Merkle Transaction', (done) => {
151-
blockRepository.getBlockTransactions(chainHeight).pipe(
136+
it('should return Merkle Transaction', async () => {
137+
const merkleTransactionss = await blockRepository.getBlockTransactions(chainHeight).pipe(
152138
mergeMap((_) => {
153139
const hash = (_[0].transactionInfo as TransactionInfo).hash;
154140
if (hash) {
155141
return blockRepository.getMerkleTransaction(chainHeight, hash);
156142
}
157143
// If reaching this line, something is not right
158144
throw new Error('Tansacation hash is undefined');
159-
}))
160-
.subscribe((merkleTransactionss) => {
161-
expect(merkleTransactionss.merklePath).not.to.be.null;
162-
done();
163-
});
145+
})).toPromise();
146+
expect(merkleTransactionss.merklePath).not.to.be.null;
164147
});
165148
});
166149

167150
describe('getBlockReceipts', () => {
168-
it('should return block receipts', (done) => {
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-
});
151+
it('should return block receipts', async () => {
152+
const statement = await receiptRepository.getBlockReceipts(chainHeight).toPromise();
153+
expect(statement.transactionStatements).not.to.be.null;
154+
expect(statement.transactionStatements.length).to.be.greaterThan(0);
175155
});
176156
});
177157
});

e2e/infrastructure/ChainHttp.spec.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,18 @@ describe('ChainHttp', () => {
2929
});
3030

3131
describe('getBlockchainHeight', () => {
32-
it('should return blockchain height', (done) => {
33-
chainRepository.getBlockchainHeight()
34-
.subscribe((height) => {
35-
expect(height.lower).to.be.greaterThan(0);
36-
done();
37-
});
32+
it('should return blockchain height', async () => {
33+
const height = await chainRepository.getBlockchainHeight().toPromise();
34+
expect(height.lower).to.be.greaterThan(0);
3835
});
3936
});
4037

4138
describe('getBlockchainScore', () => {
42-
it('should return blockchain score', (done) => {
43-
chainRepository.getChainScore()
44-
.subscribe((blockchainScore) => {
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);
48-
done();
49-
});
39+
it('should return blockchain score', async () => {
40+
const blockchainScore = await chainRepository.getChainScore().toPromise();
41+
expect(blockchainScore.scoreLow).to.not.be.equal(undefined);
42+
expect(blockchainScore.scoreHigh.lower).to.be.equal(0);
43+
expect(blockchainScore.scoreHigh.higher).to.be.equal(0);
5044
});
5145
});
5246
});

e2e/infrastructure/DiagnosticHttp.spec.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,19 @@ describe('DiagnosticHttp', () => {
2929
});
3030

3131
describe('getDiagnosticStorage', () => {
32-
it('should return diagnostic storage', (done) => {
33-
diagnosticRepository.getDiagnosticStorage()
34-
.subscribe((blockchainStorageInfo) => {
35-
expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0);
36-
expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0);
37-
expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0);
38-
done();
39-
});
32+
it('should return diagnostic storage', async () => {
33+
const blockchainStorageInfo = await diagnosticRepository.getDiagnosticStorage().toPromise();
34+
expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0);
35+
expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0);
36+
expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0);
4037
});
4138
});
4239

4340
describe('getServerInfo', () => {
44-
it('should return diagnostic storage', (done) => {
45-
diagnosticRepository.getServerInfo()
46-
.subscribe((serverInfo) => {
47-
expect(serverInfo.restVersion).not.to.be.null;
48-
expect(serverInfo.sdkVersion).not.to.be.null;
49-
done();
50-
});
41+
it('should return diagnostic storage', async () => {
42+
const serverInfo = await diagnosticRepository.getServerInfo().toPromise();
43+
expect(serverInfo.restVersion).not.to.be.null;
44+
expect(serverInfo.sdkVersion).not.to.be.null;
5145
});
5246
});
5347
});

e2e/infrastructure/IntegrationTestHelper.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ export class IntegrationTestHelper {
7373
// What would be the best maxFee? In the future we will load the fee multiplier from rest.
7474
this.maxFee = UInt64.fromUint(1000000);
7575

76-
require('fs').readFile(path.resolve(__dirname,
77-
'../../../catapult-service-bootstrap/build/generated-addresses/addresses.yaml'),
78-
(error: any, yamlData: any) => {
76+
const bootstrapRoot = process.env.CATAPULT_SERVICE_BOOTSTRAP || path.resolve(__dirname, '../../../../catapult-service-bootstrap');
77+
const bootstrapPath = `${bootstrapRoot}/build/generated-addresses/addresses.yaml`;
78+
require('fs').readFile(bootstrapPath, (error: any, yamlData: any) => {
7979
if (error) {
80-
console.log(`catapult-service-bootstrap generated address could not be loaded. Ignoring and using accounts from network.conf.`);
80+
console.log(`catapult-service-bootstrap generated address could not be loaded from path ${bootstrapPath}. Ignoring and using accounts from network.conf.`);
8181
return resolve(this);
8282
} else {
83+
console.log(`catapult-service-bootstrap generated address loaded from path ${bootstrapPath}.`);
8384
const parsedYaml = this.yaml.safeLoad(yamlData);
8485
this.account = this.createAccount(parsedYaml.nemesis_addresses[0]);
8586
this.account2 = this.createAccount(parsedYaml.nemesis_addresses[1]);

0 commit comments

Comments
 (0)