Skip to content

Commit 98d0e79

Browse files
committed
Added more e2e tests
1 parent fc2dc92 commit 98d0e79

File tree

2 files changed

+122
-41
lines changed

2 files changed

+122
-41
lines changed

e2e/service/TransactionService_AggregateBonded.spec.ts

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,25 @@
1616

1717
import { expect } from 'chai';
1818
import { Listener } from '../../src/infrastructure/Listener';
19+
import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp';
1920
import { TransactionHttp } from '../../src/infrastructure/TransactionHttp';
2021
import { Account } from '../../src/model/account/Account';
2122
import { Address } from '../../src/model/account/Address';
2223
import { NetworkType } from '../../src/model/blockchain/NetworkType';
2324
import { PlainMessage } from '../../src/model/message/PlainMessage';
25+
import { Mosaic } from '../../src/model/mosaic/Mosaic';
26+
import { MosaicId } from '../../src/model/mosaic/MosaicId';
2427
import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic';
28+
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
2529
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction';
2630
import { Deadline } from '../../src/model/transaction/Deadline';
31+
import { LockFundsTransaction } from '../../src/model/transaction/LockFundsTransaction';
2732
import { MultisigAccountModificationTransaction } from '../../src/model/transaction/MultisigAccountModificationTransaction';
33+
import { TransactionType } from '../../src/model/transaction/TransactionType';
2834
import { TransferTransaction } from '../../src/model/transaction/TransferTransaction';
35+
import { UInt64 } from '../../src/model/UInt64';
2936
import { TransactionService } from '../../src/service/TransactionService';
37+
import { TransactionUtils } from '../infrastructure/TransactionUtils';
3038

3139
describe('TransactionService', () => {
3240
let account: Account;
@@ -35,9 +43,12 @@ describe('TransactionService', () => {
3543
let cosignAccount1: Account;
3644
let cosignAccount2: Account;
3745
let cosignAccount3: Account;
46+
let networkCurrencyMosaicId: MosaicId;
3847
let url: string;
3948
let generationHash: string;
4049
let transactionHttp: TransactionHttp;
50+
let transactionService: TransactionService;
51+
let namespaceHttp: NamespaceHttp;
4152
let config;
4253

4354
before((done) => {
@@ -56,7 +67,9 @@ describe('TransactionService', () => {
5667
cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST);
5768
url = json.apiUrl;
5869
generationHash = json.generationHash;
59-
transactionHttp = new TransactionHttp(json.apiUrl);
70+
transactionHttp = new TransactionHttp(url);
71+
namespaceHttp = new NamespaceHttp(url);
72+
transactionService = new TransactionService(url);
6073
done();
6174
});
6275
});
@@ -66,6 +79,15 @@ describe('TransactionService', () => {
6679
* Setup test data
6780
* =========================
6881
*/
82+
describe('Get network currency mosaic id', () => {
83+
it('get mosaicId', (done) => {
84+
namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId) => {
85+
networkCurrencyMosaicId = networkMosaicId;
86+
done();
87+
});
88+
});
89+
});
90+
6991
describe('Setup test multisig account', () => {
7092
let listener: Listener;
7193
before (() => {
@@ -123,7 +145,6 @@ describe('TransactionService', () => {
123145
return listener.close();
124146
});
125147
it('announce', (done) => {
126-
const transactionService = new TransactionService(url);
127148
const transferTransaction = TransferTransaction.create(
128149
Deadline.create(),
129150
account2.address,
@@ -143,6 +164,65 @@ describe('TransactionService', () => {
143164
});
144165
});
145166

167+
describe('should announce aggregate bonded with hashlock', () => {
168+
let listener: Listener;
169+
before (() => {
170+
listener = new Listener(config.apiUrl);
171+
return listener.open();
172+
});
173+
after(() => {
174+
return listener.close();
175+
});
176+
it('announce', (done) => {
177+
const signedAggregatedTransaction =
178+
TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, account, account2.address, generationHash);
179+
const lockFundsTransaction = LockFundsTransaction.create(
180+
Deadline.create(),
181+
new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))),
182+
UInt64.fromUint(1000),
183+
signedAggregatedTransaction,
184+
NetworkType.MIJIN_TEST,
185+
);
186+
const signedLockFundsTransaction = lockFundsTransaction.signWith(account, generationHash);
187+
transactionService
188+
.announceHashLockAggregateBonded(signedLockFundsTransaction, signedAggregatedTransaction, listener).subscribe((tx) => {
189+
expect(tx.signer!.publicKey).to.be.equal(account.publicKey);
190+
expect(tx.type).to.be.equal(TransactionType.AGGREGATE_BONDED);
191+
done();
192+
});
193+
});
194+
});
195+
196+
describe('should announce aggregate bonded transaction', () => {
197+
let listener: Listener;
198+
before (() => {
199+
listener = new Listener(config.apiUrl);
200+
return listener.open();
201+
});
202+
after(() => {
203+
return listener.close();
204+
});
205+
it('announce', (done) => {
206+
const signedAggregatedTransaction =
207+
TransactionUtils.createSignedAggregatedBondTransaction(multisigAccount, account, account2.address, generationHash);
208+
const lockFundsTransaction = LockFundsTransaction.create(
209+
Deadline.create(),
210+
new Mosaic(networkCurrencyMosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))),
211+
UInt64.fromUint(1000),
212+
signedAggregatedTransaction,
213+
NetworkType.MIJIN_TEST,
214+
);
215+
const signedLockFundsTransaction = lockFundsTransaction.signWith(account, generationHash);
216+
transactionService.announce(signedLockFundsTransaction, listener).subscribe(() => {
217+
transactionService.announceAggregateBonded(signedAggregatedTransaction, listener).subscribe((tx) => {
218+
expect(tx.signer!.publicKey).to.be.equal(account.publicKey);
219+
expect(tx.type).to.be.equal(TransactionType.AGGREGATE_BONDED);
220+
done();
221+
});
222+
});
223+
});
224+
});
225+
146226
/**
147227
* =========================
148228
* House Keeping

src/service/TransactionService.ts

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,46 @@ export class TransactionService implements ITransactionService {
6565
);
6666
}
6767

68+
/**
69+
* @param signedTransaction Signed transaction to be announced.
70+
* @param listener Websocket listener
71+
* @returns {Observable<Transaction>}
72+
*/
73+
public announce(signedTransaction: SignedTransaction, listener: Listener): Observable<Transaction> {
74+
return this.transactionHttp.announce(signedTransaction).pipe(
75+
flatMap(() => listener.confirmed(signedTransaction.getSignerAddress(), signedTransaction.hash)),
76+
);
77+
}
78+
79+
/**
80+
* Announce aggregate transaction
81+
* **NOTE** A lock fund transaction for this aggregate bonded should exists
82+
* @param signedTransaction Signed aggregate bonded transaction.
83+
* @param listener Websocket listener
84+
* @returns {Observable<AggregateTransaction>}
85+
*/
86+
public announceAggregateBonded(signedTransaction: SignedTransaction, listener: Listener): Observable<AggregateTransaction> {
87+
return this.transactionHttp.announceAggregateBonded(signedTransaction).pipe(
88+
flatMap(() => listener.aggregateBondedAdded(signedTransaction.getSignerAddress(), signedTransaction.hash)),
89+
);
90+
}
91+
92+
/**
93+
* Announce aggregate bonded transaction with lock fund
94+
* @param signedHashLockTransaction Signed hash lock transaction.
95+
* @param signedAggregateTransaction Signed aggregate bonded transaction.
96+
* @param listener Websocket listener
97+
* @returns {Observable<AggregateTransaction>}
98+
*/
99+
public announceHashLockAggregateBonded(signedHashLockTransaction: SignedTransaction,
100+
signedAggregateTransaction: SignedTransaction,
101+
listener: Listener): Observable<AggregateTransaction> {
102+
return this.announce(signedHashLockTransaction, listener).pipe(
103+
flatMap(() => this.announceAggregateBonded(signedAggregateTransaction, listener)),
104+
);
105+
106+
}
107+
68108
/**
69109
* Resolve transaction alias(s)
70110
* @param transaction Transaction to be resolved
@@ -147,43 +187,4 @@ export class TransactionService implements ITransactionService {
147187
map((statement) => transaction.resolveAliases(statement, aggregateIndex)),
148188
);
149189
}
150-
151-
/**
152-
* @param signedTransaction Signed transaction to be announced.
153-
* @param listener Websocket listener
154-
* @returns {Observable<Transaction>}
155-
*/
156-
public announce(signedTransaction: SignedTransaction, listener: Listener): Observable<Transaction> {
157-
return this.transactionHttp.announce(signedTransaction).pipe(
158-
flatMap(() => listener.confirmed(signedTransaction.getSignerAddress(), signedTransaction.hash)),
159-
);
160-
}
161-
162-
/**
163-
* Announce aggregate transaction
164-
* @param signedTransaction Signed aggregate bonded transaction.
165-
* @param listener Websocket listener
166-
* @returns {Observable<AggregateTransaction>}
167-
*/
168-
public announceAggregateBonded(signedTransaction: SignedTransaction, listener: Listener): Observable<AggregateTransaction> {
169-
return this.transactionHttp.announceAggregateBonded(signedTransaction).pipe(
170-
flatMap(() => listener.aggregateBondedAdded(signedTransaction.getSignerAddress(), signedTransaction.hash)),
171-
);
172-
}
173-
174-
/**
175-
* Announce aggregate bonded transaction with lock fund
176-
* @param signedHashLockTransaction Signed hash lock transaction.
177-
* @param signedAggregateTransaction Signed aggregate bonded transaction.
178-
* @param listener Websocket listener
179-
* @returns {Observable<AggregateTransaction>}
180-
*/
181-
public announceHashLockAggregateBonded(signedHashLockTransaction: SignedTransaction,
182-
signedAggregateTransaction: SignedTransaction,
183-
listener: Listener): Observable<AggregateTransaction> {
184-
return this.announce(signedHashLockTransaction, listener).pipe(
185-
flatMap(() => this.announceAggregateBonded(signedAggregateTransaction, listener)),
186-
);
187-
188-
}
189190
}

0 commit comments

Comments
 (0)