@@ -108,3 +108,96 @@ suite "Aristo TxFrame":
108108 check:
109109 tx.fetchAccountRecord (acc1[0 ]).isOk ()
110110 tx.fetchAccountRecord (acc2[0 ]).isErr () # Doesn't exist in tx2
111+
112+ test " Frames using moveParentHashKeys parameter" :
113+ let
114+ tx0 = db.txFrameBegin (db.baseTxFrame ())
115+ tx1 = db.txFrameBegin (tx0)
116+
117+ check:
118+ tx0.mergeAccountRecord (acc1[0 ], acc1[1 ]).isOk ()
119+ tx1.mergeAccountRecord (acc2[0 ], acc2[1 ]).isOk ()
120+ tx0.fetchStateRoot () != tx1.fetchStateRoot ()
121+ tx0.kMap.len () == 0
122+ tx1.kMap.len () == 1
123+
124+ # Check that the kMap hashkeys are moved correctly
125+ # and that the stateroot is correct before and after each move.
126+ let tx2 = db.txFrameBegin (tx1, moveParentHashKeys = true )
127+ check:
128+ tx1.kMap.len () == 0
129+ tx2.kMap.len () == 1
130+ tx1.fetchStateRoot () == tx2.fetchStateRoot ()
131+ # keys are recomputed when fetching state root even after moving
132+ tx1.kMap.len () == 1
133+ tx2.kMap.len () == 1
134+
135+ let tx3 = db.txFrameBegin (tx2, moveParentHashKeys = false )
136+ check:
137+ tx2.kMap.len () == 1
138+ tx3.kMap.len () == 0
139+ tx2.fetchStateRoot () == tx3.fetchStateRoot ()
140+
141+ test " Frames using moveParentHashKeys parameter - moved from persist" :
142+ let
143+ tx0 = db.txFrameBegin (db.baseTxFrame ())
144+ tx1 = db.txFrameBegin (tx0)
145+
146+ check:
147+ tx0.mergeAccountRecord (acc1[0 ], acc1[1 ]).isOk ()
148+ tx1.mergeAccountRecord (acc2[0 ], acc2[1 ]).isOk ()
149+ tx0.fetchStateRoot () != tx1.fetchStateRoot ()
150+ tx0.kMap.len () == 0
151+ tx1.kMap.len () == 1
152+
153+ let
154+ tx2 = db.txFrameBegin (tx1, moveParentHashKeys = true )
155+ stateRoot = tx1.fetchStateRoot ().get ()
156+
157+ # Check that we can still persist the moved from txFrame
158+ tx1.checkpoint (1 , skipSnapshot = true )
159+ let batch = db.putBegFn ().expect (" working batch" )
160+ db.persist (batch, tx1, Opt .some (stateRoot))
161+ check:
162+ db.putEndFn (batch).isOk ()
163+
164+ db.finish ()
165+
166+ # Load the data
167+ db.initInstance ().expect (" working backend" )
168+ let tx = db.baseTxFrame ()
169+ check:
170+ tx.fetchAccountRecord (acc1[0 ]).isOk ()
171+ tx.fetchAccountRecord (acc2[0 ]).isOk ()
172+
173+ test " Frames using moveParentHashKeys parameter - moved to persist" :
174+ let
175+ tx0 = db.txFrameBegin (db.baseTxFrame ())
176+ tx1 = db.txFrameBegin (tx0)
177+
178+ check:
179+ tx0.mergeAccountRecord (acc1[0 ], acc1[1 ]).isOk ()
180+ tx1.mergeAccountRecord (acc2[0 ], acc2[1 ]).isOk ()
181+ tx0.fetchStateRoot () != tx1.fetchStateRoot ()
182+ tx0.kMap.len () == 0
183+ tx1.kMap.len () == 1
184+
185+ let
186+ tx2 = db.txFrameBegin (tx1, moveParentHashKeys = true )
187+ stateRoot = tx1.fetchStateRoot ().get ()
188+
189+ # Check that we can still persist the moved to txFrame
190+ tx2.checkpoint (2 , skipSnapshot = true )
191+ let batch = db.putBegFn ().expect (" working batch" )
192+ db.persist (batch, tx2, Opt .some (stateRoot))
193+ check:
194+ db.putEndFn (batch).isOk ()
195+
196+ db.finish ()
197+
198+ # Load the data
199+ db.initInstance ().expect (" working backend" )
200+ let tx = db.baseTxFrame ()
201+ check:
202+ tx.fetchAccountRecord (acc1[0 ]).isOk ()
203+ tx.fetchAccountRecord (acc2[0 ]).isOk ()
0 commit comments