Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Aug 28, 2022
1 parent cafc7f3 commit 2ea20ce
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions u128_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
)
Expand All @@ -13,20 +12,25 @@ func TestUint128(t *testing.T) {
// from bytes:
data := []byte{51, 47, 223, 255, 255, 255, 255, 255, 30, 12, 0, 0, 0, 0, 0, 0}

orderID, err := decimal.NewFromString("57240246860720736513843")
numberString := "57240246860720736513843"
parsed, err := decimal.NewFromString(numberString)
if err != nil {
panic(err)
}
spew.Dump(orderID)
{
if parsed.String() != numberString {
t.Errorf("parsed.String() != numberString")
}
}

{
u128 := NewUint128LittleEndian()
err := u128.UnmarshalWithDecoder(NewBorshDecoder(data))
require.NoError(t, err)
require.Equal(t, uint64(3102), u128.Hi)
require.Equal(t, uint64(18446744073707401011), u128.Lo)
require.Equal(t, orderID.BigInt(), u128.BigInt())
require.Equal(t, orderID.String(), u128.DecimalString())
require.Equal(t, parsed.BigInt(), u128.BigInt())
require.Equal(t, parsed.String(), u128.DecimalString())
}
{
u128 := NewUint128BigEndian()
Expand All @@ -35,8 +39,8 @@ func TestUint128(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(3102), u128.Hi)
require.Equal(t, uint64(18446744073707401011), u128.Lo)
require.Equal(t, orderID.BigInt(), u128.BigInt())
require.Equal(t, orderID.String(), u128.DecimalString())
require.Equal(t, parsed.BigInt(), u128.BigInt())
require.Equal(t, parsed.String(), u128.DecimalString())
}
{
j := []byte(`{"i":"57240246860720736513843"}`)
Expand All @@ -48,8 +52,8 @@ func TestUint128(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(3102), object.I.Hi)
require.Equal(t, uint64(18446744073707401011), object.I.Lo)
require.Equal(t, orderID.BigInt(), object.I.BigInt())
require.Equal(t, orderID.String(), object.I.DecimalString())
require.Equal(t, parsed.BigInt(), object.I.BigInt())
require.Equal(t, parsed.String(), object.I.DecimalString())

{
out, err := json.Marshal(object)
Expand Down

0 comments on commit 2ea20ce

Please # to comment.