@@ -12,8 +12,6 @@ import { assert, describe, it } from 'vitest'
12
12
13
13
import { ROOT_DB_KEY , Trie , createTrie } from '../../src/index.js'
14
14
15
- import type { BatchDBOp } from '@ethereumjs/util'
16
-
17
15
describe ( 'testing checkpoints' , ( ) => {
18
16
let trie : Trie
19
17
let trieCopy : Trie
@@ -51,16 +49,6 @@ describe('testing checkpoints', () => {
51
49
postRoot = bytesToHex ( trie . root ( ) )
52
50
} )
53
51
54
- it ( 'should get values from before checkpoint' , async ( ) => {
55
- const res = await trie . get ( utf8ToBytes ( 'doge' ) )
56
- assert . ok ( equalsBytes ( utf8ToBytes ( 'coin' ) , res ! ) )
57
- } )
58
-
59
- it ( 'should get values from cache' , async ( ) => {
60
- const res = await trie . get ( utf8ToBytes ( 'love' ) )
61
- assert . ok ( equalsBytes ( utf8ToBytes ( 'emotion' ) , res ! ) )
62
- } )
63
-
64
52
it ( 'should copy trie and get upstream and cache values after checkpoint' , async ( ) => {
65
53
trieCopy = trie . shallowCopy ( )
66
54
assert . equal ( bytesToHex ( trieCopy . root ( ) ) , postRoot )
@@ -87,110 +75,6 @@ describe('testing checkpoints', () => {
87
75
assert . equal ( bytesToUtf8 ( value ! ) , 'value1' )
88
76
} )
89
77
90
- it ( 'should revert to the original root' , async ( ) => {
91
- assert . ok ( trie . hasCheckpoints ( ) )
92
- await trie . revert ( )
93
- assert . equal ( bytesToHex ( trie . root ( ) ) , preRoot )
94
- assert . notOk ( trie . hasCheckpoints ( ) )
95
- } )
96
-
97
- it ( 'should not get values from cache after revert' , async ( ) => {
98
- const res = await trie . get ( utf8ToBytes ( 'love' ) )
99
- assert . notOk ( res )
100
- } )
101
-
102
- it ( 'should commit a checkpoint' , async ( ) => {
103
- trie . checkpoint ( )
104
- await trie . put ( utf8ToBytes ( 'test' ) , utf8ToBytes ( 'something' ) )
105
- await trie . put ( utf8ToBytes ( 'love' ) , utf8ToBytes ( 'emotion' ) )
106
- await trie . commit ( )
107
- assert . equal ( trie . hasCheckpoints ( ) , false )
108
- assert . equal ( bytesToHex ( trie . root ( ) ) , postRoot )
109
- } )
110
-
111
- it ( 'should get new values after commit' , async ( ) => {
112
- const res = await trie . get ( utf8ToBytes ( 'love' ) )
113
- assert . ok ( equalsBytes ( utf8ToBytes ( 'emotion' ) , res ! ) )
114
- } )
115
-
116
- it ( 'should commit a nested checkpoint' , async ( ) => {
117
- trie . checkpoint ( )
118
- await trie . put ( utf8ToBytes ( 'test' ) , utf8ToBytes ( 'something else' ) )
119
- const root = trie . root ( )
120
- trie . checkpoint ( )
121
- await trie . put ( utf8ToBytes ( 'the feels' ) , utf8ToBytes ( 'emotion' ) )
122
- await trie . revert ( )
123
- await trie . commit ( )
124
- assert . equal ( trie . hasCheckpoints ( ) , false )
125
- assert . equal ( trie . root ( ) , root )
126
- } )
127
-
128
- const k1 = utf8ToBytes ( 'k1' )
129
- const v1 = utf8ToBytes ( 'v1' )
130
- const v12 = utf8ToBytes ( 'v12' )
131
- const v123 = utf8ToBytes ( 'v123' )
132
-
133
- it ( 'revert -> put' , async ( ) => {
134
- trie = new Trie ( )
135
-
136
- trie . checkpoint ( )
137
- await trie . put ( k1 , v1 )
138
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'before revert: v1 in trie' )
139
- await trie . revert ( )
140
- assert . deepEqual ( await trie . get ( k1 ) , null , 'after revert: v1 removed' )
141
- } )
142
-
143
- it ( 'revert -> put (update)' , async ( ) => {
144
- trie = new Trie ( )
145
-
146
- await trie . put ( k1 , v1 )
147
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'before CP: v1' )
148
- trie . checkpoint ( )
149
- await trie . put ( k1 , v12 )
150
- await trie . put ( k1 , v123 )
151
- await trie . revert ( )
152
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'after revert: v1' )
153
- } )
154
-
155
- it ( 'revert -> put (update) batched' , async ( ) => {
156
- const trie = new Trie ( )
157
- await trie . put ( k1 , v1 )
158
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'before CP: v1' )
159
- trie . checkpoint ( )
160
- const ops = [
161
- { type : 'put' , key : k1 , value : v12 } ,
162
- { type : 'put' , key : k1 , value : v123 } ,
163
- ] as BatchDBOp [ ]
164
- await trie . batch ( ops )
165
- await trie . revert ( )
166
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'after revert: v1' )
167
- } )
168
-
169
- it ( 'Checkpointing: revert -> del' , async ( ) => {
170
- const trie = new Trie ( )
171
- await trie . put ( k1 , v1 )
172
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'before CP: v1' )
173
- trie . checkpoint ( )
174
- await trie . del ( k1 )
175
- assert . deepEqual ( await trie . get ( k1 ) , null , 'before revert: null' )
176
- await trie . revert ( )
177
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'after revert: v1' )
178
- } )
179
-
180
- it ( 'Checkpointing: nested checkpoints -> commit -> revert' , async ( ) => {
181
- const trie = new Trie ( )
182
- await trie . put ( k1 , v1 )
183
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'before CP: v1' )
184
- trie . checkpoint ( )
185
- await trie . put ( k1 , v12 )
186
- trie . checkpoint ( )
187
- await trie . put ( k1 , v123 )
188
- await trie . commit ( )
189
- assert . deepEqual ( await trie . get ( k1 ) , v123 , 'after commit (second CP): v123' )
190
- await trie . revert ( )
191
- assert . deepEqual ( await trie . get ( k1 ) , v1 , 'after revert (first CP): v1' )
192
- } )
193
-
194
78
/*
195
79
In this educational example, it is shown how operations on a clone of a trie
196
80
can be copied into the original trie. This also includes pruning.
0 commit comments