@@ -560,6 +560,54 @@ test('core - clone fills in with additional', async function (t) {
560
560
t . alike ( await clone . blocks . get ( 1 ) , b4a . from ( 'b' ) )
561
561
} )
562
562
563
+ test ( 'core - clone with different fork' , async function ( t ) {
564
+ const { core } = await create ( )
565
+ const { core : clone } = await create ( { keyPair : { publicKey : core . header . keyPair . publicKey } } )
566
+ const { core : clone2 } = await create ( { compat : false } )
567
+ const { core : fail } = await create ( { manifest : clone2 . header . manifest } )
568
+
569
+ t . alike ( clone . header . keyPair . publicKey , core . header . keyPair . publicKey )
570
+ t . unlike ( clone2 . header . keyPair . publicKey , core . header . keyPair . publicKey )
571
+
572
+ await core . truncate ( 0 , 1 )
573
+
574
+ t . is ( core . tree . fork , 1 )
575
+ t . is ( core . header . tree . fork , 1 )
576
+
577
+ await core . append ( [ b4a . from ( 'a' ) ] )
578
+
579
+ await clone . copyFrom ( core , core . tree . signature )
580
+
581
+ t . is ( clone . tree . fork , 1 )
582
+ t . is ( clone . header . tree . fork , 1 )
583
+
584
+ await core . append ( [ b4a . from ( 'b' ) ] )
585
+
586
+ const batch = core . tree . batch ( )
587
+ batch . fork = 0
588
+
589
+ const signature = clone2 . verifier . sign ( batch , clone2 . header . keyPair )
590
+
591
+ // fail with same fork
592
+ await t . exception ( fail . copyFrom ( core , signature ) , / I N V A L I D _ S I G N A T U R E / )
593
+
594
+ await clone2 . copyFrom ( core , signature , { fork : 0 } )
595
+
596
+ t . is ( clone2 . tree . fork , 0 )
597
+ t . is ( clone2 . header . tree . fork , 0 )
598
+
599
+ await clone2 . append ( [ b4a . from ( 'c' ) ] )
600
+
601
+ // verify state
602
+ t . is ( clone . tree . length , 1 )
603
+ t . is ( core . tree . length , 2 )
604
+ t . is ( clone2 . tree . length , 3 )
605
+
606
+ t . alike ( await clone . blocks . get ( 0 ) , b4a . from ( 'a' ) )
607
+ t . alike ( await core . blocks . get ( 1 ) , b4a . from ( 'b' ) )
608
+ t . alike ( await clone2 . blocks . get ( 2 ) , b4a . from ( 'c' ) )
609
+ } )
610
+
563
611
async function create ( opts ) {
564
612
const storage = new Map ( )
565
613
0 commit comments