11import NetworksService from '../../src/services/networks'
22import { NetworkWithID } from '../../src/types/network'
3- import env from '../../src/env'
43import i18n from '../../src/utils/i18n'
54
65const ERROR_MESSAGE = {
@@ -9,23 +8,19 @@ const ERROR_MESSAGE = {
98 NETWORK_ID_NOT_FOUND : `messages.network-not-found` ,
109}
1110
12- const {
13- presetNetworks : { current, list } ,
14- } = env
15- const [ testnetNetwork , localNetwork ] = list
16-
1711describe ( `Unit tests of networks service` , ( ) => {
1812 const newNetwork : NetworkWithID = {
1913 name : `new network` ,
20- remote : `http://new-network. localhost.com ` ,
14+ remote : `http://localhost:8114 ` ,
2115 type : 0 ,
16+ genesisHash : '' ,
2217 id : '' ,
2318 chain : '' ,
2419 }
2520
2621 const newNetworkWithDefaultTypeOf1 = {
2722 name : `new network with the default type of 1` ,
28- remote : `http://test. localhost.com ` ,
23+ remote : `http://localhost:8114 ` ,
2924 id : '' ,
3025 }
3126
@@ -52,28 +47,18 @@ describe(`Unit tests of networks service`, () => {
5247
5348 it ( `has preset networks` , async ( ) => {
5449 const networks = await service . getAll ( )
55- expect ( networks ) . toEqual ( list )
50+ expect ( networks . length ) . toBe ( 1 )
51+ expect ( networks [ 0 ] . id ) . toEqual ( 'mainnet' )
5652 } )
5753
5854 it ( `get the default network` , async ( ) => {
5955 const network = await service . defaultOne ( )
6056 expect ( network && network . type ) . toBe ( 0 )
6157 } )
6258
63- it ( `testnet should be type of default network` , async ( ) => {
64- const defaultNetwork = await service . defaultOne ( )
65- expect ( defaultNetwork ) . toEqual ( testnetNetwork )
66- } )
67-
68- it ( `testnet should be the current one by default` , async ( ) => {
59+ it ( `mainnet should be the current one by default` , async ( ) => {
6960 const currentNetworkID = await service . getCurrentID ( )
70- expect ( currentNetworkID ) . toBe ( current )
71- expect ( currentNetworkID ) . toBe ( testnetNetwork . id )
72- } )
73-
74- it ( `get network by id ${ current } ` , async ( ) => {
75- const currentNetwork = await service . get ( current )
76- expect ( currentNetwork ) . toEqual ( list . find ( network => network . id === current ) )
61+ expect ( currentNetworkID ) . toBe ( 'mainnet' )
7762 } )
7863
7964 it ( `getting a non-exsiting network should return null` , async ( ) => {
@@ -94,35 +79,31 @@ describe(`Unit tests of networks service`, () => {
9479 expect ( res . type ) . toBe ( 1 )
9580 } )
9681
97- it ( `update the local networks's name` , async ( ) => {
98- const name = `new local network name`
99- await service . update ( localNetwork . id , { name } )
100- const network = await service . get ( localNetwork . id )
101- expect ( network && network . name ) . toBe ( name )
102- } )
103-
104- it ( `update the local network address` , async ( ) => {
105- const addr = `http://updated-address.com`
106- await service . update ( localNetwork . id , { remote : addr } )
107- const network = await service . get ( localNetwork . id )
108- expect ( network && network . remote ) . toBe ( addr )
82+ it ( `update the networks's name` , async ( ) => {
83+ const network = await service . create ( newNetworkWithDefaultTypeOf1 . name , newNetworkWithDefaultTypeOf1 . remote )
84+ const name = `new network name`
85+ await service . update ( network . id , { name } )
86+ const updated = await service . get ( network . id )
87+ expect ( updated && updated . name ) . toBe ( name )
10988 } )
11089
111- it ( `update the local network type to 1` , async ( ) => {
112- const type = 1
113- await service . update ( localNetwork . id , { type } )
114- const network = await service . get ( localNetwork . id )
115- expect ( network && network . type ) . toBe ( type )
90+ it ( `update the network' address` , async ( ) => {
91+ const network = await service . create ( newNetworkWithDefaultTypeOf1 . name , newNetworkWithDefaultTypeOf1 . remote )
92+ const address = `http://localhost:8115`
93+ await service . update ( network . id , { remote : address } )
94+ const updated = await service . get ( network . id )
95+ expect ( updated && updated . remote ) . toBe ( address )
11696 } )
11797
118- it ( `set the local network to be the current one` , async ( ) => {
119- await service . activate ( localNetwork . id )
98+ it ( `set the network to be the current one` , async ( ) => {
99+ const network = await service . create ( newNetworkWithDefaultTypeOf1 . name , newNetworkWithDefaultTypeOf1 . remote )
100+ await service . activate ( network . id )
120101 const currentNetworkID = await service . getCurrentID ( )
121- expect ( currentNetworkID ) . toBe ( localNetwork . id )
102+ expect ( currentNetworkID ) . toBe ( network . id )
122103 } )
123104
124105 it ( `delete an inactive network` , async ( ) => {
125- const inactiveNetwork = localNetwork
106+ const inactiveNetwork = await service . create ( newNetworkWithDefaultTypeOf1 . name , newNetworkWithDefaultTypeOf1 . remote )
126107 const prevCurrentID = ( await service . getCurrentID ( ) ) || ''
127108 const prevNetworks = await service . getAll ( )
128109 await service . delete ( inactiveNetwork . id )
@@ -134,12 +115,13 @@ describe(`Unit tests of networks service`, () => {
134115 expect ( currentID ) . toBe ( prevCurrentID )
135116 } )
136117
137- it ( `activate the local network and delete it, the current networks should switch to the testnet network` , async ( ) => {
138- await service . activate ( localNetwork . id )
118+ it ( `activate a network and delete it, the current networks should switch to the default network` , async ( ) => {
119+ const network = await service . create ( newNetworkWithDefaultTypeOf1 . name , newNetworkWithDefaultTypeOf1 . remote )
120+ await service . activate ( network . id )
139121 const prevCurrentID = await service . getCurrentID ( )
140122 const prevNetworks = await service . getAll ( )
141- expect ( prevCurrentID ) . toBe ( localNetwork . id )
142- expect ( prevNetworks . map ( n => n . id ) ) . toEqual ( list . map ( n => n . id ) )
123+ expect ( prevCurrentID ) . toBe ( network . id )
124+ expect ( prevNetworks . map ( n => n . id ) ) . toEqual ( [ 'Mainnet' , network . id ] )
143125 await service . delete ( prevCurrentID || '' )
144126 const currentNetworks = await service . getAll ( )
145127 expect ( currentNetworks . map ( n => n . id ) ) . toEqual ( prevNetworks . filter ( n => n . id !== prevCurrentID ) . map ( n => n . id ) )
@@ -148,16 +130,16 @@ describe(`Unit tests of networks service`, () => {
148130 service . getCurrentID ( ) . then ( cID => resolve ( cID ) )
149131 } , 500 )
150132 } )
151- expect ( currentID ) . toBe ( testnetNetwork . id )
133+ expect ( currentID ) . toBe ( 'mainnet' )
152134 } )
153135
154136 it ( `reset the netowrks` , async ( ) => {
155137 await service . create ( newNetwork . name , newNetwork . remote )
156138 const newNetworkList = await service . getAll ( )
157- expect ( newNetworkList . length ) . toBe ( list . length + 1 )
139+ expect ( newNetworkList . length ) . toBe ( 2 )
158140 service . clear ( )
159141 const networks = await service . getAll ( )
160- expect ( networks . length ) . toBe ( list . length )
142+ expect ( networks . length ) . toBe ( 1 )
161143 } )
162144 } )
163145
@@ -192,8 +174,8 @@ describe(`Unit tests of networks service`, () => {
192174 } )
193175
194176 describe ( `validation on network existence` , ( ) => {
195- it ( `create network with existing name of ${ list [ 0 ] . name } ` , ( ) => {
196- expect ( service . create ( list [ 0 ] . name , list [ 0 ] . remote ) ) . rejects . toThrowError ( i18n . t ( ERROR_MESSAGE . NAME_USED ) )
177+ it ( `create network with existing name of Mainnet ` , ( ) => {
178+ expect ( service . create ( 'Mainnet' , 'http://localhost:8114' ) ) . rejects . toThrowError ( i18n . t ( ERROR_MESSAGE . NAME_USED ) )
197179 } )
198180
199181 it ( `update network which is not existing` , ( ) => {
0 commit comments