diff --git a/lib/statestore/store.go b/lib/statestore/store.go index f578c17e3..ca924d66e 100644 --- a/lib/statestore/store.go +++ b/lib/statestore/store.go @@ -136,7 +136,7 @@ func (st *StateStore) List(out interface{}) error { return err } - rout.Set(reflect.Append(rout.Elem(), elem.Elem())) + rout.Elem().Set(reflect.Append(rout.Elem(), elem.Elem())) } return nil diff --git a/lib/statestore/store_test.go b/lib/statestore/store_test.go new file mode 100644 index 000000000..667805b0c --- /dev/null +++ b/lib/statestore/store_test.go @@ -0,0 +1,38 @@ +package statestore + +import ( + "testing" + + "github.com/ipfs/go-datastore" + + "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/lib/cborrpc" +) + +func TestList(t *testing.T) { + ds := datastore.NewMapDatastore() + + e, err := cborrpc.Dump(types.NewInt(7)) + if err != nil { + t.Fatal(err) + } + + if err := ds.Put(datastore.NewKey("/2"), e); err != nil { + t.Fatal(err) + } + + st := &StateStore{ds:ds} + + var out []types.BigInt + if err := st.List(&out); err != nil { + t.Fatal(err) + } + + if len(out) != 1 { + t.Fatal("wrong len") + } + + if out[0].Int64() != 7 { + t.Fatal("wrong data") + } +}