Skip to content

Commit 40ffa0d

Browse files
committed
Added tests
1 parent 28c7d5c commit 40ffa0d

File tree

7 files changed

+177
-18
lines changed

7 files changed

+177
-18
lines changed

e2e/infrastructure/NetworkHttp.spec.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,30 @@ describe('NetworkHttp', () => {
4545
});
4646
});
4747

48-
describe('getNetworkFees', () => {
49-
it('should return network fees', async () => {
48+
describe('getTransactionFees', () => {
49+
it('should return transaction fees', async () => {
5050
const fees = await networkRepository.getTransactionFees().toPromise();
5151
expect(fees.averageFeeMultiplier).to.be.not.null;
5252
expect(fees.highestFeeMultiplier).to.be.not.null;
5353
expect(fees.lowestFeeMultiplier).to.be.not.null;
5454
expect(fees.medianFeeMultiplier).to.be.not.null;
5555
});
5656
});
57+
describe('getRentalFees', () => {
58+
it('should return rental fees', async () => {
59+
const fees = await networkRepository.getRentalFees().toPromise();
60+
expect(fees.effectiveChildNamespaceRentalFee).to.be.not.null;
61+
expect(fees.effectiveMosaicRentalFee).to.be.not.null;
62+
expect(fees.effectiveRootNamespaceRentalFeePerBlock).to.be.not.null;
63+
});
64+
});
65+
66+
describe('getNetworkProperties', () => {
67+
it('should return network configuration', async () => {
68+
const config = await networkRepository.getNetworkProperties().toPromise();
69+
expect(config.network).to.be.not.null;
70+
expect(config.chain).to.be.not.null;
71+
expect(config.plugins).to.be.not.null;
72+
});
73+
});
5774
});

src/model/transaction/AccountAddressRestrictionTransaction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export class AccountAddressRestrictionTransaction extends Transaction {
5555
*/
5656
public static create(deadline: Deadline,
5757
restrictionFlags: AccountRestrictionFlags,
58-
restrictionAdditions: Array<Address | NamespaceId>,
59-
restrictionDeletions: Array<Address | NamespaceId>,
58+
restrictionAdditions: (Address | NamespaceId)[],
59+
restrictionDeletions: (Address | NamespaceId)[],
6060
networkType: NetworkType,
6161
maxFee: UInt64 = new UInt64([0, 0])): AccountAddressRestrictionTransaction {
6262
return new AccountAddressRestrictionTransaction(networkType,
@@ -85,8 +85,8 @@ export class AccountAddressRestrictionTransaction extends Transaction {
8585
deadline: Deadline,
8686
maxFee: UInt64,
8787
public readonly restrictionFlags: AccountRestrictionFlags,
88-
public readonly restrictionAdditions: Array<Address | NamespaceId>,
89-
public readonly restrictionDeletions: Array<Address | NamespaceId>,
88+
public readonly restrictionAdditions: (Address | NamespaceId)[],
89+
public readonly restrictionDeletions: (Address | NamespaceId)[],
9090
signature?: string,
9191
signer?: PublicAccount,
9292
transactionInfo?: TransactionInfo) {

src/model/transaction/AccountMosaicRestrictionTransaction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
5555
*/
5656
public static create(deadline: Deadline,
5757
restrictionFlags: AccountRestrictionFlags,
58-
restrictionAdditions: Array<MosaicId | NamespaceId>,
59-
restrictionDeletions: Array<MosaicId | NamespaceId>,
58+
restrictionAdditions: (MosaicId | NamespaceId)[],
59+
restrictionDeletions: (MosaicId | NamespaceId)[],
6060
networkType: NetworkType,
6161
maxFee: UInt64 = new UInt64([0, 0])): AccountMosaicRestrictionTransaction {
6262
return new AccountMosaicRestrictionTransaction(networkType,
@@ -85,8 +85,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
8585
deadline: Deadline,
8686
maxFee: UInt64,
8787
public readonly restrictionFlags: AccountRestrictionFlags,
88-
public readonly restrictionAdditions: Array<MosaicId | NamespaceId>,
89-
public readonly restrictionDeletions: Array<MosaicId | NamespaceId>,
88+
public readonly restrictionAdditions: (MosaicId | NamespaceId)[],
89+
public readonly restrictionDeletions: (MosaicId | NamespaceId)[],
9090
signature?: string,
9191
signer?: PublicAccount,
9292
transactionInfo?: TransactionInfo) {

src/model/transaction/AccountRestrictionTransaction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class AccountRestrictionTransaction {
4141
public static createAddressRestrictionModificationTransaction(
4242
deadline: Deadline,
4343
restrictionFlags: AccountRestrictionFlags,
44-
restrictionAdditions: Array<Address | NamespaceId>,
45-
restrictionDeletions: Array<Address | NamespaceId>,
44+
restrictionAdditions: (Address | NamespaceId)[],
45+
restrictionDeletions: (Address | NamespaceId)[],
4646
networkType: NetworkType,
4747
maxFee: UInt64 = new UInt64([0, 0]),
4848
): AccountAddressRestrictionTransaction {
@@ -75,8 +75,8 @@ export class AccountRestrictionTransaction {
7575
public static createMosaicRestrictionModificationTransaction(
7676
deadline: Deadline,
7777
restrictionFlags: AccountRestrictionFlags,
78-
restrictionAdditions: Array<MosaicId | NamespaceId>,
79-
restrictionDeletions: Array<MosaicId | NamespaceId>,
78+
restrictionAdditions: (MosaicId | NamespaceId)[],
79+
restrictionDeletions: (MosaicId | NamespaceId)[],
8080
networkType: NetworkType,
8181
maxFee: UInt64 = new UInt64([0, 0]),
8282
): AccountMosaicRestrictionTransaction {

src/service/TransactionService.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,16 @@ export class TransactionService implements ITransactionService {
112112
/**
113113
* @internal
114114
*
115-
* This method publishes an error if the listener receives an error code for the given address and transaction hash. Otherwise, it returns the passed transactionObservable
115+
* This method publishes an error if the listener receives an error code for the given address & transaction hash.
116+
* Otherwise, it returns the passed transactionObservable
116117
*
117118
* @param listener the listener.
118119
* @param address the signer address
119120
* @param transactionHash the transaction hash
120121
* @param transactionObservable the observable with the valid transaction
121122
*/
122-
private getTransactionOrRaiseError<T extends Transaction>(listener: IListener, address: Address, transactionHash: string, transactionObservable: Observable<T>): Observable<T> {
123+
private getTransactionOrRaiseError<T extends Transaction>(listener: IListener, address: Address, transactionHash: string,
124+
transactionObservable: Observable<T>): Observable<T> {
123125
const errorObservable = listener.status(address).pipe(filter((t) => t.hash.toUpperCase() === transactionHash.toUpperCase()));
124126
return merge(transactionObservable, errorObservable).pipe(first(), map((errorOrTransaction) => {
125127
if (errorOrTransaction instanceof TransactionStatusError) {

test/infrastructure/NetworkHttp.spec.ts

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,34 @@
1515
*/
1616
import { expect } from 'chai';
1717
import * as http from 'http';
18-
import { NetworkRoutesApi, NetworkTypeDTO, NodeInfoDTO, NodeRoutesApi, TransactionFeesDTO } from 'symbol-openapi-typescript-node-client';
18+
import { NetworkRoutesApi,
19+
NetworkTypeDTO,
20+
NodeInfoDTO,
21+
NodeRoutesApi,
22+
TransactionFeesDTO,
23+
RentalFeesDTO,
24+
NetworkConfigurationDTO,
25+
NetworkPropertiesDTO,
26+
NodeIdentityEqualityStrategy,
27+
ChainPropertiesDTO,
28+
PluginsPropertiesDTO,
29+
AccountLinkNetworkPropertiesDTO,
30+
AggregateNetworkPropertiesDTO,
31+
HashLockNetworkPropertiesDTO,
32+
SecretLockNetworkPropertiesDTO,
33+
MetadataNetworkPropertiesDTO,
34+
MosaicNetworkPropertiesDTO,
35+
MultisigNetworkPropertiesDTO,
36+
NamespaceNetworkPropertiesDTO,
37+
AccountRestrictionNetworkPropertiesDTO,
38+
MosaicRestrictionNetworkPropertiesDTO,
39+
TransferNetworkPropertiesDTO } from 'symbol-openapi-typescript-node-client';
1940
import { instance, mock, reset, when } from 'ts-mockito';
2041
import { DtoMapping } from '../../src/core/utils/DtoMapping';
2142
import { NetworkHttp } from '../../src/infrastructure/NetworkHttp';
2243
import { NodeHttp } from '../../src/infrastructure/NodeHttp';
2344
import { NetworkType } from '../../src/model/network/NetworkType';
45+
import { deepEqual } from 'assert';
2446

2547
describe('NetworkHttp', () => {
2648
const url = 'http://someHost';
@@ -40,7 +62,7 @@ describe('NetworkHttp', () => {
4062
reset(networkRoutesApi);
4163
});
4264

43-
it('getNetworkFees', async () => {
65+
it('getTransactionFees', async () => {
4466

4567
const body = new TransactionFeesDTO();
4668
body.averageFeeMultiplier = 1;
@@ -58,6 +80,22 @@ describe('NetworkHttp', () => {
5880
expect(networkFees.medianFeeMultiplier).to.be.equals(4);
5981
});
6082

83+
it('getRentalFees', async () => {
84+
85+
const body = new RentalFeesDTO();
86+
body.effectiveChildNamespaceRentalFee = '1';
87+
body.effectiveMosaicRentalFee = '2';
88+
body.effectiveRootNamespaceRentalFeePerBlock = '3';
89+
90+
when(networkRoutesApi.getRentalFees()).thenReturn(Promise.resolve({response, body}));
91+
92+
const rentalFees = await networkRepository.getRentalFees().toPromise();
93+
expect(rentalFees).to.be.not.null;
94+
expect(rentalFees.effectiveChildNamespaceRentalFee).to.be.equals('1');
95+
expect(rentalFees.effectiveMosaicRentalFee).to.be.equals('2');
96+
expect(rentalFees.effectiveRootNamespaceRentalFeePerBlock).to.be.equals('3');
97+
});
98+
6199
it('getNetworkType', async () => {
62100

63101
const body = new NodeInfoDTO();
@@ -82,4 +120,106 @@ describe('NetworkHttp', () => {
82120
expect(networkName.name).to.be.equals(body.name);
83121
});
84122

123+
it('getNetworkProperties', async () => {
124+
125+
const body = new NetworkConfigurationDTO();
126+
127+
const network = new NetworkPropertiesDTO();
128+
network.identifier = 'id';
129+
network.nodeEqualityStrategy = NodeIdentityEqualityStrategy.Host;
130+
network.publicKey = 'pubKey';
131+
network.generationHash = 'genHash';
132+
network.epochAdjustment = '123456';
133+
134+
const chain = new ChainPropertiesDTO();
135+
chain.blockGenerationTargetTime = '1';
136+
chain.blockPruneInterval = '1';
137+
chain.blockTimeSmoothingFactor = '1';
138+
chain.currencyMosaicId = '1111111111111111';
139+
chain.defaultDynamicFeeMultiplier = '1';
140+
chain.enableVerifiableReceipts = true;
141+
chain.enableVerifiableState = true;
142+
chain.harvestBeneficiaryPercentage = '1';
143+
chain.harvestingMosaicId = '2222222222222222';
144+
chain.importanceActivityPercentage = '1';
145+
chain.importanceGrouping = '1';
146+
chain.initialCurrencyAtomicUnits = '1';
147+
chain.maxBlockFutureTime = '1';
148+
chain.maxDifficultyBlocks = '1';
149+
chain.maxHarvesterBalance = '1';
150+
chain.maxMosaicAtomicUnits = '1';
151+
chain.maxRollbackBlocks = '1';
152+
chain.maxTransactionLifetime = '1';
153+
chain.maxTransactionsPerBlock = '1';
154+
chain.minHarvesterBalance = '1';
155+
chain.totalChainImportance = '1';
156+
157+
const plugin = new PluginsPropertiesDTO();
158+
plugin.accountlink = new AccountLinkNetworkPropertiesDTO();
159+
plugin.accountlink.dummy = 'dummy';
160+
161+
plugin.aggregate = new AggregateNetworkPropertiesDTO();
162+
plugin.aggregate.enableBondedAggregateSupport = true;
163+
plugin.aggregate.enableStrictCosignatureCheck = true;
164+
plugin.aggregate.maxBondedTransactionLifetime = '1';
165+
plugin.aggregate.maxCosignaturesPerAggregate = '1';
166+
plugin.aggregate.maxTransactionsPerAggregate = '1';
167+
168+
plugin.lockhash = new HashLockNetworkPropertiesDTO();
169+
plugin.lockhash.lockedFundsPerAggregate = '1';
170+
plugin.lockhash.maxHashLockDuration = '1';
171+
172+
plugin.locksecret = new SecretLockNetworkPropertiesDTO();
173+
plugin.locksecret.maxProofSize = '1';
174+
plugin.locksecret.maxSecretLockDuration = '1';
175+
plugin.locksecret.minProofSize = '1';
176+
177+
plugin.metadata = new MetadataNetworkPropertiesDTO();
178+
plugin.metadata.maxValueSize = '1';
179+
180+
plugin.mosaic = new MosaicNetworkPropertiesDTO();
181+
plugin.mosaic.maxMosaicDivisibility = '1';
182+
plugin.mosaic.maxMosaicDuration = '1';
183+
plugin.mosaic.maxMosaicsPerAccount = '1';
184+
plugin.mosaic.mosaicRentalFee = '1';
185+
plugin.mosaic.mosaicRentalFeeSinkPublicKey = '1';
186+
187+
plugin.multisig = new MultisigNetworkPropertiesDTO();
188+
plugin.multisig.maxCosignatoriesPerAccount = '1';
189+
plugin.multisig.maxCosignedAccountsPerAccount = '1';
190+
plugin.multisig.maxMultisigDepth = '1';
191+
192+
plugin.namespace = new NamespaceNetworkPropertiesDTO();
193+
plugin.namespace.childNamespaceRentalFee = '1';
194+
plugin.namespace.maxChildNamespaces = '1';
195+
plugin.namespace.maxNameSize = '1';
196+
plugin.namespace.maxNamespaceDepth = '1';
197+
plugin.namespace.maxNamespaceDuration = '1';
198+
plugin.namespace.minNamespaceDuration = '1';
199+
plugin.namespace.namespaceGracePeriodDuration = '1';
200+
plugin.namespace.namespaceRentalFeeSinkPublicKey = '1';
201+
plugin.namespace.reservedRootNamespaceNames = '1';
202+
plugin.namespace.rootNamespaceRentalFeePerBlock = '1';
203+
204+
plugin.restrictionaccount = new AccountRestrictionNetworkPropertiesDTO();
205+
plugin.restrictionaccount.maxAccountRestrictionValues = '1';
206+
207+
plugin.restrictionmosaic = new MosaicRestrictionNetworkPropertiesDTO();
208+
plugin.restrictionmosaic.maxMosaicRestrictionValues = '1';
209+
210+
plugin.transfer = new TransferNetworkPropertiesDTO();
211+
plugin.transfer.maxMessageSize = '1';
212+
213+
body.chain = chain;
214+
body.network = network;
215+
body.plugins = plugin;
216+
217+
when(networkRoutesApi.getNetworkProperties()).thenReturn(Promise.resolve({response, body}));
218+
219+
const networkProperties = await networkRepository.getNetworkProperties().toPromise();
220+
deepEqual(networkProperties.network, body.network);
221+
deepEqual(networkProperties.chain, body.chain);
222+
deepEqual(networkProperties.plugins, body.plugins);
223+
});
224+
85225
});
File renamed without changes.

0 commit comments

Comments
 (0)