-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
212 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/xyield/xrpl-go/model/ledger" | ||
"github.com/xyield/xrpl-go/model/transactions" | ||
) | ||
|
||
func TestUInt16FromJson(t *testing.T) { | ||
tt := []struct { | ||
description string | ||
input any | ||
expected []byte | ||
expectedErr error | ||
}{ | ||
{ | ||
description: "convert uint16", | ||
input: uint16(1), | ||
expected: []byte{0, 1}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "convert uint", | ||
input: uint(1), | ||
expected: []byte{0, 1}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "convert int", | ||
input: int(1), | ||
expected: []byte{0, 1}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "convert TxType", | ||
input: transactions.PaymentTx, | ||
expected: []byte{0, 0}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "convert LedgerEntryType", | ||
input: ledger.AccountRootEntry, | ||
expected: []byte{0, 97}, | ||
expectedErr: nil, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.description, func(t *testing.T) { | ||
u16 := &UInt16{} | ||
got, err := u16.FromJson(tc.input) | ||
if tc.expectedErr != nil { | ||
require.EqualError(t, err, tc.expectedErr.Error()) | ||
require.Empty(t, got) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, tc.expected, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/xyield/xrpl-go/model/transactions/types" | ||
) | ||
|
||
func TestUint32FromJson(t *testing.T) { | ||
tt := []struct { | ||
description string | ||
input any | ||
expected []byte | ||
expectedErr error | ||
}{ | ||
{ | ||
description: "convert uint32", | ||
input: uint32(1), | ||
expected: []byte{0, 0, 0, 1}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "convert uint", | ||
input: uint(1), | ||
expected: []byte{0, 0, 0, 1}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "convert flag", | ||
input: types.SetFlag(1), | ||
expected: []byte{0, 0, 0, 1}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "invalid type should error", | ||
input: "invalid", | ||
expected: nil, | ||
expectedErr: ErrInvalidUInt32, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.description, func(t *testing.T) { | ||
u32 := &UInt32{} | ||
got, err := u32.FromJson(tc.input) | ||
if tc.expectedErr != nil { | ||
require.EqualError(t, err, tc.expectedErr.Error()) | ||
require.Empty(t, got) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, tc.expected, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/xyield/xrpl-go/binary-codec/definitions" | ||
) | ||
|
||
func TestUint8FromJson(t *testing.T) { | ||
tt := []struct { | ||
description string | ||
input any | ||
expected []byte | ||
expectedErr error | ||
}{ | ||
{ | ||
description: "find transaction code", | ||
input: "tecAMM_ACCOUNT", | ||
expected: []byte{168}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "regular uint8", | ||
input: uint8(30), | ||
expected: []byte{30}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "regular int", | ||
input: int(30), | ||
expected: []byte{30}, | ||
expectedErr: nil, | ||
}, | ||
{ | ||
description: "invalid transaction result", | ||
input: "invalid", | ||
expected: nil, | ||
expectedErr: &definitions.NotFoundError{Instance: "TransactionResultName", Input: "invalid"}, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.description, func(t *testing.T) { | ||
u8 := &UInt8{} | ||
got, err := u8.FromJson(tc.input) | ||
if tc.expectedErr != nil { | ||
require.EqualError(t, err, tc.expectedErr.Error()) | ||
require.Empty(t, got) | ||
} else { | ||
require.NoError(t, err) | ||
require.Equal(t, tc.expected, got) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters