@@ -142,6 +142,30 @@ contract('PartialMerkleTree', async ([_, primary, nonPrimary]) => {
142
142
assert . equal ( web3 . toUtf8 ( await tree . get ( 'foo' ) ) , 'bar' )
143
143
} )
144
144
} )
145
+
146
+ describe ( 'safeGet()' , async ( ) => {
147
+ it ( 'should return stored value for the given key' , async ( ) => {
148
+ await tree . insert ( 'foo' , 'bar' , { from : primary } )
149
+ assert . equal ( web3 . toUtf8 ( await tree . get ( 'foo' ) ) , 'bar' )
150
+ } )
151
+ it ( 'should throw if the given key is not included' , async ( ) => {
152
+ await tree . insert ( 'foo' , 'bar' , { from : primary } )
153
+ try {
154
+ await tree . get ( 'fuz' )
155
+ assert . fail ( 'Did not reverted' )
156
+ } catch ( e ) {
157
+ assert . ok ( 'Reverted successfully' )
158
+ }
159
+ } )
160
+ } )
161
+
162
+ describe ( 'doesInclude()' , async ( ) => {
163
+ it ( 'should return boolean whether the tree includes the given key or not' , async ( ) => {
164
+ await tree . insert ( 'foo' , 'bar' , { from : primary } )
165
+ assert . equal ( await tree . doesInclude ( 'foo' ) , true )
166
+ assert . equal ( await tree . doesInclude ( 'fuz' ) , false )
167
+ } )
168
+ } )
145
169
} )
146
170
147
171
context ( 'We can reenact merkle tree transformation by submitting only referred siblings instead of submitting all nodes' , async ( ) => {
@@ -166,19 +190,19 @@ contract('PartialMerkleTree', async ([_, primary, nonPrimary]) => {
166
190
siblingsForKey1 = proof [ 1 ]
167
191
} )
168
192
169
- it ( 'should start with same root hash by initialization' , async ( ) => {
193
+ it ( 'should start with same root hash by initialization' , async ( ) => {
170
194
//initilaze with the first root hash
171
195
await treeB . initialize ( firstPhaseOfTreeA )
172
196
assert . equal ( await treeB . getRootHash ( ) , firstPhaseOfTreeA )
173
197
} )
174
198
175
- it ( 'should not change root after committing branch data' , async ( ) => {
199
+ it ( 'should not change root after committing branch data' , async ( ) => {
176
200
// commit branch data
177
201
await treeB . commitBranch ( 'key1' , referredValueForKey1 , branchMaskForKey1 , siblingsForKey1 )
178
202
assert . equal ( await treeB . getRootHash ( ) , firstPhaseOfTreeA )
179
203
} )
180
204
181
- it ( 'should be able to return proof data' , async ( ) => {
205
+ it ( 'should be able to return proof data' , async ( ) => {
182
206
// commit branch data
183
207
await treeB . getProof ( 'key1' )
184
208
} )
0 commit comments