Skip to content

Commit

Permalink
code review cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Nov 27, 2024
1 parent 7e53a55 commit b7f2e6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
31 changes: 16 additions & 15 deletions modules/apps/transfer/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types_test

import (
"encoding/json"
"errors"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -728,19 +729,19 @@ func TestUnmarshalPacketData(t *testing.T) {
testCases := []struct {
name string
malleate func()
expError string
expError error
}{
{
"success: v1 -> v2 with empty encoding (JSON)",
func() {},
"",
nil,
},
{
"success: v1 -> v2 with JSON encoding",
func() {
encoding = types.EncodingJSON
},
"",
nil,
},
{
"success: v1 -> v2 with protobuf encoding",
Expand All @@ -752,7 +753,7 @@ func TestUnmarshalPacketData(t *testing.T) {
packetDataBz = bz
encoding = types.EncodingProtobuf
},
"",
nil,
},
{
"success: v1 -> v2 with abi encoding",
Expand All @@ -769,7 +770,7 @@ func TestUnmarshalPacketData(t *testing.T) {
packetDataBz = bz
encoding = types.EncodingABI
},
"",
nil,
},
{
"success: v2 with empty encoding (protobuf)",
Expand All @@ -785,7 +786,7 @@ func TestUnmarshalPacketData(t *testing.T) {
packetDataBz = packetData.GetBytes()
version = types.V2
},
"",
nil,
},
{
"success: v2 with JSON encoding",
Expand All @@ -802,7 +803,7 @@ func TestUnmarshalPacketData(t *testing.T) {
version = types.V2
encoding = types.EncodingJSON
},
"",
nil,
},
{
"failure: v2 with ABI encoding (not supported)",
Expand All @@ -811,45 +812,45 @@ func TestUnmarshalPacketData(t *testing.T) {
version = types.V2
encoding = types.EncodingABI
},
"encoding application/x-solidity-abi is only supported for ICS20-V1",
errors.New("encoding application/x-solidity-abi is only supported for ICS20-V1"),
},
{
"failure: invalid encoding",
func() {
encoding = "invalid"
},
"invalid encoding provided",
errors.New("invalid encoding provided"),
},
{
"failure: invalid type for json",
func() {
packetDataBz = []byte("invalid")
encoding = types.EncodingJSON
},
ibcerrors.ErrInvalidType.Error(),
ibcerrors.ErrInvalidType,
},
{
"failure: invalid type for protobuf",
func() {
packetDataBz = []byte("invalid")
encoding = types.EncodingProtobuf
},
ibcerrors.ErrInvalidType.Error(),
ibcerrors.ErrInvalidType,
},
{
"failure: invalid type for abi",
func() {
packetDataBz = []byte("invalid")
encoding = types.EncodingABI
},
ibcerrors.ErrInvalidType.Error(),
ibcerrors.ErrInvalidType,
},
{
"invalid version",
func() {
version = "ics20-100"
},
types.ErrInvalidVersion.Error(),
types.ErrInvalidVersion,
},
}

Expand All @@ -864,14 +865,14 @@ func TestUnmarshalPacketData(t *testing.T) {

packetData, err := types.UnmarshalPacketData(packetDataBz, version, encoding)

expPass := tc.expError == ""
expPass := tc.expError == nil
if expPass {
require.NoError(t, err)
require.NotEmpty(t, packetData.Tokens)
require.NotEmpty(t, packetData.Sender)
require.NotEmpty(t, packetData.Receiver)
} else {
require.ErrorContains(t, err, tc.expError)
ibctesting.RequireErrorIsOrContains(t, err, tc.expError)
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions modules/core/04-channel/v2/types/commitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types_test
import (
"encoding/hex"
"encoding/json"
"fmt"
"math/big"
"testing"

Expand Down Expand Up @@ -39,8 +38,6 @@ func TestCommitPacket(t *testing.T) {
Receiver: "receiver",
Memo: "memo",
})
fmt.Printf("transferData: %s\n", string(transferData))
fmt.Printf("hex value: %s\n", hex.EncodeToString(transferData))
require.NoError(t, err)
packet.Payloads[0].Value = transferData
packet.Payloads[0].Encoding = transfertypes.EncodingABI
Expand Down

0 comments on commit b7f2e6b

Please sign in to comment.