Skip to content

Commit

Permalink
fix: use FIL pointer to unmarshaltext
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Mar 29, 2023
1 parent 13ed053 commit f803df2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion venus-shared/actors/types/bigint_fil.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (f FIL) MarshalText() (text []byte, err error) {
return []byte(f.String()), nil
}

func (f FIL) UnmarshalText(text []byte) error {
func (f *FIL) UnmarshalText(text []byte) error {
p, err := ParseFIL(string(text))
if err != nil {
return err
Expand Down
35 changes: 33 additions & 2 deletions venus-shared/types/bigint_fil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"testing"

"github.com/BurntSushi/toml"
tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags"
"github.com/filecoin-project/venus/venus-shared/testutil"
"github.com/filecoin-project/venus/venus-shared/types/params"
Expand Down Expand Up @@ -192,7 +193,7 @@ func TestFilShort(t *testing.T) {
}
}

func TestMarshal(t *testing.T) {
func TestJSONMarshal(t *testing.T) {
tf.UnitTest(t)
type A struct {
Fil FIL
Expand All @@ -208,7 +209,7 @@ func TestMarshal(t *testing.T) {
fmt.Println(string(aBytes))
}

func TestUnMarshal(t *testing.T) {
func TestJSONUnMarshal(t *testing.T) {
tf.UnitTest(t)
type A struct {
Fil FIL
Expand Down Expand Up @@ -237,3 +238,33 @@ func TestUnMarshal(t *testing.T) {
require.Equal(t, a.Fil.String(), s.expect.String())
}
}

func TestTextUnMarshal(t *testing.T) {
tf.UnitTest(t)
type A struct {
Fil FIL
}
bigFIl, _ := big.NewInt(0).SetString("100000000000000000000", 10)
for _, s := range []struct {
fil string
expect FIL
}{
{
fil: `Fil = "0.000000000001 FIL"`,
expect: FIL{Int: big.NewInt(1000000)},
},
{
fil: `Fil = "1 FIL"`,
expect: FIL{Int: big.NewInt(1000000000000000000)},
},
{
fil: `Fil = "100 FIL"`,
expect: FIL{Int: bigFIl},
},
} {
a := A{}
err := toml.Unmarshal([]byte(s.fil), &a)
require.NoError(t, err)
require.Equal(t, a.Fil.String(), s.expect.String())
}
}

0 comments on commit f803df2

Please sign in to comment.