11import { expect } from 'chai' ;
22import { KeyGenerator } from '../../src/core/format/KeyGenerator' ;
3+ import { NamespaceRepository } from '../../src/infrastructure/NamespaceRepository' ;
34import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRepository' ;
45import { Account } from '../../src/model/account/Account' ;
56import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
67import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags' ;
78import { MosaicId } from '../../src/model/mosaic/MosaicId' ;
89import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce' ;
10+ import { AliasAction } from '../../src/model/namespace/AliasAction' ;
11+ import { NamespaceId } from '../../src/model/namespace/NamespaceId' ;
912import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType' ;
13+ import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction' ;
1014import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction' ;
1115import { Deadline } from '../../src/model/transaction/Deadline' ;
1216import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction' ;
17+ import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction' ;
1318import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction' ;
1419import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction' ;
20+ import { NamespaceRegistrationTransaction } from '../../src/model/transaction/NamespaceRegistrationTransaction' ;
1521import { TransactionType } from '../../src/model/transaction/TransactionType' ;
1622import { UInt64 } from '../../src/model/UInt64' ;
1723import { MosaicRestrictionTransactionService } from '../../src/service/MosaicRestrictionTransactionService' ;
@@ -22,17 +28,21 @@ describe('MosaicRestrictionTransactionService', () => {
2228 const key = KeyGenerator . generateUInt64Key ( 'TestKey' ) ;
2329 let account : Account ;
2430 let restrictionRepository : RestrictionMosaicRepository ;
31+ let namespaceRepository : NamespaceRepository ;
2532 let mosaicId : MosaicId ;
2633 let generationHash : string ;
2734 const helper = new IntegrationTestHelper ( ) ;
2835 let networkType : NetworkType ;
36+ let namespaceIdAddress : NamespaceId ;
37+ let namespaceIdMosaic : NamespaceId ;
2938
3039 before ( ( ) => {
3140 return helper . start ( ) . then ( ( ) => {
3241 account = helper . account ;
3342 generationHash = helper . generationHash ;
3443 networkType = helper . networkType ;
3544 restrictionRepository = helper . repositoryFactory . createRestrictionMosaicRepository ( ) ;
45+ namespaceRepository = helper . repositoryFactory . createNamespaceRepository ( ) ;
3646 } ) ;
3747 } ) ;
3848
@@ -64,6 +74,7 @@ describe('MosaicRestrictionTransactionService', () => {
6474 UInt64 . fromUint ( 1000 ) ,
6575 networkType , helper . maxFee ,
6676 ) ;
77+ console . log ( mosaicId . toHex ( ) ) ;
6778 const signedTransaction = mosaicDefinitionTransaction . signWith ( account , generationHash ) ;
6879 return helper . announce ( signedTransaction ) ;
6980 } ) ;
@@ -99,6 +110,7 @@ describe('MosaicRestrictionTransactionService', () => {
99110 account . address ,
100111 UInt64 . fromUint ( 2 ) ,
101112 networkType ,
113+ undefined ,
102114 helper . maxFee ,
103115 ) ;
104116 const aggregateTransaction = AggregateTransaction . createComplete ( Deadline . create ( ) ,
@@ -111,14 +123,80 @@ describe('MosaicRestrictionTransactionService', () => {
111123 } ) ;
112124 } ) ;
113125
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+
114192 /**
115193 * =========================
116194 * Test
117195 * =========================
118196 */
119- describe ( 'Test new services' , ( ) => {
197+ describe ( 'Test new services - MosaicGlobalRestriction ' , ( ) => {
120198 it ( 'should create MosaicGlobalRestrictionTransaction' , ( done ) => {
121- const service = new MosaicRestrictionTransactionService ( restrictionRepository ) ;
199+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
122200
123201 return service . createMosaicGlobalRestrictionTransaction (
124202 deadline ,
@@ -137,9 +215,33 @@ describe('MosaicRestrictionTransactionService', () => {
137215 done ( ) ;
138216 } ) ;
139217 } ) ;
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+ } ) ;
142241
242+ describe ( 'Test new services - MosaicAddressRestriction' , ( ) => {
243+ it ( 'should create MosaicAddressRestrictionTransaction' , ( done ) => {
244+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
143245 return service . createMosaicAddressRestrictionTransaction (
144246 deadline ,
145247 networkType ,
@@ -159,10 +261,33 @@ describe('MosaicRestrictionTransactionService', () => {
159261 } ) ;
160262 } ) ;
161263
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+
162287 describe ( 'Announce MosaicGlobalRestriction through service' , ( ) => {
163288
164289 it ( 'should create MosaicGlobalRestriction and announce' , ( done ) => {
165- const service = new MosaicRestrictionTransactionService ( restrictionRepository ) ;
290+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
166291 service . createMosaicGlobalRestrictionTransaction (
167292 deadline ,
168293 networkType ,
@@ -188,7 +313,7 @@ describe('MosaicRestrictionTransactionService', () => {
188313 describe ( 'Announce MosaicAddressRestriction through service' , ( ) => {
189314
190315 it ( 'should create MosaicAddressRestriction and announce' , ( done ) => {
191- const service = new MosaicRestrictionTransactionService ( restrictionRepository ) ;
316+ const service = new MosaicRestrictionTransactionService ( restrictionRepository , namespaceRepository ) ;
192317
193318 return service . createMosaicAddressRestrictionTransaction (
194319 deadline ,
0 commit comments