@@ -1187,3 +1187,45 @@ func assertEquals(ctx context.Context, t testing.TB, a *Root, expected []cbg.CBO
1187
1187
}))
1188
1188
assertCount (t , a , uint64 (len (expected )))
1189
1189
}
1190
+
1191
+ func TestCidStability (t * testing.T ) {
1192
+ const count = 500
1193
+
1194
+ bs := cbor .NewCborStore (newMockBlocks ())
1195
+ ctx := context .Background ()
1196
+ a , err := NewAMT (bs )
1197
+ require .NoError (t , err )
1198
+
1199
+ cids := make ([]cid.Cid , count )
1200
+
1201
+ // Add, flushing each time.
1202
+ for i := 0 ; i < count ; i ++ {
1203
+ c , err := a .Flush (ctx )
1204
+ require .NoError (t , err )
1205
+ cids [i ] = c
1206
+ assert .NoError (t , a .Set (ctx , uint64 (i ), cborstr (fmt .Sprintf ("%d" , i ))))
1207
+ }
1208
+
1209
+ // now go backwards
1210
+ for i := count - 1 ; i >= 0 ; i -- {
1211
+ found , err := a .Delete (ctx , uint64 (i ))
1212
+ assert .NoError (t , err )
1213
+ assert .True (t , found )
1214
+ c , err := a .Flush (ctx )
1215
+ require .NoError (t , err )
1216
+ assert .Equal (t , cids [i ], c )
1217
+ }
1218
+
1219
+ // now go backwards and start over.
1220
+ a2 , err := LoadAMT (ctx , bs , cids [len (cids )- 1 ])
1221
+ require .NoError (t , err )
1222
+
1223
+ for i := count - 2 ; i >= 0 ; i -- {
1224
+ found , err := a2 .Delete (ctx , uint64 (i ))
1225
+ assert .NoError (t , err )
1226
+ assert .True (t , found )
1227
+ c , err := a2 .Flush (ctx )
1228
+ require .NoError (t , err )
1229
+ assert .Equal (t , cids [i ], c )
1230
+ }
1231
+ }
0 commit comments