@@ -64,6 +64,15 @@ describe('handleStop', () => {
64
64
outputs : [ ] ,
65
65
} ) ;
66
66
await storage . registerToken ( testToken ) ;
67
+ const address0 = await storage . getAddressAtIndex ( 0 ) ;
68
+ const address1 = await storage . getAddressAtIndex ( 1 ) ;
69
+ const testNano = {
70
+ ncId : 'abc' ,
71
+ address : address0 . base58 ,
72
+ blueprintId : 'blueprintId' ,
73
+ blueprintName : 'blueprintName' ,
74
+ } ;
75
+ await storage . registerNanoContract ( 'abc' , testNano ) ;
67
76
// We have 1 transaction
68
77
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
69
78
// 20 addresses
@@ -72,6 +81,20 @@ describe('handleStop', () => {
72
81
let tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
73
82
expect ( tokens ) . toHaveLength ( 1 ) ;
74
83
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
84
+ // And 1 registered nano contract
85
+ let nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
86
+ expect ( nanos ) . toHaveLength ( 1 ) ;
87
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
88
+
89
+ // Test address update
90
+ await expect ( store . getNanoContract ( 'abc' ) ) . resolves . toMatchObject ( { address : address0 . base58 } ) ;
91
+ await storage . updateNanoContractRegisteredAddress ( 'abc' , address1 . base58 ) ;
92
+ await expect ( store . getNanoContract ( 'abc' ) ) . resolves . toMatchObject ( { address : address1 . base58 } ) ;
93
+
94
+ await expect ( storage . updateNanoContractRegisteredAddress ( 'abc' , 'abc' ) ) . rejects . toThrow ( Error ) ;
95
+
96
+ // Go back to default address
97
+ await storage . updateNanoContractRegisteredAddress ( 'abc' , address0 . base58 ) ;
75
98
76
99
storage . version = 'something' ;
77
100
// handleStop with defaults
@@ -82,19 +105,27 @@ describe('handleStop', () => {
82
105
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
83
106
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 20 ) ;
84
107
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeTruthy ( ) ;
108
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeTruthy ( ) ;
85
109
tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
86
110
expect ( tokens ) . toHaveLength ( 1 ) ;
87
111
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
112
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
113
+ expect ( nanos ) . toHaveLength ( 1 ) ;
114
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
88
115
89
116
// handleStop with cleanStorage = true
90
117
await storage . handleStop ( { cleanStorage : true } ) ;
91
118
// Will clean the history bit not addresses or registered tokens
92
119
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 0 ) ;
93
120
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 20 ) ;
94
121
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeTruthy ( ) ;
122
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeTruthy ( ) ;
95
123
tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
96
124
expect ( tokens ) . toHaveLength ( 1 ) ;
97
125
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
126
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
127
+ expect ( nanos ) . toHaveLength ( 1 ) ;
128
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
98
129
99
130
await storage . addTx ( {
100
131
tx_id : 'another-new-tx' ,
@@ -109,9 +140,13 @@ describe('handleStop', () => {
109
140
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
110
141
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 0 ) ;
111
142
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeTruthy ( ) ;
143
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeTruthy ( ) ;
112
144
tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
113
145
expect ( tokens ) . toHaveLength ( 1 ) ;
114
146
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
147
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
148
+ expect ( nanos ) . toHaveLength ( 1 ) ;
149
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
115
150
116
151
// handleStop with cleanAddresses = true
117
152
await loadAddresses ( 0 , 20 , storage ) ;
@@ -120,6 +155,12 @@ describe('handleStop', () => {
120
155
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
121
156
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 20 ) ;
122
157
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeFalsy ( ) ;
158
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeFalsy ( ) ;
159
+
160
+ tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
161
+ expect ( tokens ) . toHaveLength ( 0 ) ;
162
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
163
+ expect ( nanos ) . toHaveLength ( 0 ) ;
123
164
124
165
// Access data is untouched when stopping the wallet
125
166
// XXX: since we stringify to save on store, the optional undefined properties are removed
0 commit comments