1414 * limitations under the License.
1515 */
1616import { deepEqual } from 'assert' ;
17- import { expect } from 'chai' ;
17+ import { expect , assert } from 'chai' ;
1818import { NamespaceHttp } from '../../src/infrastructure/NamespaceHttp' ;
1919import { PublicAccount } from '../../src/model/account/PublicAccount' ;
2020import { NetworkType } from '../../src/model/blockchain/NetworkType' ;
2121import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic' ;
2222import { NamespaceId } from '../../src/model/namespace/NamespaceId' ;
23+ import { TransactionHttp } from '../../src/infrastructure/TransactionHttp' ;
24+ import { Listener } from '../../src/infrastructure/infrastructure' ;
25+ import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction' ;
26+ import { Deadline } from '../../src/model/transaction/Deadline' ;
27+ import { AliasActionType } from '../../src/model/namespace/AliasActionType' ;
28+ import { Account } from '../../src/model/account/Account' ;
29+ import { RegisterNamespaceTransaction } from '../../src/model/transaction/RegisterNamespaceTransaction' ;
30+ import { UInt64 } from '../../src/model/UInt64' ;
2331
2432describe ( 'NamespaceHttp' , ( ) => {
2533 const defaultNamespaceId = NetworkCurrencyMosaic . NAMESPACE_ID ;
2634 let namespaceId : NamespaceId ;
2735 let namespaceHttp : NamespaceHttp ;
28- let publicAccount : PublicAccount ;
36+ let account : Account ;
2937 let namespaceLinkedAddress : string ;
38+ let config ;
39+ let transactionHttp : TransactionHttp ;
3040 before ( ( done ) => {
3141 const path = require ( 'path' ) ;
3242 require ( 'fs' ) . readFile ( path . resolve ( __dirname , '../conf/network.conf' ) , ( err , data ) => {
3343 if ( err ) {
3444 throw err ;
3545 }
3646 const json = JSON . parse ( data ) ;
37- publicAccount = PublicAccount . createFromPublicKey ( json . testAccount . publicKey , NetworkType . MIJIN_TEST ) ;
47+ config = json ;
48+ account = Account . createFromPrivateKey ( json . testAccount . privateKey , NetworkType . MIJIN_TEST ) ;
3849 namespaceId = new NamespaceId ( json . namespace . id ) ;
3950 namespaceLinkedAddress = json . namespace . linkedAddress ;
4051 namespaceHttp = new NamespaceHttp ( json . apiUrl ) ;
52+ transactionHttp = new TransactionHttp ( json . apiUrl ) ;
4153 done ( ) ;
4254 } ) ;
4355 } ) ;
56+ describe ( 'RegisterNamespaceTransaction' , ( ) => {
57+ let listener : Listener ;
58+ before ( ( ) => {
59+ listener = new Listener ( config . apiUrl ) ;
60+ return listener . open ( ) ;
61+ } ) ;
62+ after ( ( ) => {
63+ return listener . close ( ) ;
64+ } ) ;
65+ it ( 'standalone' , ( done ) => {
66+ const namespaceName = 'root-test-namespace-' + Math . floor ( Math . random ( ) * 10000 ) ;
67+ const registerNamespaceTransaction = RegisterNamespaceTransaction . createRootNamespace (
68+ Deadline . create ( ) ,
69+ namespaceName ,
70+ UInt64 . fromUint ( 1000 ) ,
71+ NetworkType . MIJIN_TEST ,
72+ ) ;
73+ namespaceId = new NamespaceId ( namespaceName ) ;
74+ const signedTransaction = registerNamespaceTransaction . signWith ( account ) ;
75+ listener . confirmed ( account . address ) . subscribe ( ( transaction ) => {
76+ done ( ) ;
77+ } ) ;
78+ listener . status ( account . address ) . subscribe ( ( error ) => {
79+ console . log ( 'Error:' , error ) ;
80+ assert ( false ) ;
81+ done ( ) ;
82+ } ) ;
83+ transactionHttp . announce ( signedTransaction ) ;
84+ } ) ;
85+ } ) ;
86+ describe ( 'AddressAliasTransaction' , ( ) => {
87+ let listener : Listener ;
88+ before ( ( ) => {
89+ listener = new Listener ( config . apiUrl ) ;
90+ return listener . open ( ) ;
91+ } ) ;
92+ after ( ( ) => {
93+ return listener . close ( ) ;
94+ } ) ;
95+
96+ it ( 'standalone' , ( done ) => {
97+ const addressAliasTransaction = AddressAliasTransaction . create (
98+ Deadline . create ( ) ,
99+ AliasActionType . Link ,
100+ namespaceId ,
101+ account . address ,
102+ NetworkType . MIJIN_TEST
103+ ) ;
104+ const signedTransaction = addressAliasTransaction . signWith ( account ) ;
105+
106+ listener . confirmed ( account . address ) . subscribe ( ( transaction ) => {
107+ done ( ) ;
108+ } ) ;
109+ listener . status ( account . address ) . subscribe ( ( error ) => {
110+ console . log ( 'Error:' , error ) ;
111+ assert ( false ) ;
112+ done ( ) ;
113+ } ) ;
114+ transactionHttp . announce ( signedTransaction ) ;
115+ } ) ;
116+ } ) ;
44117
45118 describe ( 'getNamespace' , ( ) => {
46119 it ( 'should return namespace data given namepsaceId' , ( done ) => {
@@ -55,19 +128,19 @@ describe('NamespaceHttp', () => {
55128
56129 describe ( 'getNamespacesFromAccount' , ( ) => {
57130 it ( 'should return namespace data given publicKeyNemesis' , ( done ) => {
58- namespaceHttp . getNamespacesFromAccount ( publicAccount . address )
131+ namespaceHttp . getNamespacesFromAccount ( account . address )
59132 . subscribe ( ( namespaces ) => {
60- deepEqual ( namespaces [ 0 ] . owner , publicAccount ) ;
133+ deepEqual ( namespaces [ 0 ] . owner , account . publicAccount ) ;
61134 done ( ) ;
62135 } ) ;
63136 } ) ;
64137 } ) ;
65138
66139 describe ( 'getNamespacesFromAccounts' , ( ) => {
67140 it ( 'should return namespaces data given publicKeyNemesis' , ( done ) => {
68- namespaceHttp . getNamespacesFromAccounts ( [ publicAccount . address ] )
141+ namespaceHttp . getNamespacesFromAccounts ( [ account . address ] )
69142 . subscribe ( ( namespaces ) => {
70- deepEqual ( namespaces [ 0 ] . owner , publicAccount ) ;
143+ deepEqual ( namespaces [ 0 ] . owner , account . publicAccount ) ;
71144 done ( ) ;
72145 } ) ;
73146 } ) ;
0 commit comments