Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lens/util/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,17 @@ func (wt *paramWrapperType) MarshalJSON() ([]byte, error) {
t = t.Elem()
}

// if v is the zero value use default marshaling
if !v.IsValid() {
return json.Marshal(wt.obj)
}
// if v is typed zero value use default marshaling
if v.IsZero() {
return json.Marshal(wt.obj)
}

switch t.Kind() {
case reflect.Struct:
// if an empty struct marshal the empty struct and bail.
if v.IsZero() {
return json.Marshal(wt.obj)
}
// if its a struct, walk its fields and recurse.
m := make(map[string]interface{})
for i := 0; i < v.NumField(); i++ {
Expand Down
54 changes: 48 additions & 6 deletions tasks/messages/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"reflect"
"testing"

"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/crypto"
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
paych6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/paych"

"github.com/filecoin-project/lily/chain/actors/builtin"
"github.com/filecoin-project/lily/chain/actors/builtin/market"
miner "github.com/filecoin-project/lily/chain/actors/builtin/miner"
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
"reflect"
"testing"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/chain/types"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
"github.com/ipfs/go-cid"
)

Expand Down Expand Up @@ -233,6 +238,34 @@ func TestParseMessageParams(t *testing.T) {
wantEncoded: "{\"Recoveries\":[{\"Deadline\":1,\"Partition\":1,\"Sectors\":{\"Count\":10,\"RLE\":[1,10]}}]}",
wantErr: false,
},
// from https://github.com/filecoin-project/lily/issues/892
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without 691f5c2 I have verified this test fails with:

message_test.go:292: got unexpected error: failed to parse message params method: 2, actor code: bafkqafdgnfwc6nrpobqxs3lfnz2gg2dbnzxgk3a, params: ��U���"���#�t�`�":�d_z�Q��@���WF���v����Xa��oUp�ٮ}�2@����I���enw��GYWI��wӱ'�����<KM��$����s�;����J����[��G)<=��n��eIH$�Tׁ��[R�,q�|d���,@: failed to override message param json marshaller: reflect: call of reflect.Value.NumField on zero Value

{
name: "UpdateChannelState",
method: 2,
actorCode: builtin6.PaymentChannelActorCodeID,
params: mustMarshalCbor(t, &paych6.UpdateChannelStateParams{
Sv: paych6.SignedVoucher{
ChannelAddr: mustParseAddress(t, "t2agxsfeq274rqk5f2mduseovdmrpxv52r6gp4mky"),
TimeLockMin: 0,
TimeLockMax: 0,
SecretPreimage: nil,
Extra: nil,
Lane: 6,
Nonce: 87,
Amount: big.NewInt(7960172680),
MinSettleHeight: 0,
Merges: nil,
Signature: &crypto.Signature{
Type: 2,
Data: mustDecodeBase64(t, "rm9VcNjZrn2MMkCMsQsPSRWjtmVud+ARR1lXSRsM13fTsSeeuoaImDxLTc4UJMwfEZFz/TuunrzhSqiKHfVbq5RHKTw9g4ZusbNlSUgk5VTXgfiIW1IBLHG1fGSqopUs"),
},
},
Secret: nil,
}),
wantMethod: "UpdateChannelState",
wantEncoded: "{\"Secret\":null,\"Sv\":{\"Amount\":{\"Int\":7960172680},\"ChannelAddr\":\"f2agxsfeq274rqk5f2mduseovdmrpxv52r6gp4mky\",\"Extra\":null,\"Lane\":6,\"Merges\":null,\"MinSettleHeight\":0,\"Nonce\":87,\"SecretPreimage\":null,\"Signature\":{\"Data\":\"rm9VcNjZrn2MMkCMsQsPSRWjtmVud+ARR1lXSRsM13fTsSeeuoaImDxLTc4UJMwfEZFz/TuunrzhSqiKHfVbq5RHKTw9g4ZusbNlSUgk5VTXgfiIW1IBLHG1fGSqopUs\",\"Type\":2},\"TimeLockMax\":0,\"TimeLockMin\":0}}",
wantErr: false,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -295,6 +328,15 @@ func mustMarshalCbor(t *testing.T, v cbor.Marshaler) []byte {
return buf.Bytes()
}

func mustParseAddress(t *testing.T, addrStr string) address.Address {
t.Helper()
a, err := address.NewFromString(addrStr)
if err != nil {
t.Fatalf("bad address: %v", err)
}
return a
}

func mustMakeMapFromJsonString(t *testing.T, str string) map[string]interface{} {
if str == "" {
return nil
Expand Down