Skip to content

Commit 2567479

Browse files
committed
Added more e2e tests
1 parent b218d25 commit 2567479

File tree

2 files changed

+123
-41
lines changed

2 files changed

+123
-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: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { MosaicMetadataTransaction } from '../model/transaction/MosaicMetadataTr
3030
import { MosaicSupplyChangeTransaction } from '../model/transaction/MosaicSupplyChangeTransaction';
3131
import { SecretLockTransaction } from '../model/transaction/SecretLockTransaction';
3232
import { SecretProofTransaction } from '../model/transaction/SecretProofTransaction';
33+
import { SignedTransaction } from '../model/transaction/SignedTransaction';
3334
import { Transaction } from '../model/transaction/Transaction';
3435
import { TransactionType } from '../model/transaction/TransactionType';
3536
import { TransferTransaction } from '../model/transaction/TransferTransaction';
@@ -65,6 +66,46 @@ export class TransactionService implements ITransactionService {
6566
);
6667
}
6768

69+
/**
70+
* @param signedTransaction Signed transaction to be announced.
71+
* @param listener Websocket listener
72+
* @returns {Observable<Transaction>}
73+
*/
74+
public announce(signedTransaction: SignedTransaction, listener: Listener): Observable<Transaction> {
75+
return this.transactionHttp.announce(signedTransaction).pipe(
76+
flatMap(() => listener.confirmed(signedTransaction.getSignerAddress(), signedTransaction.hash)),
77+
);
78+
}
79+
80+
/**
81+
* Announce aggregate transaction
82+
* **NOTE** A lock fund transaction for this aggregate bonded should exists
83+
* @param signedTransaction Signed aggregate bonded transaction.
84+
* @param listener Websocket listener
85+
* @returns {Observable<AggregateTransaction>}
86+
*/
87+
public announceAggregateBonded(signedTransaction: SignedTransaction, listener: Listener): Observable<AggregateTransaction> {
88+
return this.transactionHttp.announceAggregateBonded(signedTransaction).pipe(
89+
flatMap(() => listener.aggregateBondedAdded(signedTransaction.getSignerAddress(), signedTransaction.hash)),
90+
);
91+
}
92+
93+
/**
94+
* Announce aggregate bonded transaction with lock fund
95+
* @param signedHashLockTransaction Signed hash lock transaction.
96+
* @param signedAggregateTransaction Signed aggregate bonded transaction.
97+
* @param listener Websocket listener
98+
* @returns {Observable<AggregateTransaction>}
99+
*/
100+
public announceHashLockAggregateBonded(signedHashLockTransaction: SignedTransaction,
101+
signedAggregateTransaction: SignedTransaction,
102+
listener: Listener): Observable<AggregateTransaction> {
103+
return this.announce(signedHashLockTransaction, listener).pipe(
104+
flatMap(() => this.announceAggregateBonded(signedAggregateTransaction, listener)),
105+
);
106+
107+
}
108+
68109
/**
69110
* Resolve transaction alias(s)
70111
* @param transaction Transaction to be resolved
@@ -147,43 +188,4 @@ export class TransactionService implements ITransactionService {
147188
map((statement) => transaction.resolveAliases(statement, aggregateIndex)),
148189
);
149190
}
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-
}
189191
}

0 commit comments

Comments
 (0)