@@ -64,6 +64,13 @@ describe('handleStop', () => {
64
64
outputs : [ ] ,
65
65
} ) ;
66
66
await storage . registerToken ( testToken ) ;
67
+ const testNano = {
68
+ ncId : 'abc' ,
69
+ address : 'nanoAddress' ,
70
+ blueprintId : 'blueprintId' ,
71
+ blueprintName : 'blueprintName' ,
72
+ } ;
73
+ await storage . registerNanoContract ( 'abc' , testNano ) ;
67
74
// We have 1 transaction
68
75
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
69
76
// 20 addresses
@@ -72,6 +79,10 @@ describe('handleStop', () => {
72
79
let tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
73
80
expect ( tokens ) . toHaveLength ( 1 ) ;
74
81
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
82
+ // And 1 registered nano contract
83
+ let nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
84
+ expect ( nanos ) . toHaveLength ( 1 ) ;
85
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
75
86
76
87
storage . version = 'something' ;
77
88
// handleStop with defaults
@@ -82,19 +93,27 @@ describe('handleStop', () => {
82
93
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
83
94
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 20 ) ;
84
95
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeTruthy ( ) ;
96
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeTruthy ( ) ;
85
97
tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
86
98
expect ( tokens ) . toHaveLength ( 1 ) ;
87
99
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
100
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
101
+ expect ( nanos ) . toHaveLength ( 1 ) ;
102
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
88
103
89
104
// handleStop with cleanStorage = true
90
105
await storage . handleStop ( { cleanStorage : true } ) ;
91
106
// Will clean the history bit not addresses or registered tokens
92
107
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 0 ) ;
93
108
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 20 ) ;
94
109
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeTruthy ( ) ;
110
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeTruthy ( ) ;
95
111
tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
96
112
expect ( tokens ) . toHaveLength ( 1 ) ;
97
113
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
114
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
115
+ expect ( nanos ) . toHaveLength ( 1 ) ;
116
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
98
117
99
118
await storage . addTx ( {
100
119
tx_id : 'another-new-tx' ,
@@ -109,9 +128,13 @@ describe('handleStop', () => {
109
128
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
110
129
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 0 ) ;
111
130
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeTruthy ( ) ;
131
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeTruthy ( ) ;
112
132
tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
113
133
expect ( tokens ) . toHaveLength ( 1 ) ;
114
134
expect ( tokens [ 0 ] ) . toEqual ( testToken ) ;
135
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
136
+ expect ( nanos ) . toHaveLength ( 1 ) ;
137
+ expect ( nanos [ 0 ] ) . toEqual ( testNano ) ;
115
138
116
139
// handleStop with cleanAddresses = true
117
140
await loadAddresses ( 0 , 20 , storage ) ;
@@ -120,6 +143,12 @@ describe('handleStop', () => {
120
143
await expect ( store . historyCount ( ) ) . resolves . toEqual ( 1 ) ;
121
144
await expect ( store . addressCount ( ) ) . resolves . toEqual ( 20 ) ;
122
145
await expect ( store . isTokenRegistered ( testToken . uid ) ) . resolves . toBeFalsy ( ) ;
146
+ await expect ( store . isNanoContractRegistered ( testNano . ncId ) ) . resolves . toBeFalsy ( ) ;
147
+
148
+ tokens = await toArray ( storage . getRegisteredTokens ( ) ) ;
149
+ expect ( tokens ) . toHaveLength ( 0 ) ;
150
+ nanos = await toArray ( storage . getRegisteredNanoContracts ( ) ) ;
151
+ expect ( nanos ) . toHaveLength ( 0 ) ;
123
152
124
153
// Access data is untouched when stopping the wallet
125
154
// XXX: since we stringify to save on store, the optional undefined properties are removed
0 commit comments