@@ -920,3 +920,59 @@ func TestExtNodeDeletedExtShortIsBranchFirstLevel(t *testing.T) {
920
920
921
921
ExtNodeDeleted (key1 , key2 , key3 , "ExtNodeDeletedExtShortIsBranchFirstLevel" )
922
922
}
923
+
924
+ func TestExtensionIntoBranch (t * testing.T ) {
925
+ SkipIfNoGeth (t )
926
+ oracle .NodeUrl = oracle .LocalUrl
927
+
928
+ blockNum := 0
929
+ blockNumberParent := big .NewInt (int64 (blockNum ))
930
+ blockHeaderParent := oracle .PrefetchBlock (blockNumberParent , true , nil )
931
+ database := state .NewDatabase (blockHeaderParent )
932
+ statedb , _ := state .New (blockHeaderParent .Root , database , nil )
933
+ addr := common .HexToAddress ("0x50efbf12580138bc623c95757286df4e24eb81c9" )
934
+
935
+ statedb .DisableLoadingRemoteAccounts ()
936
+
937
+ statedb .CreateAccount (addr )
938
+
939
+ oracle .PreventHashingInSecureTrie = true // to store the unchanged key
940
+
941
+ val0 := common .BigToHash (big .NewInt (int64 (1 )))
942
+ key0 := common .HexToHash ("0x1200000000000000000000000000000000000000000000000000000000000000" )
943
+ statedb .SetState (addr , key0 , val0 )
944
+
945
+ key00 := common .HexToHash ("0x0000000000000000000000000000000000000000000000000000000000000000" )
946
+ statedb .SetState (addr , key00 , val0 )
947
+ // After insertion of key0 and key00, we have a branch B with two leaves - at position 1 and 0.
948
+
949
+ key1 := common .HexToHash ("0x1234561000000000000000000000000000000000000000000000000000000000" )
950
+
951
+ // make the value long to have a hashed branch
952
+ v1 := common .FromHex ("0xbbefaa12580138bc263c95757826df4e24eb81c9aaaaaaaaaaaaaaaaaaaaaaaa" )
953
+ val1 := common .BytesToHash (v1 )
954
+ statedb .SetState (addr , key1 , val1 )
955
+ // After insertion of key1, we have a branch B with a leaf at position 0
956
+ // and an extension node E1 at position 1 (with one nibble: 2)
957
+ // The underlying branch B1 of E1 has two leaves - at position 0 and 3.
958
+
959
+ key2 := common .HexToHash ("0x1434563000000000000000000000000000000000000000000000000000000000" )
960
+ // After inserting key2, we have a branch B with two nodes - a leaf at position 0 and branch B1
961
+ // at position 1. At position 1 we have a branch B2 at position 2 (used to be E1's nibble)
962
+ // and a leaf at position 4 (newly added leaf).
963
+ // Branch B2 has two leaves - at position 0 and 3.
964
+
965
+ v1 = common .FromHex ("0xbb" )
966
+ val := common .BytesToHash (v1 )
967
+ trieMod := TrieModification {
968
+ Type : StorageChanged ,
969
+ Key : key2 ,
970
+ Value : val ,
971
+ Address : addr ,
972
+ }
973
+ trieModifications := []TrieModification {trieMod }
974
+
975
+ prepareWitness ("ExtensionIntoBranch" , trieModifications , statedb )
976
+
977
+ oracle .PreventHashingInSecureTrie = false
978
+ }
0 commit comments