1
1
import { expect } from 'chai' ;
2
2
import { KeyGenerator } from '../../src/core/format/KeyGenerator' ;
3
+ import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository' ;
3
4
import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRepository' ;
4
5
import { Account } from '../../src/model/account/Account' ;
5
6
import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
6
7
import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags' ;
7
8
import { MosaicId } from '../../src/model/mosaic/MosaicId' ;
8
9
import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce' ;
10
+ import { AliasAction } from '../../src/model/namespace/AliasAction' ;
11
+ import { NamespaceId } from '../../src/model/namespace/NamespaceId' ;
9
12
import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType' ;
13
+ import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction' ;
10
14
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction' ;
11
15
import { Deadline } from '../../src/model/transaction/Deadline' ;
12
16
import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction' ;
17
+ import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction' ;
13
18
import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction' ;
14
19
import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction' ;
20
+ import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction' ;
15
21
import { TransactionType } from '../../src/model/transaction/TransactionType' ;
16
22
import { UInt64 } from '../../src/model/UInt64' ;
17
23
import { MosaicRestrictionTransactionService } from '../../src/service/MosaicRestrictionTransactionService' ;
@@ -22,17 +28,21 @@ describe('MosaicRestrictionTransactionService', () => {
22
28
const key = KeyGenerator . generateUInt64Key ( 'TestKey' ) ;
23
29
let account : Account ;
24
30
let restrictionRepository : RestrictionMosaicRepository ;
31
+ let namespaceRepository : NamespaceRepository ;
25
32
let mosaicId : MosaicId ;
26
33
let generationHash : string ;
27
34
const helper = new IntegrationTestHelper ( ) ;
28
35
let networkType : NetworkType ;
36
+ let namespaceIdAddress : NamespaceId ;
37
+ let namespaceIdMosaic : NamespaceId ;
29
38
30
39
before ( ( ) => {
31
40
return helper . start ( ) . then ( ( ) => {
32
41
account = helper . account ;
33
42
generationHash = helper . generationHash ;
34
43
networkType = helper . networkType ;
35
44
restrictionRepository = helper . repositoryFactory . createRestrictionMosaicRepository ( ) ;
45
+ namespaceRepository = helper . repositoryFactory . createNamespaceRepository ( ) ;
36
46
} ) ;
37
47
} ) ;
38
48
@@ -64,6 +74,7 @@ describe('MosaicRestrictionTransactionService', () => {
64
74
UInt64 . fromUint ( 1000 ) ,
65
75
networkType , helper . maxFee ,
66
76
) ;
77
+ console . log ( mosaicId . toHex ( ) ) ;
67
78
const signedTransaction = mosaicDefinitionTransaction . signWith ( account , generationHash ) ;
68
79
return helper . announce ( signedTransaction ) ;
69
80
} ) ;
@@ -99,6 +110,7 @@ describe('MosaicRestrictionTransactionService', () => {
99
110
account . address ,
100
111
UInt64 . fromUint ( 2 ) ,
101
112
networkType ,
113
+ undefined ,
102
114
helper . maxFee ,
103
115
) ;
104
116
const aggregateTransaction = AggregateTransaction . createComplete ( Deadline . create ( ) ,
@@ -111,14 +123,80 @@ describe('MosaicRestrictionTransactionService', () => {
111
123
} ) ;
112
124
} ) ;
113
125
126
+ describe ( 'NamespaceRegistrationTransaction' , ( ) => {
127
+
128
+ it ( 'standalone' , ( ) => {
129
+ const namespaceName = 'root-test-namespace-' + Math . floor ( Math . random ( ) * 10000 ) ;
130
+ const registerNamespaceTransaction = NamespaceRegistrationTransaction . createRootNamespace (
131
+ Deadline . create ( ) ,
132
+ namespaceName ,
133
+ UInt64 . fromUint ( 50 ) ,
134
+ networkType , helper . maxFee ,
135
+ ) ;
136
+ namespaceIdMosaic = new NamespaceId ( namespaceName ) ;
137
+ const signedTransaction = registerNamespaceTransaction . signWith ( account , generationHash ) ;
138
+
139
+ return helper . announce ( signedTransaction ) ;
140
+ } ) ;
141
+ } ) ;
142
+
143
+ describe ( 'NamespaceRegistrationTransaction' , ( ) => {
144
+
145
+ it ( 'standalone' , ( ) => {
146
+ const namespaceName = 'root-test-namespace-' + Math . floor ( Math . random ( ) * 10000 ) ;
147
+ const registerNamespaceTransaction = NamespaceRegistrationTransaction . createRootNamespace (
148
+ Deadline . create ( ) ,
149
+ namespaceName ,
150
+ UInt64 . fromUint ( 50 ) ,
151
+ networkType , helper . maxFee ,
152
+ ) ;
153
+ namespaceIdAddress = new NamespaceId ( namespaceName ) ;
154
+ const signedTransaction = registerNamespaceTransaction . signWith ( account , generationHash ) ;
155
+
156
+ return helper . announce ( signedTransaction ) ;
157
+ } ) ;
158
+ } ) ;
159
+
160
+ describe ( 'AddressAliasTransaction' , ( ) => {
161
+
162
+ it ( 'standalone' , ( ) => {
163
+ const addressAliasTransaction = AddressAliasTransaction . create (
164
+ Deadline . create ( ) ,
165
+ AliasAction . Link ,
166
+ namespaceIdAddress ,
167
+ account . address ,
168
+ networkType , helper . maxFee ,
169
+ ) ;
170
+ const signedTransaction = addressAliasTransaction . signWith ( account , generationHash ) ;
171
+
172
+ return helper . announce ( signedTransaction ) ;
173
+ } ) ;
174
+ } ) ;
175
+
176
+ describe ( 'MosaicAliasTransaction' , ( ) => {
177
+
178
+ it ( 'standalone' , ( ) => {
179
+ const mosaicAliasTransaction = MosaicAliasTransaction . create (
180
+ Deadline . create ( ) ,
181
+ AliasAction . Link ,
182
+ namespaceIdMosaic ,
183
+ mosaicId ,
184
+ networkType , helper . maxFee ,
185
+ ) ;
186
+ const signedTransaction = mosaicAliasTransaction . signWith ( account , generationHash ) ;
187
+
188
+ return helper . announce ( signedTransaction ) ;
189
+ } ) ;
190
+ } ) ;
191
+
114
192
/**
115
193
* =========================
116
194
* Test
117
195
* =========================
118
196
*/
119
- describe ( 'Test new services' , ( ) => {
197
+ describe ( 'Test new services - MosaicGlobalRestriction ' , ( ) => {
120
198
it ( 'should create MosaicGlobalRestrictionTransaction' , ( done ) => {
121
- const service = new MosaicRestrictionTransactionService ( restrictionRepository ) ;
199
+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
122
200
123
201
return service . createMosaicGlobalRestrictionTransaction (
124
202
deadline ,
@@ -137,9 +215,33 @@ describe('MosaicRestrictionTransactionService', () => {
137
215
done ( ) ;
138
216
} ) ;
139
217
} ) ;
140
- it ( 'should create MosaicAddressRestrictionTransaction' , ( done ) => {
141
- const service = new MosaicRestrictionTransactionService ( restrictionRepository ) ;
218
+ } ) ;
219
+
220
+ describe ( 'Test new services - MosaicGlobalRestriction' , ( ) => {
221
+ it ( 'should create MosaicGlobalRestrictionTransaction using alias' , ( done ) => {
222
+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
223
+ return service . createMosaicGlobalRestrictionTransaction (
224
+ deadline ,
225
+ networkType ,
226
+ namespaceIdMosaic ,
227
+ key ,
228
+ '2' ,
229
+ MosaicRestrictionType . GE , undefined , helper . maxFee ,
230
+ ) . subscribe ( ( transaction : MosaicGlobalRestrictionTransaction ) => {
231
+ expect ( transaction . type ) . to . be . equal ( TransactionType . MOSAIC_GLOBAL_RESTRICTION ) ;
232
+ expect ( transaction . previousRestrictionValue . toString ( ) ) . to . be . equal ( '1' ) ;
233
+ expect ( transaction . previousRestrictionType ) . to . be . equal ( MosaicRestrictionType . GE ) ;
234
+ expect ( transaction . newRestrictionValue . toString ( ) ) . to . be . equal ( '2' ) ;
235
+ expect ( transaction . newRestrictionType ) . to . be . equal ( MosaicRestrictionType . GE ) ;
236
+ expect ( transaction . restrictionKey . toHex ( ) ) . to . be . equal ( key . toHex ( ) ) ;
237
+ done ( ) ;
238
+ } ) ;
239
+ } ) ;
240
+ } ) ;
142
241
242
+ describe ( 'Test new services - MosaicAddressRestriction' , ( ) => {
243
+ it ( 'should create MosaicAddressRestrictionTransaction' , ( done ) => {
244
+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
143
245
return service . createMosaicAddressRestrictionTransaction (
144
246
deadline ,
145
247
networkType ,
@@ -159,10 +261,33 @@ describe('MosaicRestrictionTransactionService', () => {
159
261
} ) ;
160
262
} ) ;
161
263
264
+ describe ( 'Test new services - MosaicAddressRestriction' , ( ) => {
265
+ it ( 'should create MosaicAddressRestrictionTransaction with address alias' , ( done ) => {
266
+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
267
+
268
+ return service . createMosaicAddressRestrictionTransaction (
269
+ deadline ,
270
+ networkType ,
271
+ mosaicId ,
272
+ key ,
273
+ namespaceIdAddress ,
274
+ '4' ,
275
+ helper . maxFee ,
276
+ ) . subscribe ( ( transaction : MosaicAddressRestrictionTransaction ) => {
277
+ expect ( transaction . type ) . to . be . equal ( TransactionType . MOSAIC_ADDRESS_RESTRICTION ) ;
278
+ expect ( transaction . previousRestrictionValue . toString ( ) ) . to . be . equal ( '3' ) ;
279
+ expect ( transaction . newRestrictionValue . toString ( ) ) . to . be . equal ( '4' ) ;
280
+ expect ( transaction . targetAddressToString ( ) ) . to . be . equal ( account . address . plain ( ) ) ;
281
+ expect ( transaction . restrictionKey . toHex ( ) ) . to . be . equal ( key . toHex ( ) ) ;
282
+ done ( ) ;
283
+ } ) ;
284
+ } ) ;
285
+ } ) ;
286
+
162
287
describe ( 'Announce MosaicGlobalRestriction through service' , ( ) => {
163
288
164
289
it ( 'should create MosaicGlobalRestriction and announce' , ( done ) => {
165
- const service = new MosaicRestrictionTransactionService ( restrictionRepository ) ;
290
+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
166
291
service . createMosaicGlobalRestrictionTransaction (
167
292
deadline ,
168
293
networkType ,
@@ -188,7 +313,7 @@ describe('MosaicRestrictionTransactionService', () => {
188
313
describe ( 'Announce MosaicAddressRestriction through service' , ( ) => {
189
314
190
315
it ( 'should create MosaicAddressRestriction and announce' , ( done ) => {
191
- const service = new MosaicRestrictionTransactionService ( restrictionRepository ) ;
316
+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
192
317
193
318
return service . createMosaicAddressRestrictionTransaction (
194
319
deadline ,
0 commit comments