ForEach mutates empty AMT
acruikshank opened this issue · 0 comments
acruikshank commented
Version: github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200424220931-6263827e49f2
Problem:
Flushing an empty AMT produces a different CID before and after a ForEach
is run on it. The following test fails:
func TestEmptyAMTRoot(t *testing.T) {
ctx := context.Background()
rt := mock.NewBuilder(context.Background(), address.Undef).Build(t)
store := adt.AsStore(rt)
root := amt.NewAMT(store)
cid1, err := root.Flush(ctx)
require.NoError(t, err)
root.ForEach(ctx, func(_ uint64, _ *cbg.Deferred) error {
return nil
})
cid2, err := root.Flush(ctx)
require.NoError(t, err)
assert.Equal(t, cid1, cid2)
}
The problem appears to be that the expVals
slice is empty before the ForEach
and is populated with 8 nil values after.