Skip to content

Commit 56fbd02

Browse files
authored
[JAV-52, JAV-54, JAV-57, JAV-27, JAV-58, JAV-59] Small issue fixes (#284)
* JAV-52 [github #276] Fixed mosaicAmountView observable issue Fixed @types/long dev package in package.json * JAV-54 [Github #277] Improved AccountRestriction payload * JAV-57 [Github #285] Fixed error handling issue * JAV-27 [Github #246] Fixed Alias issue * Added @InterAl for abstract mathod * JAV-58 [Github #286] Fixed MosaicId significant byte not detected * Implement KeyGenerator * Fix copyright, jsdoc and return value type. Remove regex * JAV-59 [Github #287] Fixed network http only allow MIJIN_TEST issue * Changed metadataTransactionService key from string to UInt64 * Rename, relax validation, convert to arraybuf instead of hex * JAV-52 [github #276] Fixed mosaicAmountView observable issue Fixed @types/long dev package in package.json * JAV-54 [Github #277] Improved AccountRestriction payload * JAV-57 [Github #285] Fixed error handling issue * JAV-27 [Github #246] Fixed Alias issue * Added @InterAl for abstract mathod * JAV-58 [Github #286] Fixed MosaicId significant byte not detected * JAV-59 [Github #287] Fixed network http only allow MIJIN_TEST issue * Changed metadataTransactionService key from string to UInt64
1 parent 7615a42 commit 56fbd02

35 files changed

+221
-190
lines changed

e2e/infrastructure/RestrictionHttp.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import {deepEqual} from 'assert';
18-
import {assert} from 'chai';
18+
import {assert, expect} from 'chai';
1919
import {AccountHttp} from '../../src/infrastructure/AccountHttp';
2020
import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure';
2121
import { RestrictionHttp } from '../../src/infrastructure/RestrictionHttp';
@@ -309,7 +309,7 @@ describe('RestrictionHttp', () => {
309309
it('should call getAccountRestrictions successfully', (done) => {
310310
setTimeout(() => {
311311
restrictionHttp.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => {
312-
deepEqual(accountRestrictions.accountRestrictions.address, accountAddress);
312+
expect(accountRestrictions.length).to.be.greaterThan(0);
313313
done();
314314
});
315315
}, 1000);
@@ -320,7 +320,7 @@ describe('RestrictionHttp', () => {
320320
it('should call getAccountRestrictionsFromAccounts successfully', (done) => {
321321
setTimeout(() => {
322322
restrictionHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => {
323-
deepEqual(accountRestrictions[0]!.accountRestrictions.address, accountAddress);
323+
deepEqual(accountRestrictions[0]!.address, accountAddress);
324324
done();
325325
});
326326
}, 1000);

e2e/service/MetadataTransactionService.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ describe('MetadataTransactionService', () => {
206206
NetworkType.MIJIN_TEST,
207207
MetadataType.Account,
208208
targetAccount.publicAccount,
209-
key.toHex(),
209+
key,
210210
newValue,
211211
targetAccount.publicAccount,
212212
).subscribe((transaction: AccountMetadataTransaction) => {
@@ -225,7 +225,7 @@ describe('MetadataTransactionService', () => {
225225
NetworkType.MIJIN_TEST,
226226
MetadataType.Mosaic,
227227
targetAccount.publicAccount,
228-
key.toHex(),
228+
key,
229229
newValue + 'delta',
230230
targetAccount.publicAccount,
231231
mosaicId,
@@ -247,7 +247,7 @@ describe('MetadataTransactionService', () => {
247247
NetworkType.MIJIN_TEST,
248248
MetadataType.Namespace,
249249
targetAccount.publicAccount,
250-
key.toHex(),
250+
key,
251251
newValue + 'delta',
252252
targetAccount.publicAccount,
253253
namespaceId,
@@ -280,7 +280,7 @@ describe('MetadataTransactionService', () => {
280280
NetworkType.MIJIN_TEST,
281281
MetadataType.Mosaic,
282282
targetAccount.publicAccount,
283-
key.toHex(),
283+
key,
284284
newValue + 'delta',
285285
targetAccount.publicAccount,
286286
mosaicId,

e2e/service/MosaicService.spec.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
import { map, mergeMap, toArray } from 'rxjs/operators';
1+
/*
2+
* Copyright 2019 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
217
import { AccountHttp } from '../../src/infrastructure/AccountHttp';
318
import { MosaicHttp } from '../../src/infrastructure/MosaicHttp';
419
import { Address } from '../../src/model/account/Address';
@@ -22,15 +37,17 @@ describe('MosaicService', () => {
2237
done();
2338
});
2439
});
25-
it('should return the mosaic list skipping the expired mosaics', () => {
40+
it('should return the mosaic list skipping the expired mosaics', (done) => {
2641
const mosaicService = new MosaicService(accountHttp, mosaicHttp);
2742

2843
const address = accountAddress;
2944

30-
return mosaicService.mosaicsAmountViewFromAddress(address).pipe(
31-
mergeMap((_) => _),
32-
map((mosaic) => console.log('You have', mosaic.relativeAmount(), mosaic.fullName())),
33-
toArray(),
34-
).toPromise();
45+
return mosaicService.mosaicsAmountViewFromAddress(address).subscribe((amountViews) => {
46+
const views = amountViews.map((v) => {
47+
return {mosaicId: v.fullName(), amount: v.relativeAmount()};
48+
});
49+
console.log(views);
50+
done();
51+
});
3552
});
3653
});

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@types/chai": "^4.0.4",
3636
"@types/crypto-js": "^3.1.43",
3737
"@types/lodash": "^4.14.85",
38+
"@types/long": "^4.0.0",
3839
"@types/mocha": "^2.2.44",
3940
"@types/request": "^2.47.0",
4041
"@types/request-promise-native": "^1.0.14",
@@ -55,7 +56,6 @@
5556
"typescript-require": "^0.2.9-1"
5657
},
5758
"dependencies": {
58-
"@types/long": "^4.0.0",
5959
"bluebird": "^3.5.5",
6060
"crypto-js": "^3.1.9-1",
6161
"js-joda": "^1.6.2",

src/infrastructure/AccountHttp.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class AccountHttp extends Http implements AccountRepository {
145145

146146
});
147147
}),
148-
catchError((error) => throwError(error)),
148+
catchError((error) => throwError(this.errorHandling(error))),
149149
);
150150
}
151151

@@ -166,7 +166,7 @@ export class AccountHttp extends Http implements AccountRepository {
166166
);
167167
});
168168
}),
169-
catchError((error) => throwError(error)),
169+
catchError((error) => throwError(this.errorHandling(error))),
170170
);
171171
}
172172
/**
@@ -190,7 +190,7 @@ export class AccountHttp extends Http implements AccountRepository {
190190
.map((multisigAccount) => PublicAccount.createFromPublicKey(multisigAccount, networkType)),
191191
);
192192
}),
193-
catchError((error) => throwError(error)),
193+
catchError((error) => throwError(this.errorHandling(error))),
194194
)));
195195
}
196196

@@ -223,7 +223,7 @@ export class AccountHttp extends Http implements AccountRepository {
223223
});
224224
return new MultisigAccountGraphInfo(multisigAccounts);
225225
}),
226-
catchError((error) => throwError(error)),
226+
catchError((error) => throwError(this.errorHandling(error))),
227227
)));
228228
}
229229

@@ -245,7 +245,7 @@ export class AccountHttp extends Http implements AccountRepository {
245245
return CreateTransactionFromDTO(transactionDTO);
246246
});
247247
}),
248-
catchError((error) => throwError(error)),
248+
catchError((error) => throwError(this.errorHandling(error))),
249249
);
250250
}
251251

@@ -268,7 +268,7 @@ export class AccountHttp extends Http implements AccountRepository {
268268
return CreateTransactionFromDTO(transactionDTO);
269269
});
270270
}),
271-
catchError((error) => throwError(error)),
271+
catchError((error) => throwError(this.errorHandling(error))),
272272
);
273273
}
274274

@@ -291,7 +291,7 @@ export class AccountHttp extends Http implements AccountRepository {
291291
return CreateTransactionFromDTO(transactionDTO);
292292
});
293293
}),
294-
catchError((error) => throwError(error)),
294+
catchError((error) => throwError(this.errorHandling(error))),
295295
);
296296
}
297297

@@ -315,7 +315,7 @@ export class AccountHttp extends Http implements AccountRepository {
315315
return CreateTransactionFromDTO(transactionDTO);
316316
});
317317
}),
318-
catchError((error) => throwError(error)),
318+
catchError((error) => throwError(this.errorHandling(error))),
319319
);
320320
}
321321

@@ -338,7 +338,7 @@ export class AccountHttp extends Http implements AccountRepository {
338338
return CreateTransactionFromDTO(transactionDTO) as AggregateTransaction;
339339
});
340340
}),
341-
catchError((error) => throwError(error)),
341+
catchError((error) => throwError(this.errorHandling(error))),
342342
);
343343
}
344344
}

src/infrastructure/Http.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ export abstract class Http {
5959
}
6060

6161
errorHandling(error: any): Error {
62-
if (error.response && error.response.statusCode && error.response.body) {
62+
if (error.response && error.response.statusCode && error.body) {
6363
const formattedError = {
6464
statusCode: error.response.statusCode,
65-
errorDetails: error.response.body,
65+
errorDetails: error.response,
66+
body: error.body,
6667
};
6768
return new Error(JSON.stringify(formattedError));
6869
}

src/infrastructure/MetadataHttp.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
7272
return this.buildMetadata(metadataEntry);
7373
});
7474
}),
75-
catchError((error) => throwError(error)),
75+
catchError((error) => throwError(this.errorHandling(error))),
7676
);
7777
}
7878

@@ -91,7 +91,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
9191
return this.buildMetadata(metadataEntry);
9292
});
9393
}),
94-
catchError((error) => throwError(error)),
94+
catchError((error) => throwError(this.errorHandling(error))),
9595
);
9696
}
9797

@@ -109,7 +109,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
109109
const metadataDTO = response.body;
110110
return this.buildMetadata(metadataDTO);
111111
}),
112-
catchError((error) => throwError(error)),
112+
catchError((error) => throwError(this.errorHandling(error))),
113113
);
114114
}
115115

@@ -131,7 +131,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
131131
return this.buildMetadata(metadataEntry);
132132
});
133133
}),
134-
catchError((error) => throwError(error)),
134+
catchError((error) => throwError(this.errorHandling(error))),
135135
);
136136
}
137137

@@ -150,7 +150,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
150150
return this.buildMetadata(metadataEntry);
151151
});
152152
}),
153-
catchError((error) => throwError(error)),
153+
catchError((error) => throwError(this.errorHandling(error))),
154154
);
155155
}
156156

@@ -168,7 +168,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
168168
const metadataDTO = response.body;
169169
return this.buildMetadata(metadataDTO);
170170
}),
171-
catchError((error) => throwError(error)),
171+
catchError((error) => throwError(this.errorHandling(error))),
172172
);
173173
}
174174

@@ -190,7 +190,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
190190
return this.buildMetadata(metadataEntry);
191191
});
192192
}),
193-
catchError((error) => throwError(error)),
193+
catchError((error) => throwError(this.errorHandling(error))),
194194
);
195195
}
196196

@@ -209,7 +209,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
209209
return this.buildMetadata(metadataEntry);
210210
});
211211
}),
212-
catchError((error) => throwError(error)),
212+
catchError((error) => throwError(this.errorHandling(error))),
213213
);
214214
}
215215

@@ -227,7 +227,7 @@ export class MetadataHttp extends Http implements MetadataRepository {
227227
const metadataDTO = response.body;
228228
return this.buildMetadata(metadataDTO);
229229
}),
230-
catchError((error) => throwError(error)),
230+
catchError((error) => throwError(this.errorHandling(error))),
231231
);
232232
}
233233

src/infrastructure/NamespaceHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ export class NamespaceHttp extends Http implements NamespaceRepository {
270270
*/
271271
private extractAlias(namespace: any): Alias {
272272
if (namespace.alias && namespace.alias.type === AliasType.Mosaic) {
273-
return new MosaicAlias(namespace.alias.type, namespace.alias.mosaicId);
273+
return new MosaicAlias(namespace.alias.mosaicId);
274274
} else if (namespace.alias && namespace.alias.type === AliasType.Address) {
275-
return new AddressAlias(namespace.alias.type, namespace.alias.address);
275+
return new AddressAlias(namespace.alias.address);
276276
}
277277

278278
return new EmptyAlias();

src/infrastructure/NetworkHttp.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import { ClientResponse } from 'http';
1818
import {from as observableFrom, Observable, throwError} from 'rxjs';
1919
import {catchError, map} from 'rxjs/operators';
2020
import {NetworkType} from '../model/blockchain/NetworkType';
21-
import { NetworkRoutesApi, NetworkTypeDTO } from './api';
21+
import { NodeInfo } from '../model/node/NodeInfo';
2222
import {Http} from './Http';
2323
import {NetworkRepository} from './NetworkRepository';
24+
import { NodeHttp } from './NodeHttp';
2425

2526
/**
2627
* Network http repository.
@@ -32,15 +33,15 @@ export class NetworkHttp extends Http implements NetworkRepository {
3233
* @internal
3334
* Nem2 Library account routes api
3435
*/
35-
private networkRoutesApi: NetworkRoutesApi;
36+
private nodeHttp: NodeHttp;
3637

3738
/**
3839
* Constructor
3940
* @param url
4041
*/
4142
constructor(url: string) {
4243
super();
43-
this.networkRoutesApi = new NetworkRoutesApi(url);
44+
this.nodeHttp = new NodeHttp(url);
4445

4546
}
4647

@@ -50,16 +51,11 @@ export class NetworkHttp extends Http implements NetworkRepository {
5051
* @return network type enum.
5152
*/
5253
public getNetworkType(): Observable<NetworkType> {
53-
return observableFrom(this.networkRoutesApi.getNetworkType()).pipe(
54-
map((response: { response: ClientResponse; body: NetworkTypeDTO; } ) => {
55-
const networkTypeDTO = response.body;
56-
if (networkTypeDTO.name === 'mijinTest') {
57-
return NetworkType.MIJIN_TEST;
58-
} else {
59-
throw new Error('network ' + networkTypeDTO.name + ' is not supported yet by the sdk');
60-
}
54+
return observableFrom(this.nodeHttp.getNodeInfo()).pipe(
55+
map(((nodeInfo: NodeInfo) => {
56+
return nodeInfo.networkIdentifier;
6157
}),
62-
catchError((error) => throwError(this.errorHandling(error))),
58+
catchError((error) => throwError(this.errorHandling(error)))),
6359
);
6460
}
6561
}

0 commit comments

Comments
 (0)