Skip to content

Commit

Permalink
common: add BigInt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Nov 22, 2023
1 parent b7b254b commit 0dde487
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions common/types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 0dde487

Please sign in to comment.