Skip to content

Commit e2f694e

Browse files
committed
Fixed bug in account property DTO mapper.
1 parent e71beaa commit e2f694e

File tree

7 files changed

+83
-32
lines changed

7 files changed

+83
-32
lines changed

e2e/conf/network.conf

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
{
2-
"APIUrl": "http://localhost:3000"
2+
"apiUrl": "http://localhost:3000",
3+
"testAccount": {
4+
"privateKey": "B3C5B6DD7DCDE9ACF040499E982203404515B26A1D9C909276F2CF9099D72AA5",
5+
"address": "SAG4PUQZJH534BN7BAQKESIDWWJPFIHJOLWUSOKB",
6+
"publicKey": "16644FB8EDBF3BE36E91AC19EF65B46030EE2A0B2BF7D689B0E0E8AC1F793260"
7+
},
8+
"multisigAccount": {
9+
"privateKey": "95BAE7D0C17DCC9B3BF0C404F863BF15D5DEA2C16AD69CAB635E47E0464B358D",
10+
"address": "SCRABJ2OCFOBKMYO3H6FWR2RELHGMYXQRJCDIUFA",
11+
"publicKey": "89458BF00F28F6121081CB781DED5F1922A36918B1A682ED3D457FB00D78CD8D"
12+
},
13+
"cosignatoryAccount": {
14+
"privateKey": "EAFC5E1EFB6D37A8DADCC1FAD87266B8A0C185A6763DF58CBD615856A5CDFB0B",
15+
"address": "SDG3RSJJIUMPBMXQOEAZ5WJVLCPLJ33WVPRBQICX",
16+
"publicKey": "7F12578F5C355DEA763E53E170D21D6D28ED6E2B96C4597A16E875FE06CC030C"
17+
},
18+
"cosignatory2Account": {
19+
"privateKey": "740855D54E7265C3096758DBE143AA33E67D40EF9C00D5251C7CF989BA2AEFAC",
20+
"address": "SARPZCINH3565TXYQPANBHDR6XF7UVTY2P2FJJAB",
21+
"publicKey": "237A7EA34532E8254095B3E39A676FB9E731D6667B28A54DC453CA3A44034C91"
22+
},
23+
"cosignatory3Account": {
24+
"privateKey": "76879F080CB8D06D24E4C69C2D46AE2B78000A364E8AB1A74120F5A539491077",
25+
"address": "SCOZIUOOL3DKQQEZ3FLEAUFGY7SH7XQKM5IBJDGM",
26+
"publicKey": "31CE6071B5F501B633A08BD77B7BDFEDD79B7ED43E4FF8A85FF62E39EBBC194E"
27+
}
328
}

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,32 @@ import {Address} from '../../src/model/account/Address';
2121
import {PublicAccount} from '../../src/model/account/PublicAccount';
2222
import {NetworkType} from '../../src/model/blockchain/NetworkType';
2323

24-
import {APIUrl} from '../conf/conf.spec';
25-
2624
describe('AccountHttp', () => {
27-
const accountAddress = Address.createFromRawAddress('SDRDGFTDLLCB67D4HPGIMIHPNSRYRJRT7DOBGWZY');
28-
const accountPublicKey = '1026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF37755';
29-
const publicAccount = PublicAccount.createFromPublicKey('846B4439154579A5903B1459C9CF69CB8153F6D0110A7A0ED61DE29AE4810BF2',
30-
NetworkType.MIJIN_TEST);
31-
const multisigPublicAccount = PublicAccount.createFromPublicKey('B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D',
32-
NetworkType.MIJIN_TEST);
33-
34-
const accountHttp = new AccountHttp(APIUrl);
25+
let accountAddress: Address;
26+
let accountPublicKey: string;
27+
let publicAccount: PublicAccount;
28+
let multisigPublicAccount: PublicAccount;
29+
let accountHttp: AccountHttp;
30+
31+
before((done) => {
32+
const path = require('path');
33+
require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => {
34+
if (err) {
35+
throw err;
36+
}
37+
const json = JSON.parse(data);
38+
console.log(json);
39+
40+
accountAddress = Address.createFromRawAddress(json.testAccount.address);
41+
// accountAddress = Address.createFromRawAddress('SBAGR4-IBHFHZ-YURYBL-F4XAJT-3CECON-3N2IGJ-Q3X2');
42+
accountPublicKey = json.testAccount.publicKey;
43+
publicAccount = PublicAccount.createFromPublicKey(json.testAccount.publicKey, NetworkType.MIJIN_TEST);
44+
multisigPublicAccount = PublicAccount.createFromPublicKey(json.multisigAccount.publicKey, NetworkType.MIJIN_TEST);
45+
46+
accountHttp = new AccountHttp(json.apiUrl);
47+
done();
48+
});
49+
});
3550

3651
describe('getAccountInfo', () => {
3752
it('should return account data given a NEM Address', (done) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"pretest": "npm run build",
77
"test": "mocha --ui bdd --recursive ./dist/test --timeout 90000",
88
"e2econfigcopy": "copyfiles --flat ./e2e/conf/*.conf ./dist/e2e/conf/",
9-
"test:e2e": "mocha --ui bdd --recursive ./dist/e2e --timeout 90000",
9+
"test:e2e": "npm run build && mocha --ui bdd --recursive ./dist/e2e --timeout 90000",
1010
"test:all": "mocha --ui bdd --recursive ./dist/ --timeout 90000",
1111
"build": "rm -rf dist/ && tsc && npm run e2econfigcopy ",
1212
"test:cov": "nyc --reporter=lcov --reporter=text-lcov npm t && nyc report --reporter=text-lcov",

src/infrastructure/AccountHttp.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import {Http} from './Http';
3333
import {NetworkHttp} from './NetworkHttp';
3434
import {QueryParams} from './QueryParams';
3535
import {CreateTransactionFromDTO} from './transaction/CreateTransactionFromDTO';
36+
import { AccountProperties } from '../model/account/AccountProperties';
37+
import { AccountProperty } from '../model/account/AccountProperty';
3638

3739
/**
3840
* Account http repository.
@@ -87,11 +89,12 @@ export class AccountHttp extends Http implements AccountRepository {
8789
*/
8890
public getAccountProperty(publicAccount: PublicAccount): Observable<AccountPropertiesInfo> {
8991
return observableFrom(this.accountRoutesApi.getAccountProperties(publicAccount.publicKey)).pipe(map((accountProperties) => {
90-
return new AccountPropertiesInfo(
91-
accountProperties.meta,
92-
accountProperties.accountProperties,
93-
);
94-
}));
92+
return new AccountPropertiesInfo(
93+
accountProperties.meta,
94+
new AccountProperties(Address.createFromEncoded(accountProperties.accountProperties.address),
95+
accountProperties.accountProperties.properties.map((prop) =>
96+
new AccountProperty(prop.propertyType, prop.values))));
97+
}));
9598
}
9699

97100
/**
@@ -106,7 +109,9 @@ export class AccountHttp extends Http implements AccountRepository {
106109
return accountProperties.map((property) => {
107110
return new AccountPropertiesInfo(
108111
property.meta,
109-
property.accountProperties,
112+
new AccountProperties(Address.createFromEncoded(property.accountProperties.address),
113+
property.accountProperties.properties.map((prop) =>
114+
new AccountProperty(prop.propertyType, prop.values))),
110115
);
111116
});
112117
}));
@@ -119,7 +124,7 @@ export class AccountHttp extends Http implements AccountRepository {
119124
*/
120125
public getAccountsInfo(addresses: Address[]): Observable<AccountInfo[]> {
121126
const accountIdsBody = {
122-
accountIds: addresses.map((address) => address.plain()),
127+
addresses: addresses.map((address) => address.plain()),
123128
};
124129
return observableFrom(
125130
this.accountRoutesApi.getAccountsInfo(accountIdsBody)).pipe(map((accountsInfoMetaDataDTO) => {

src/infrastructure/Listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import {Observable, Subject} from 'rxjs';
1818
import {filter, map, share} from 'rxjs/operators';
19-
import 'ws';
19+
import * as WebSocket from 'ws';
2020
import {Address} from '../model/account/Address';
2121
import {PublicAccount} from '../model/account/PublicAccount';
2222
import {BlockInfo} from '../model/blockchain/BlockInfo';

src/model/account/AccountPropertiesInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class AccountPropertiesInfo {
3232
/**
3333
* Properties.
3434
*/
35-
public readonly accountProperties: AccountProperties[]) {
35+
public readonly accountProperties: AccountProperties) {
3636

3737
}
3838
}

test/model/account/AccountPropertiesInfo.spec.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,43 @@
1515
*/
1616

1717
import {deepEqual} from 'assert';
18+
import { AccountProperties } from '../../../src/model/account/AccountProperties';
19+
import { AccountPropertiesInfo } from '../../../src/model/account/AccountPropertiesInfo';
20+
import { AccountProperty } from '../../../src/model/account/AccountProperty';
1821
import {Address} from '../../../src/model/account/Address';
19-
import {AccountPropertiesInfo, PropertyModificationType, PropertyType } from '../../../src/model/model';
22+
import { PropertyModificationType } from '../../../src/model/account/PropertyModificationType';
23+
import { PropertyType } from '../../../src/model/account/PropertyType';
2024

2125
describe('AccountPropertiesInfo', () => {
2226

2327
it('should createComplete an AccountPropertiesInfo object', () => {
2428

2529
const accountPropertiesInfoDTO = {
2630
meta: {id: '12345'},
27-
accountProperties: [{
28-
address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'),
31+
accountProperties: {
32+
address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142',
2933
properties: [{
3034
propertyType: PropertyType.AllowAddress,
3135
values: [{modificationType: PropertyModificationType.Add,
3236
value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM',
3337
}],
3438
}],
35-
}],
39+
},
3640
};
3741

3842
const accountPropertiesInfo = new AccountPropertiesInfo(
3943
accountPropertiesInfoDTO.meta,
40-
accountPropertiesInfoDTO.accountProperties,
44+
new AccountProperties(Address.createFromEncoded(accountPropertiesInfoDTO.accountProperties.address),
45+
accountPropertiesInfoDTO.accountProperties.properties.map((prop) =>
46+
new AccountProperty(prop.propertyType, prop.values))),
4147
);
4248

4349
deepEqual(accountPropertiesInfo.meta.id, accountPropertiesInfoDTO.meta.id);
44-
deepEqual(accountPropertiesInfo.accountProperties.length, accountPropertiesInfoDTO.accountProperties.length);
45-
deepEqual(accountPropertiesInfo.accountProperties[0].address, accountPropertiesInfoDTO.accountProperties[0].address);
46-
deepEqual(accountPropertiesInfo.accountProperties[0].properties.length,
47-
accountPropertiesInfoDTO.accountProperties[0].properties.length);
48-
deepEqual(accountPropertiesInfo.accountProperties[0].properties[0].values[0],
49-
accountPropertiesInfoDTO.accountProperties[0].properties[0].values[0]);
50+
deepEqual(accountPropertiesInfo.accountProperties.address,
51+
Address.createFromEncoded(accountPropertiesInfoDTO.accountProperties.address));
52+
deepEqual(accountPropertiesInfo.accountProperties.properties.length,
53+
accountPropertiesInfoDTO.accountProperties.properties.length);
54+
deepEqual(accountPropertiesInfo.accountProperties.properties[0].values[0],
55+
accountPropertiesInfoDTO.accountProperties.properties[0].values[0]);
5056
});
5157
});

0 commit comments

Comments
 (0)