Skip to content

Commit 9eff7cb

Browse files
committed
Migrated listener and services integration tests to use the new helper
1 parent bf0f178 commit 9eff7cb

10 files changed

+572
-943
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/IntegrationTestHelper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class IntegrationTestHelper {
3737
public cosignAccount1: Account;
3838
public cosignAccount2: Account;
3939
public cosignAccount3: Account;
40+
public cosignAccount4: Account;
4041
public networkType: NetworkType;
4142
public generationHash: string;
4243
public listener: Listener;
@@ -67,6 +68,7 @@ export class IntegrationTestHelper {
6768
this.cosignAccount1 = this.createAccount(json.cosignatoryAccount);
6869
this.cosignAccount2 = this.createAccount(json.cosignatory2Account);
6970
this.cosignAccount3 = this.createAccount(json.cosignatory3Account);
71+
this.cosignAccount4 = this.createAccount(json.cosignatory4Account);
7072
this.harvestingAccount = this.createAccount(json.harvestingAccount);
7173

7274
this.maxFee = UInt64.fromUint(1000000); //What would be the best maxFee? In the future we will load the fee multiplier from rest.
@@ -83,6 +85,7 @@ export class IntegrationTestHelper {
8385
this.account3 = this.createAccount(parsedYaml.nemesis_addresses[2]);
8486
this.multisigAccount = this.createAccount(parsedYaml.nemesis_addresses[3]);
8587
this.cosignAccount1 = this.createAccount(parsedYaml.nemesis_addresses[4]);
88+
this.cosignAccount4 = this.createAccount(parsedYaml.nemesis_addresses[5]);
8689
this.harvestingAccount = this.createAccount(parsedYaml.nemesis_addresses_harvesting[0]);
8790
return resolve(this);
8891
}

e2e/infrastructure/Listener.spec.ts

Lines changed: 83 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ import { TransactionRepository } from '../../src/infrastructure/TransactionRepos
2020
import { Account } from '../../src/model/account/Account';
2121
import { NetworkType } from '../../src/model/blockchain/NetworkType';
2222
import { PlainMessage } from '../../src/model/message/PlainMessage';
23-
import { Mosaic, UInt64 } from '../../src/model/model';
23+
import {
24+
Address,
25+
CosignatureTransaction,
26+
LockFundsTransaction,
27+
Mosaic,
28+
SignedTransaction,
29+
UInt64
30+
} from '../../src/model/model';
2431
import { MosaicId } from '../../src/model/mosaic/MosaicId';
2532
import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic';
2633
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
2734
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction';
2835
import { Deadline } from '../../src/model/transaction/Deadline';
2936
import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction';
3037
import { TransferTransaction } from '../../src/model/transaction/TransferTransaction';
31-
import { TransactionUtils } from './TransactionUtils';
3238
import { IntegrationTestHelper } from "./IntegrationTestHelper";
3339
import { NamespaceRepository } from "../../src/infrastructure/NamespaceRepository";
3440
import { filter } from "rxjs/operators";
41+
import { ChronoUnit } from "js-joda";
3542

3643
describe('Listener', () => {
3744

@@ -75,6 +82,42 @@ describe('Listener', () => {
7582
// cold down
7683
setTimeout(done, 200);
7784
});
85+
86+
87+
let createSignedAggregatedBondTransaction = (aggregatedTo: Account,
88+
signer: Account,
89+
recipient: Address): SignedTransaction => {
90+
const transferTransaction = TransferTransaction.create(
91+
Deadline.create(),
92+
recipient,
93+
[],
94+
PlainMessage.create('test-message'),
95+
networkType, helper.maxFee
96+
);
97+
98+
const aggregateTransaction = AggregateTransaction.createBonded(
99+
Deadline.create(2, ChronoUnit.MINUTES),
100+
[transferTransaction.toAggregate(aggregatedTo.publicAccount)],
101+
networkType,
102+
[], helper.maxFee
103+
);
104+
return signer.sign(aggregateTransaction, generationHash);
105+
};
106+
107+
let createHashLockTransactionAndAnnounce = (signedAggregatedTransaction: SignedTransaction,
108+
signer: Account,
109+
mosaicId: MosaicId) => {
110+
const lockFundsTransaction = LockFundsTransaction.create(
111+
Deadline.create(),
112+
new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))),
113+
UInt64.fromUint(1000),
114+
signedAggregatedTransaction,
115+
networkType, helper.maxFee
116+
);
117+
const signedLockFundsTransaction = signer.sign(lockFundsTransaction, generationHash);
118+
transactionRepository.announce(signedLockFundsTransaction);
119+
};
120+
78121
describe('Confirmed', () => {
79122

80123
it('confirmedTransactionsGiven address signer', () => {
@@ -150,8 +193,6 @@ describe('Listener', () => {
150193
});
151194

152195
describe('TransferTransaction', () => {
153-
154-
155196
it('standalone', () => {
156197
const transferTransaction = TransferTransaction.create(
157198
Deadline.create(),
@@ -200,18 +241,16 @@ describe('Listener', () => {
200241
done();
201242
});
202243
helper.listener.confirmed(account.address).subscribe(() => {
203-
TransactionUtils.announceAggregateBoundedTransaction(signedAggregatedTx, transactionRepository);
244+
transactionRepository.announceAggregateBonded(signedAggregatedTx)
204245
});
205246
helper.listener.status(account.address).subscribe((error) => {
206247
console.log('Error:', error);
207248
assert(false);
208249
done();
209250
});
210-
const signedAggregatedTx = TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, account,
211-
account2.address, generationHash);
251+
const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address);
212252

213-
TransactionUtils.createHashLockTransactionAndAnnounce(signedAggregatedTx, account, networkCurrencyMosaicId,
214-
transactionRepository, generationHash);
253+
createHashLockTransactionAndAnnounce(signedAggregatedTx, account, networkCurrencyMosaicId);
215254
});
216255
});
217256
describe('Aggregate Bonded Transactions', () => {
@@ -223,26 +262,28 @@ describe('Listener', () => {
223262
helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => {
224263
accountRepository.getAccountPartialTransactions(cosignAccount1.publicAccount.address).subscribe((transactions) => {
225264
const transactionToCosign = transactions[0];
226-
TransactionUtils.cosignTransaction(transactionToCosign, cosignAccount2, transactionRepository);
265+
const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign);
266+
const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction);
267+
transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction);
268+
227269
});
228270
});
229271
helper.listener.status(cosignAccount1.address).subscribe((error) => {
230272
console.log('Error:', error);
231273
assert(false);
232274
done();
233275
});
234-
TransactionUtils.announceAggregateBoundedTransaction(signedAggregatedTx, transactionRepository);
276+
transactionRepository.announceAggregateBonded(signedAggregatedTx)
235277
});
236278
helper.listener.status(cosignAccount1.address).subscribe((error) => {
237279
console.log('Error:', error);
238280
assert(false);
239281
done();
240282
});
241283
const signedAggregatedTx =
242-
TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address, generationHash);
284+
createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address);
243285

244-
TransactionUtils.createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1,
245-
networkCurrencyMosaicId, transactionRepository, generationHash);
286+
createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId);
246287
});
247288
});
248289

@@ -255,22 +296,23 @@ describe('Listener', () => {
255296
helper.listener.aggregateBondedAdded(cosignAccount1.address).subscribe(() => {
256297
accountRepository.getAccountPartialTransactions(cosignAccount1.publicAccount.address).subscribe((transactions) => {
257298
const transactionToCosign = transactions[0];
258-
TransactionUtils.cosignTransaction(transactionToCosign, cosignAccount2, transactionRepository);
299+
const cosignatureTransaction = CosignatureTransaction.create(transactionToCosign);
300+
const cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction);
301+
transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction);
259302
});
260303
});
261304
helper.listener.confirmed(cosignAccount1.address).subscribe(() => {
262-
TransactionUtils.announceAggregateBoundedTransaction(signedAggregatedTx, transactionRepository);
305+
transactionRepository.announceAggregateBonded(signedAggregatedTx)
263306
});
264307
helper.listener.status(cosignAccount1.address).subscribe((error) => {
265308
console.log('Error:', error);
266309
assert(false);
267310
done();
268311
});
269312
const signedAggregatedTx =
270-
TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address, generationHash);
313+
createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.address);
271314

272-
TransactionUtils.createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1,
273-
networkCurrencyMosaicId, transactionRepository, generationHash);
315+
createHashLockTransactionAndAnnounce(signedAggregatedTx, cosignAccount1, networkCurrencyMosaicId);
274316
});
275317
});
276318

@@ -317,13 +359,21 @@ describe('Listener', () => {
317359

318360
describe('Transactions Status', () => {
319361

320-
it('transactionStatusGiven', (done) => {
321-
helper.listener.status(account.address).subscribe((error) => {
362+
it('transactionStatusGiven', () => {
363+
const mosaics = [NetworkCurrencyMosaic.createRelative(1000000000000)];
364+
const transferTransaction = TransferTransaction.create(
365+
Deadline.create(),
366+
account2.address,
367+
mosaics,
368+
PlainMessage.create('test-message'),
369+
networkType, helper.maxFee
370+
);
371+
372+
return helper.announce(transferTransaction.signWith(account, generationHash)).then(() => {
373+
throw new Error("Transaction should have failed!!");
374+
}, error => {
322375
expect(error.status).to.be.equal('Failure_Core_Insufficient_Balance');
323-
done();
324376
});
325-
const mosaics = [NetworkCurrencyMosaic.createRelative(1000000000000)];
326-
TransactionUtils.createAndAnnounce(account, account2.address, transactionRepository, mosaics, generationHash);
327377
});
328378
});
329379

@@ -333,7 +383,15 @@ describe('Listener', () => {
333383
helper.listener.newBlock().subscribe(() => {
334384
done();
335385
});
336-
TransactionUtils.createAndAnnounce(account, account.address, transactionRepository, undefined, generationHash);
386+
const transferTransaction = TransferTransaction.create(
387+
Deadline.create(),
388+
account2.address,
389+
[],
390+
PlainMessage.create('test-message'),
391+
networkType, helper.maxFee
392+
);
393+
394+
helper.announce(transferTransaction.signWith(account, generationHash));
337395
});
338396
});
339397
});

e2e/infrastructure/TransactionUtils.ts

Lines changed: 0 additions & 118 deletions
This file was deleted.

e2e/infrastructure/UnresolvedMapping.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ import { TransferTransaction } from '../../src/model/transaction/TransferTransac
4040
import { UInt64 } from '../../src/model/UInt64';
4141
import { IntegrationTestHelper } from "./IntegrationTestHelper";
4242
import { Address } from "../../src/model/account/Address";
43-
import { PublicAccount } from "../../src/model/account/PublicAccount";
44-
import { RepositoryFactory } from "../../src/infrastructure/RepositoryFactory";
45-
import { AccountRepository } from "../../src/infrastructure/AccountRepository";
46-
import { MultisigRepository } from "../../src/infrastructure/MultisigRepository";
4743
import { NamespaceRepository } from "../../src/infrastructure/NamespaceRepository";
48-
import { TransactionRepository } from "../../src/infrastructure/TransactionRepository";
4944

5045
describe('TransactionHttp', () => {
5146
let helper = new IntegrationTestHelper();

0 commit comments

Comments
 (0)