Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BP: release/v4 <- #88] test: use non-deprecated gomock package & fix unit tests #113

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions middleware/packet-forward-middleware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ cosmovisor:
.PHONY: build build-linux build-simd-all build-simd-linux cosmovisor

mocks: $(MOCKS_DIR)
go install go.uber.org/mock/[email protected]
mockgen -package=mock -destination=./test/mock/transfer_keeper.go $(GOMOD)/router/types TransferKeeper
mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/router/types ChannelKeeper
mockgen -package=mock -destination=./test/mock/distribution_keeper.go $(GOMOD)/router/types DistributionKeeper
mockgen -package=mock -destination=./test/mock/bank_keeper.go $(GOMOD)/router/types BankKeeper
mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/router/types ChannelKeeper
mockgen -package=mock -destination=./test/mock/ics4_wrapper.go github.com/cosmos/ibc-go/v4/modules/core/05-port/types ICS4Wrapper
mockgen -package=mock -destination=./test/mock/ibc_module.go github.com/cosmos/ibc-go/v4/modules/core/05-port/types IBCModule

Expand Down
2 changes: 1 addition & 1 deletion middleware/packet-forward-middleware/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/cosmos/cosmos-sdk v0.45.16
github.com/cosmos/ibc-go/v4 v4.4.2
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand All @@ -16,6 +15,7 @@ require (
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.27
github.com/tendermint/tm-db v0.6.7
go.uber.org/mock v0.2.0
google.golang.org/genproto v0.0.0-20230125152338-dcaf20b6aeaa
google.golang.org/grpc v1.52.3
)
Expand Down
4 changes: 2 additions & 2 deletions middleware/packet-forward-middleware/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -662,6 +661,8 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=
go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down Expand Up @@ -933,7 +934,6 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
26 changes: 16 additions & 10 deletions middleware/packet-forward-middleware/router/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/test"
"github.com/golang/mock/gomock"
"github.com/iancoleman/orderedmap"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -123,13 +123,19 @@ func TestOnRecvPacket_EmptyPacket(t *testing.T) {
senderAccAddr := test.AccAddress(t)
packet := emptyPacket()

// Expected mocks
gomock.InOrder(
setup.Mocks.IBCModuleMock.EXPECT().OnRecvPacket(ctx, packet, senderAccAddr).
Return(channeltypes.NewResultAcknowledgement([]byte(""))),
)

ack := forwardMiddleware.OnRecvPacket(ctx, packet, senderAccAddr)
require.False(t, ack.Success())
require.True(t, ack.Success())

expectedAck := &channeltypes.Acknowledgement{}
err := cdc.UnmarshalJSON(ack.Acknowledgement(), expectedAck)
require.NoError(t, err)
require.Equal(t, "packet-forward-middleware error: failed to unmarshal packet data as FungibleTokenPacketData: EOF", expectedAck.GetError())
require.Equal(t, "", expectedAck.GetError())
}

func TestOnRecvPacket_InvalidReceiver(t *testing.T) {
Expand Down Expand Up @@ -257,7 +263,7 @@ func TestOnRecvPacket_ForwardNoFee(t *testing.T) {
Channel: channel,
}}
packetOrig := transferPacket(t, senderAddr, hostAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, nil)
packetFwd := transferPacket(t, intermediateAddr, destAddr, nil)

acknowledgement := channeltypes.NewResultAcknowledgement([]byte("test"))
Expand Down Expand Up @@ -317,7 +323,7 @@ func TestOnRecvPacket_ForwardAmountInt256(t *testing.T) {
}}

packetOrig := transferPacket256(t, senderAddr, hostAddr, metadata)
packetModifiedSender := transferPacket256(t, senderAddr, intermediateAddr, metadata)
packetModifiedSender := transferPacket256(t, senderAddr, intermediateAddr, nil)
packetFwd := transferPacket256(t, intermediateAddr, destAddr, nil)

acknowledgement := channeltypes.NewResultAcknowledgement([]byte("test"))
Expand Down Expand Up @@ -377,7 +383,7 @@ func TestOnRecvPacket_ForwardWithFee(t *testing.T) {
Channel: channel,
}}
packetOrig := transferPacket(t, senderAddr, hostAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, nil)
packetFwd := transferPacket(t, intermediateAddr, destAddr, nil)
acknowledgement := channeltypes.NewResultAcknowledgement([]byte("test"))
successAck := cdc.MustMarshalJSON(&acknowledgement)
Expand Down Expand Up @@ -452,9 +458,9 @@ func TestOnRecvPacket_ForwardMultihopStringNext(t *testing.T) {
}

packetOrig := transferPacket(t, senderAddr, hostAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, nil)
packet2 := transferPacket(t, intermediateAddr, hostAddr2, nextMetadata)
packet2ModifiedSender := transferPacket(t, intermediateAddr, intermediateAddr2, nextMetadata)
packet2ModifiedSender := transferPacket(t, intermediateAddr, intermediateAddr2, nil)
packetFwd := transferPacket(t, intermediateAddr2, destAddr, nil)

memo1, err := json.Marshal(nextMetadata)
Expand Down Expand Up @@ -563,9 +569,9 @@ func TestOnRecvPacket_ForwardMultihopJSONNext(t *testing.T) {
},
}
packetOrig := transferPacket(t, senderAddr, hostAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, metadata)
packetModifiedSender := transferPacket(t, senderAddr, intermediateAddr, nil)
packet2 := transferPacket(t, intermediateAddr, hostAddr2, nextMetadata)
packet2ModifiedSender := transferPacket(t, intermediateAddr, intermediateAddr2, nextMetadata)
packet2ModifiedSender := transferPacket(t, intermediateAddr, intermediateAddr2, nil)
packetFwd := transferPacket(t, intermediateAddr2, destAddr, nil)

msgTransfer1 := transfertypes.NewMsgTransfer(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion middleware/packet-forward-middleware/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/keeper"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/router/types"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4/test/mock"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
"go.uber.org/mock/gomock"

"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down
Loading