From 0dde487c4334a9b0a28daef367210a2e3624f9c9 Mon Sep 17 00:00:00 2001 From: Warren He Date: Tue, 21 Nov 2023 16:02:07 -0800 Subject: [PATCH] common: add BigInt tests --- common/types_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 common/types_test.go diff --git a/common/types_test.go b/common/types_test.go new file mode 100644 index 000000000..5d94bdd97 --- /dev/null +++ b/common/types_test.go @@ -0,0 +1,33 @@ +package common + +import ( + "encoding/json" + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestBigInt(t *testing.T) { + var v BigInt + + textRef := []byte("11111111111111111111") + err := v.UnmarshalText(textRef) + require.NoError(t, err) + textRoundTrip, err := v.MarshalText() + require.NoError(t, err) + require.Equal(t, textRef, textRoundTrip) + + jsonRef := []byte("\"22222222222222222222\"") + err = json.Unmarshal(jsonRef, &v) + require.NoError(t, err) + jsonRoundTrip, err := json.Marshal(v) + require.NoError(t, err) + require.Equal(t, jsonRef, jsonRoundTrip) + + stringRef := "33333333333333333333" + err = v.Int.UnmarshalText([]byte(stringRef)) + require.NoError(t, err) + stringRoundTrip := fmt.Sprintf("%v", v) + require.Equal(t, stringRef, stringRoundTrip) +}