@@ -142,6 +142,30 @@ contract('PartialMerkleTree', async ([_, primary, nonPrimary]) => {
142142 assert . equal ( web3 . toUtf8 ( await tree . get ( 'foo' ) ) , 'bar' )
143143 } )
144144 } )
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+ } )
145169 } )
146170
147171 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]) => {
166190 siblingsForKey1 = proof [ 1 ]
167191 } )
168192
169- it ( 'should start with same root hash by initialization' , async ( ) => {
193+ it ( 'should start with same root hash by initialization' , async ( ) => {
170194 //initilaze with the first root hash
171195 await treeB . initialize ( firstPhaseOfTreeA )
172196 assert . equal ( await treeB . getRootHash ( ) , firstPhaseOfTreeA )
173197 } )
174198
175- it ( 'should not change root after committing branch data' , async ( ) => {
199+ it ( 'should not change root after committing branch data' , async ( ) => {
176200 // commit branch data
177201 await treeB . commitBranch ( 'key1' , referredValueForKey1 , branchMaskForKey1 , siblingsForKey1 )
178202 assert . equal ( await treeB . getRootHash ( ) , firstPhaseOfTreeA )
179203 } )
180204
181- it ( 'should be able to return proof data' , async ( ) => {
205+ it ( 'should be able to return proof data' , async ( ) => {
182206 // commit branch data
183207 await treeB . getProof ( 'key1' )
184208 } )
0 commit comments