-
Notifications
You must be signed in to change notification settings - Fork 62
/
NamespaceHttp.spec.ts
134 lines (122 loc) · 5.7 KB
/
NamespaceHttp.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 2018 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 { deepEqual } from 'assert';
import { expect } from 'chai';
import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository';
import { Account } from '../../src/model/account/Account';
import { Address } from '../../src/model/account/Address';
import { AliasAction } from '../../src/model/namespace/AliasAction';
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction';
import { Deadline } from '../../src/model/transaction/Deadline';
import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction';
import { UInt64 } from '../../src/model/UInt64';
import { IntegrationTestHelper } from './IntegrationTestHelper';
import { NamespacePaginationStreamer } from '../../src/infrastructure/paginationStreamer/NamespacePaginationStreamer';
import { take, toArray } from 'rxjs/operators';
import { Order } from '../../src/infrastructure';
describe('NamespaceHttp', () => {
let defaultNamespaceId: NamespaceId;
let namespaceId: NamespaceId;
let namespaceRepository: NamespaceRepository;
let account: Account;
let generationHash: string;
const helper = new IntegrationTestHelper();
const epochAdjustment = 1573430400;
before(() => {
return helper.start({ openListener: true }).then(() => {
account = helper.account;
generationHash = helper.generationHash;
namespaceRepository = helper.repositoryFactory.createNamespaceRepository();
defaultNamespaceId = helper.networkCurrency.namespaceId!;
});
});
after(() => {
return helper.close();
});
describe('NamespaceRegistrationTransaction', () => {
it('standalone', () => {
const namespaceName = 'root-test-namespace-' + Math.floor(Math.random() * 10000);
const registerNamespaceTransaction = NamespaceRegistrationTransaction.createRootNamespace(
Deadline.create(epochAdjustment),
namespaceName,
UInt64.fromUint(1000),
helper.networkType,
helper.maxFee,
);
namespaceId = new NamespaceId(namespaceName);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
return helper.announce(signedTransaction);
});
});
describe('AddressAliasTransaction', () => {
it('standalone', () => {
const addressAliasTransaction = AddressAliasTransaction.create(
Deadline.create(epochAdjustment),
AliasAction.Link,
namespaceId,
account.address,
helper.networkType,
helper.maxFee,
);
const signedTransaction = addressAliasTransaction.signWith(account, generationHash);
return helper.announce(signedTransaction);
});
});
describe('getNamespace', () => {
it('should return namespace data given namepsaceId', async () => {
const namespace = await namespaceRepository.getNamespace(defaultNamespaceId).toPromise();
expect(namespace.startHeight.lower).to.be.equal(1);
expect(namespace.startHeight.higher).to.be.equal(0);
});
});
describe('getNamespacesName', () => {
it('should return namespace name given array of namespaceIds', async () => {
const namespaceNames = await namespaceRepository.getNamespacesNames([defaultNamespaceId]).toPromise();
expect(namespaceNames[0].name).to.be.equal('currency');
});
});
describe('getLinkedMosaicId', () => {
it('should return mosaicId given currency namespaceId', async () => {
const mosaicId = await namespaceRepository.getLinkedMosaicId(defaultNamespaceId).toPromise();
expect(mosaicId).to.not.be.null;
});
});
describe('getLinkedAddress', () => {
it('should return address given namespaceId', async () => {
const address = (await namespaceRepository.getLinkedAddress(namespaceId).toPromise()) as Address;
expect(address.plain()).to.be.equal(account.address.plain());
});
});
describe('searchNamespace', () => {
it('should return namespace info', async () => {
const info = await namespaceRepository.search({ ownerAddress: account.address }).toPromise();
expect(info.data.length).to.be.greaterThan(0);
});
});
describe('searchNamespace with streamer', () => {
it('should return namespace info', async () => {
const streamer = new NamespacePaginationStreamer(namespaceRepository);
const infoStreamer = await streamer
.search({ ownerAddress: account.address, pageSize: 20, order: Order.Desc })
.pipe(take(20), toArray())
.toPromise();
const info = await namespaceRepository.search({ pageSize: 20, order: Order.Desc }).toPromise();
expect(infoStreamer.length).to.be.greaterThan(0);
deepEqual(infoStreamer[0], info.data[0]);
});
});
});