Skip to content

Commit f9e7faa

Browse files
committed
Migrated Receipt and added receit tests
1 parent f2cb8be commit f9e7faa

File tree

2 files changed

+181
-32
lines changed

2 files changed

+181
-32
lines changed

e2e/service/MosaicService.spec.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
// import { map, mergeMap, toArray } from 'rxjs/operators';
2-
// import { AccountHttp } from '../../src/infrastructure/AccountHttp';
3-
// import { MosaicHttp } from '../../src/infrastructure/MosaicHttp';
4-
// import { Address } from '../../src/model/account/Address';
5-
// import { MosaicService } from '../../src/service/MosaicService';
1+
import { map, mergeMap, toArray } from 'rxjs/operators';
2+
import { AccountHttp } from '../../src/infrastructure/AccountHttp';
3+
import { MosaicHttp } from '../../src/infrastructure/MosaicHttp';
4+
import { Address } from '../../src/model/account/Address';
5+
import { MosaicService } from '../../src/service/MosaicService';
66

7-
// describe('MosaicService', () => {
8-
// let accountAddress: Address;
9-
// let accountHttp: AccountHttp;
10-
// let mosaicHttp: MosaicHttp;
7+
describe('MosaicService', () => {
8+
let accountAddress: Address;
9+
let accountHttp: AccountHttp;
10+
let mosaicHttp: MosaicHttp;
1111

12-
// before((done) => {
13-
// const path = require('path');
14-
// require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => {
15-
// if (err) {
16-
// throw err;
17-
// }
18-
// const json = JSON.parse(data);
19-
// accountAddress = Address.createFromRawAddress(json.testAccount.address);
20-
// accountHttp = new AccountHttp(json.apiUrl);
21-
// mosaicHttp = new MosaicHttp(json.apiUrl);
22-
// done();
23-
// });
24-
// });
25-
// it('should return the mosaic list skipping the expired mosaics', () => {
26-
// const mosaicService = new MosaicService(accountHttp, mosaicHttp);
12+
before((done) => {
13+
const path = require('path');
14+
require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => {
15+
if (err) {
16+
throw err;
17+
}
18+
const json = JSON.parse(data);
19+
accountAddress = Address.createFromRawAddress(json.testAccount.address);
20+
accountHttp = new AccountHttp(json.apiUrl);
21+
mosaicHttp = new MosaicHttp(json.apiUrl);
22+
done();
23+
});
24+
});
25+
it('should return the mosaic list skipping the expired mosaics', () => {
26+
const mosaicService = new MosaicService(accountHttp, mosaicHttp);
2727

28-
// const address = accountAddress;
28+
const address = accountAddress;
2929

30-
// return mosaicService.mosaicsAmountViewFromAddress(address).pipe(
31-
// mergeMap((_) => _),
32-
// map((mosaic) => console.log('You have', mosaic.relativeAmount(), mosaic.fullName())),
33-
// toArray(),
34-
// ).toPromise();
35-
// });
36-
// });
30+
return mosaicService.mosaicsAmountViewFromAddress(address).pipe(
31+
mergeMap((_) => _),
32+
map((mosaic) => console.log('You have', mosaic.relativeAmount(), mosaic.fullName())),
33+
toArray(),
34+
).toPromise();
35+
});
36+
});
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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+
17+
import { deepEqual } from 'assert';
18+
import { expect } from 'chai';
19+
import { CreateStatementFromDTO } from '../../../src/infrastructure/receipt/CreateReceiptFromDTO';
20+
import {Account} from '../../../src/model/account/Account';
21+
import { Address } from '../../../src/model/account/Address';
22+
import { NetworkType } from '../../../src/model/blockchain/NetworkType';
23+
import { MosaicId } from '../../../src/model/mosaic/MosaicId';
24+
import { AddressAlias } from '../../../src/model/namespace/AddressAlias';
25+
import { MosaicAlias } from '../../../src/model/namespace/MosaicAlias';
26+
import { ReceiptType } from '../../../src/model/receipt/ReceiptType';
27+
28+
describe('Receipt - CreateStatementFromDTO', () => {
29+
let account: Account;
30+
let account2: Account;
31+
let statementDto;
32+
const netWorkType = NetworkType.MIJIN_TEST;
33+
34+
before(() => {
35+
account = Account.createFromPrivateKey('D242FB34C2C4DD36E995B9C865F93940065E326661BA5A4A247331D211FE3A3D', NetworkType.MIJIN_TEST);
36+
account2 = Account.createFromPrivateKey('E5DCCEBDB01A8B03A7DB7BA5888E2E33FD4617B5F6FED48C4C09C0780F422713', NetworkType.MIJIN_TEST);
37+
statementDto = {transactionStatements: [
38+
{
39+
height: [52, 0],
40+
source: {
41+
primaryId: 0,
42+
secondaryId: 0,
43+
},
44+
receipts: [
45+
{
46+
version: 1,
47+
type: 8515,
48+
account: account.publicKey,
49+
mosaicId: [3646934825, 3576016193],
50+
amount: [1000, 0],
51+
},
52+
],
53+
},
54+
],
55+
addressResolutionStatements: [
56+
{
57+
height: [1488, 0],
58+
unresolved: '9103B60AAF2762688300000000000000000000000000000000',
59+
resolutionEntries: [
60+
{
61+
source: {
62+
primaryId: 4,
63+
secondaryId: 0,
64+
},
65+
resolved: '917E7E29A01014C2F300000000000000000000000000000000',
66+
},
67+
],
68+
},
69+
{
70+
height: [1488, 0],
71+
unresolved: '917E7E29A01014C2F300000000000000000000000000000000',
72+
resolutionEntries: [
73+
{
74+
source: {
75+
primaryId: 2,
76+
secondaryId: 0,
77+
},
78+
resolved: '9103B60AAF2762688300000000000000000000000000000000',
79+
},
80+
],
81+
},
82+
],
83+
mosaicResolutionStatements: [
84+
{
85+
height: [
86+
1506,
87+
0,
88+
],
89+
unresolved: [4014740460, 2448037180],
90+
resolutionEntries: [
91+
{
92+
source: {
93+
primaryId: 1,
94+
secondaryId: 0,
95+
},
96+
resolved: '08a12f89ee5a49f8',
97+
},
98+
],
99+
},
100+
{
101+
height: [
102+
1506,
103+
0,
104+
],
105+
unresolved: [
106+
2234768168,
107+
2553890912,
108+
],
109+
resolutionEntries: [
110+
{
111+
source: {
112+
primaryId: 5,
113+
secondaryId: 0,
114+
},
115+
resolved: '08a12f89ee5a49f8',
116+
},
117+
],
118+
},
119+
]};
120+
});
121+
it('should create Statement', () => {
122+
const statement = CreateStatementFromDTO(statementDto, netWorkType);
123+
const unresolvedAddress = statement.addressResolutionStatements[0].unresolved as Address;
124+
const unresolvedMosaicId = statement.mosaicResolutionStatements[0].unresolved as MosaicId;
125+
126+
expect(statement.transactionStatements.length).to.be.equal(1);
127+
expect(statement.addressResolutionStatements.length).to.be.equal(2);
128+
expect(statement.mosaicResolutionStatements.length).to.be.equal(2);
129+
130+
expect(statement.transactionStatements[0].receipts.length).to.be.equal(1);
131+
deepEqual(statement.transactionStatements[0].height, [52, 0]);
132+
expect(statement.transactionStatements[0].source.primaryId).to.be.equal(0);
133+
expect(statement.transactionStatements[0].source.secondaryId).to.be.equal(0);
134+
expect(statement.transactionStatements[0].receipts[0].type).to.be.equal(ReceiptType.Harvest_Fee);
135+
136+
deepEqual(statement.addressResolutionStatements[0].height, [1488, 0]);
137+
deepEqual(unresolvedAddress.plain(),
138+
Address.createFromEncoded('9103B60AAF2762688300000000000000000000000000000000').plain());
139+
expect(statement.addressResolutionStatements[0].resolutionEntries.length).to.be.equal(1);
140+
expect((statement.addressResolutionStatements[0].resolutionEntries[0].resolved as AddressAlias)
141+
.address.plain()).to.be.equal(Address.createFromEncoded('917E7E29A01014C2F300000000000000000000000000000000').plain());
142+
143+
deepEqual(statement.mosaicResolutionStatements[0].height, [1506, 0]);
144+
deepEqual(unresolvedMosaicId.toDTO().id, [4014740460, 2448037180]);
145+
expect(statement.mosaicResolutionStatements[0].resolutionEntries.length).to.be.equal(1);
146+
deepEqual((statement.mosaicResolutionStatements[0].resolutionEntries[0].resolved as MosaicAlias)
147+
.mosaicId.toHex(), '08a12f89ee5a49f8');
148+
});
149+
});

0 commit comments

Comments
 (0)