/
StateProofService.spec.ts
134 lines (122 loc) · 4.38 KB
/
StateProofService.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright 2020 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { expect } from 'chai';
import { Observable } from 'rxjs';
import { take, toArray } from 'rxjs/operators';
import { Order, RepositoryFactoryHttp, SearchCriteria, SearcherRepository } from '../../src/infrastructure';
import { NamespaceRegistrationType } from '../../src/model/namespace';
import { StateMerkleProof } from '../../src/model/state';
import { StateProofService } from '../../src/service';
const url = 'http://localhost:3000';
const repositoryFactory = new RepositoryFactoryHttp(url);
const service = new StateProofService(repositoryFactory);
const stateCounts = 50;
//Process the latest data first.
const order = Order.Desc;
// TODO, create dynamic it tests
async function test<E, C extends SearchCriteria>(
path: string,
repository: SearcherRepository<E, C>,
merkleMethod: (state: E) => Observable<StateMerkleProof>,
getId: (state: E) => string,
criteria: C = { order, pageSize: stateCounts } as C,
): Promise<void> {
const streamer = repository.streamer();
const infos = await streamer.search(criteria).pipe(take(stateCounts), toArray()).toPromise();
const promises = infos.map(async (info) => {
const idText = getId(info);
const stateUrl = `${url}/${path}/${idText}`;
try {
const merkle = await merkleMethod(info).toPromise();
expect(merkle).to.not.undefined;
if (merkle.valid) console.log(stateUrl + ' ' + merkle.valid + ' ' + merkle.stateHash);
else {
console.error(stateUrl + ' ' + merkle.valid);
}
} catch (e) {
console.error(stateUrl + ' ' + e);
console.error(e);
}
});
await Promise.all(promises);
}
describe('StateProofService', () => {
it('Mosaics', async () => {
await test(
'mosaics',
repositoryFactory.createMosaicRepository(),
(info) => service.mosaic(info),
(info) => info.id.toHex(),
);
});
it('Namespaces', async () => {
await test(
'namespaces',
repositoryFactory.createNamespaceRepository(),
(info) => service.namespaces(info),
(info) => info.id.toHex(),
{ order, pageSize: stateCounts, registrationType: NamespaceRegistrationType.RootNamespace },
);
});
it('Accounts', async () => {
await test(
'accounts',
repositoryFactory.createAccountRepository(),
(info) => service.account(info),
(info) => info.address.plain(),
);
});
it('Hash Lock', async () => {
await test(
'lock/hash',
repositoryFactory.createHashLockRepository(),
(info) => service.hashLock(info),
(info) => info.hash,
);
});
it('Secret Lock', async () => {
await test(
'lock/secret',
repositoryFactory.createSecretLockRepository(),
(info) => service.secretLock(info),
(info) => info.compositeHash,
);
});
it('Account restrictions', async () => {
await test(
'restrictions/account',
repositoryFactory.createRestrictionAccountRepository(),
(info) => service.accountRestriction(info),
(info) => info.address.plain(),
);
});
it('Mosaic restrictions', async () => {
await test(
'restrictions/mosaic',
repositoryFactory.createRestrictionMosaicRepository(),
(info) => service.mosaicRestriction(info),
(info) => info.compositeHash,
);
});
it('Metadata', async () => {
await test(
'metadata',
repositoryFactory.createMetadataRepository(),
(info) => service.metadata(info),
(info) => info.metadataEntry.compositeHash,
);
});
});