@@ -183,6 +183,34 @@ test('treeHash with default length', async function (t) {
183
183
t . unlike ( await core . treeHash ( ) , await core2 . treeHash ( ) )
184
184
} )
185
185
186
+ test ( 'treeHash of not-locally-available length works' , async function ( t ) {
187
+ const core = new Hypercore ( RAM )
188
+ await core . append ( 'entry' )
189
+ const remoteCore = new Hypercore ( RAM , core . key )
190
+
191
+ const s1 = core . replicate ( true , { keepAlive : false } )
192
+ const s2 = remoteCore . replicate ( false , { keepAlive : false } )
193
+ s1 . pipe ( s2 ) . pipe ( s1 )
194
+
195
+ await remoteCore . ready ( )
196
+ t . is ( remoteCore . length , 0 , 'Sanity check: initially unsynced' )
197
+
198
+ const treeHash = await remoteCore . treeHash ( 1 )
199
+ t . pass ( 'No error when getting treeHash from unsynced core' )
200
+ t . alike ( treeHash , await core . treeHash ( ) , 'Sanity check: correct treeHash' )
201
+ } )
202
+
203
+ test ( 'treeHash of not-locally-available length works at length 0' , async function ( t ) {
204
+ const core = new Hypercore ( RAM )
205
+ const remoteCore = new Hypercore ( RAM , core . key )
206
+
207
+ t . alike (
208
+ await core . treeHash ( 0 ) ,
209
+ await remoteCore . treeHash ( 0 ) ,
210
+ 'Can get treeHash(0) on remote core (even without replication)'
211
+ )
212
+ } )
213
+
186
214
test ( 'snapshot locks the state' , async function ( t ) {
187
215
const core = new Hypercore ( RAM )
188
216
await core . ready ( )
0 commit comments