Skip to content

Commit 87eebe1

Browse files
authored
Added networkCurrency resolver for e2e tests (#529)
* Fixed #523 - Added networkCurrency resolver for e2e tests * trigger travis
1 parent 3c87571 commit 87eebe1

File tree

6 files changed

+49
-36
lines changed

6 files changed

+49
-36
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { Account } from '../../src/model/account/Account';
2424
import { Address } from '../../src/model/account/Address';
2525
import { PublicAccount } from '../../src/model/account/PublicAccount';
2626
import { PlainMessage } from '../../src/model/message/PlainMessage';
27-
import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal';
2827
import { AliasAction } from '../../src/model/namespace/AliasAction';
2928
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
3029
import { NetworkType } from '../../src/model/network/NetworkType';
@@ -93,7 +92,7 @@ describe('AccountHttp', () => {
9392
const transferTransaction = TransferTransaction.create(
9493
Deadline.create(),
9594
account2.address,
96-
[NetworkCurrencyLocal.createAbsolute(1)],
95+
[helper.createNetworkCurrency(1, false)],
9796
PlainMessage.create('test-message'),
9897
networkType,
9998
helper.maxFee,

e2e/infrastructure/BlockHttp.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717
import { expect } from 'chai';
1818
import { mergeMap } from 'rxjs/operators';
19-
import { BlockHttp } from '../../src/infrastructure/BlockHttp';
2019
import { BlockRepository } from '../../src/infrastructure/BlockRepository';
2120
import { QueryParams } from '../../src/infrastructure/QueryParams';
2221
import { ReceiptRepository } from '../../src/infrastructure/ReceiptRepository';
2322
import { Account } from '../../src/model/account/Account';
2423
import { PlainMessage } from '../../src/model/message/PlainMessage';
25-
import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal';
2624
import { NetworkType } from '../../src/model/network/NetworkType';
2725
import { Deadline } from '../../src/model/transaction/Deadline';
2826
import { TransactionInfo } from '../../src/model/transaction/TransactionInfo';
@@ -73,7 +71,7 @@ describe('BlockHttp', () => {
7371
const transferTransaction = TransferTransaction.create(
7472
Deadline.create(),
7573
account2.address,
76-
[NetworkCurrencyLocal.createAbsolute(1)],
74+
[helper.createNetworkCurrency(1, false)],
7775
PlainMessage.create('test-message'),
7876
networkType,
7977
helper.maxFee,

e2e/infrastructure/IntegrationTestHelper.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ import { SignedTransaction } from '../../src/model/transaction/SignedTransaction
2424
import { Transaction } from '../../src/model/transaction/Transaction';
2525
import { UInt64 } from '../../src/model/UInt64';
2626
import { TransactionService } from '../../src/service/TransactionService';
27+
import { NetworkHarvestLocal } from '../../src/model/mosaic/NetworkHarvestLocal';
28+
import { NetworkCurrencyPublic } from '../../src/model/mosaic/NetworkCurrencyPublic';
29+
import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal';
30+
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
2731

2832
export class IntegrationTestHelper {
2933
public readonly yaml = require('js-yaml');
@@ -43,6 +47,8 @@ export class IntegrationTestHelper {
4347
public maxFee: UInt64;
4448
public harvestingAccount: Account;
4549
public transactionService: TransactionService;
50+
public networkCurrencyNamespaceId: NamespaceId;
51+
public networkCurrencyDivisibility: number;
4652

4753
start(): Promise<IntegrationTestHelper> {
4854
return new Promise<IntegrationTestHelper>(
@@ -77,6 +83,12 @@ export class IntegrationTestHelper {
7783
// What would be the best maxFee? In the future we will load the fee multiplier from rest.
7884
this.maxFee = UInt64.fromUint(1000000);
7985

86+
// network Currency
87+
this.networkCurrencyNamespaceId = this.apiUrl.toLowerCase().includes('localhost') ?
88+
NetworkCurrencyLocal.NAMESPACE_ID : NetworkCurrencyPublic.NAMESPACE_ID;
89+
this.networkCurrencyDivisibility = this.apiUrl.toLowerCase().includes('localhost') ?
90+
NetworkCurrencyLocal.DIVISIBILITY : NetworkCurrencyPublic.DIVISIBILITY;
91+
8092
const bootstrapRoot = process.env.CATAPULT_SERVICE_BOOTSTRAP || path.resolve(__dirname, '../../../../catapult-service-bootstrap');
8193
const bootstrapPath = `${bootstrapRoot}/build/generated-addresses/addresses.yaml`;
8294
require('fs').readFile(bootstrapPath, (error: any, yamlData: any) => {
@@ -110,6 +122,13 @@ export class IntegrationTestHelper {
110122
return Account.createFromPrivateKey(data.privateKey ? data.privateKey : data.private, this.networkType);
111123
}
112124

125+
createNetworkCurrency(amount: number, isRelative: boolean = true): NetworkCurrencyPublic | NetworkCurrencyLocal {
126+
if (this.apiUrl.toLowerCase().includes('localhost')) {
127+
return isRelative ? NetworkCurrencyLocal.createRelative(amount) : NetworkCurrencyLocal.createAbsolute(amount);
128+
}
129+
return isRelative ? NetworkCurrencyPublic.createRelative(amount) : NetworkCurrencyPublic.createAbsolute(amount);
130+
}
131+
113132
announce(signedTransaction: SignedTransaction): Promise<Transaction> {
114133
console.log(`Announcing transaction: ${signedTransaction.type}`);
115134
return this.transactionService.announce(signedTransaction, this.listener).pipe(map((t) => {

e2e/infrastructure/Listener.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { Account } from '../../src/model/account/Account';
2323
import { PlainMessage } from '../../src/model/message/PlainMessage';
2424
import { Address, CosignatureTransaction, LockFundsTransaction, Mosaic, SignedTransaction, UInt64 } from '../../src/model/model';
2525
import { MosaicId } from '../../src/model/mosaic/MosaicId';
26-
import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal';
2726
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
2827
import { NetworkType } from '../../src/model/network/NetworkType';
2928
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction';
@@ -45,7 +44,7 @@ describe('Listener', () => {
4544
let namespaceRepository: NamespaceRepository;
4645
let generationHash: string;
4746
let networkType: NetworkType;
48-
const NetworkCurrencyLocalId: NamespaceId = NetworkCurrencyLocal.NAMESPACE_ID;
47+
const NetworkCurrencyLocalId: NamespaceId = helper.networkCurrencyNamespaceId;
4948
let transactionRepository: TransactionRepository;
5049

5150
before(() => {
@@ -100,7 +99,7 @@ describe('Listener', () => {
10099
mosaicId: MosaicId | NamespaceId) => {
101100
const lockFundsTransaction = LockFundsTransaction.create(
102101
Deadline.create(),
103-
new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY))),
102+
new Mosaic(mosaicId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility))),
104103
UInt64.fromUint(1000),
105104
signedAggregatedTransaction,
106105
networkType, helper.maxFee,
@@ -180,7 +179,7 @@ describe('Listener', () => {
180179
const transferTransaction = TransferTransaction.create(
181180
Deadline.create(),
182181
cosignAccount1.address,
183-
[new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyLocal.DIVISIBILITY)))],
182+
[new Mosaic(NetworkCurrencyLocalId, UInt64.fromUint(10 * Math.pow(10, helper.networkCurrencyDivisibility)))],
184183
PlainMessage.create('test-message'),
185184
networkType, helper.maxFee,
186185
);
@@ -341,7 +340,7 @@ describe('Listener', () => {
341340
describe('Transactions Status', () => {
342341

343342
it('transactionStatusGiven', () => {
344-
const mosaics = [NetworkCurrencyLocal.createRelative(1000000000000)];
343+
const mosaics = [helper.createNetworkCurrency(1000000000000)];
345344
const transferTransaction = TransferTransaction.create(
346345
Deadline.create(),
347346
account2.address,

e2e/infrastructure/NamespaceHttp.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { expect } from 'chai';
1818
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository';
1919
import { Account } from '../../src/model/account/Account';
2020
import { Address } from '../../src/model/account/Address';
21-
import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal';
2221
import { AliasAction } from '../../src/model/namespace/AliasAction';
2322
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
2423
import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction';
@@ -28,7 +27,7 @@ import { UInt64 } from '../../src/model/UInt64';
2827
import { IntegrationTestHelper } from './IntegrationTestHelper';
2928

3029
describe('NamespaceHttp', () => {
31-
const defaultNamespaceId = NetworkCurrencyLocal.NAMESPACE_ID;
30+
let defaultNamespaceId: NamespaceId;
3231
let namespaceId: NamespaceId;
3332
let namespaceRepository: NamespaceRepository;
3433
let account: Account;
@@ -40,6 +39,7 @@ describe('NamespaceHttp', () => {
4039
account = helper.account;
4140
generationHash = helper.generationHash;
4241
namespaceRepository = helper.repositoryFactory.createNamespaceRepository();
42+
defaultNamespaceId = helper.networkCurrencyNamespaceId;
4343
});
4444
});
4545

0 commit comments

Comments
 (0)