From 281e54685ed57282369bfd9fba885c43e5584dc1 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:23:25 +0000 Subject: [PATCH] `[BP: release/v4 <- #88]` test: use non-deprecated gomock package & fix unit tests (#113) * test: use non-deprecated gomock package & fix unit tests (#88) * test: use non-deprecated gomock package & fix unit tests * build: add go install cmd to the mocks target * test: fix failing test on empty packet payload (cherry picked from commit b1b6db8d03b5713dbabdfb2cb05fc5ec622d08de) # Conflicts: # middleware/packet-forward-middleware/Makefile # middleware/packet-forward-middleware/go.mod # middleware/packet-forward-middleware/go.sum # middleware/packet-forward-middleware/router/module_test.go # middleware/packet-forward-middleware/test/mock/channel_keeper.go # middleware/packet-forward-middleware/test/mock/ibc_module.go # middleware/packet-forward-middleware/test/mock/ics4_wrapper.go # middleware/packet-forward-middleware/test/mock/transfer_keeper.go # middleware/packet-forward-middleware/test/setup.go * fix backport v7 -> v4 --------- Co-authored-by: Justin Tieri <37750742+jtieri@users.noreply.github.com> Co-authored-by: Reece Williams --- middleware/packet-forward-middleware/Makefile | 2 ++ middleware/packet-forward-middleware/go.mod | 2 +- middleware/packet-forward-middleware/go.sum | 4 +-- .../router/module_test.go | 26 ++++++++++++------- .../test/mock/bank_keeper.go | 2 +- .../test/mock/channel_keeper.go | 2 +- .../test/mock/distribution_keeper.go | 2 +- .../test/mock/ibc_module.go | 2 +- .../test/mock/ics4_wrapper.go | 2 +- .../test/mock/transfer_keeper.go | 2 +- .../packet-forward-middleware/test/setup.go | 2 +- 11 files changed, 28 insertions(+), 20 deletions(-) diff --git a/middleware/packet-forward-middleware/Makefile b/middleware/packet-forward-middleware/Makefile index c611ca9a..cba98df0 100644 --- a/middleware/packet-forward-middleware/Makefile +++ b/middleware/packet-forward-middleware/Makefile @@ -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/mockgen@v0.2.0 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 diff --git a/middleware/packet-forward-middleware/go.mod b/middleware/packet-forward-middleware/go.mod index 9a226809..e93ddb18 100644 --- a/middleware/packet-forward-middleware/go.mod +++ b/middleware/packet-forward-middleware/go.mod @@ -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 @@ -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 ) diff --git a/middleware/packet-forward-middleware/go.sum b/middleware/packet-forward-middleware/go.sum index 0857714d..73be064d 100644 --- a/middleware/packet-forward-middleware/go.sum +++ b/middleware/packet-forward-middleware/go.sum @@ -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= @@ -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= @@ -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= diff --git a/middleware/packet-forward-middleware/router/module_test.go b/middleware/packet-forward-middleware/router/module_test.go index d7367084..19243dd2 100644 --- a/middleware/packet-forward-middleware/router/module_test.go +++ b/middleware/packet-forward-middleware/router/module_test.go @@ -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" @@ -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) { @@ -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")) @@ -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")) @@ -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) @@ -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) @@ -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( diff --git a/middleware/packet-forward-middleware/test/mock/bank_keeper.go b/middleware/packet-forward-middleware/test/mock/bank_keeper.go index 04809d3c..c8effe42 100644 --- a/middleware/packet-forward-middleware/test/mock/bank_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/bank_keeper.go @@ -8,7 +8,7 @@ import ( reflect "reflect" types "github.com/cosmos/cosmos-sdk/types" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockBankKeeper is a mock of BankKeeper interface. diff --git a/middleware/packet-forward-middleware/test/mock/channel_keeper.go b/middleware/packet-forward-middleware/test/mock/channel_keeper.go index 2dc6285b..65783a42 100644 --- a/middleware/packet-forward-middleware/test/mock/channel_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/channel_keeper.go @@ -10,7 +10,7 @@ import ( types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/cosmos-sdk/x/capability/types" types1 "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockChannelKeeper is a mock of ChannelKeeper interface. diff --git a/middleware/packet-forward-middleware/test/mock/distribution_keeper.go b/middleware/packet-forward-middleware/test/mock/distribution_keeper.go index 8b2ce93e..b8d7a909 100644 --- a/middleware/packet-forward-middleware/test/mock/distribution_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/distribution_keeper.go @@ -8,7 +8,7 @@ import ( reflect "reflect" types "github.com/cosmos/cosmos-sdk/types" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockDistributionKeeper is a mock of DistributionKeeper interface. diff --git a/middleware/packet-forward-middleware/test/mock/ibc_module.go b/middleware/packet-forward-middleware/test/mock/ibc_module.go index 08544725..a82e3bc7 100644 --- a/middleware/packet-forward-middleware/test/mock/ibc_module.go +++ b/middleware/packet-forward-middleware/test/mock/ibc_module.go @@ -11,7 +11,7 @@ import ( types0 "github.com/cosmos/cosmos-sdk/x/capability/types" types1 "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" exported "github.com/cosmos/ibc-go/v4/modules/core/exported" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockIBCModule is a mock of IBCModule interface. diff --git a/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go b/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go index 7886fc32..db8a2a64 100644 --- a/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go +++ b/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go @@ -10,7 +10,7 @@ import ( types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/cosmos-sdk/x/capability/types" exported "github.com/cosmos/ibc-go/v4/modules/core/exported" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockICS4Wrapper is a mock of ICS4Wrapper interface. diff --git a/middleware/packet-forward-middleware/test/mock/transfer_keeper.go b/middleware/packet-forward-middleware/test/mock/transfer_keeper.go index 02a0a445..ec595459 100644 --- a/middleware/packet-forward-middleware/test/mock/transfer_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/transfer_keeper.go @@ -10,7 +10,7 @@ import ( types "github.com/cosmos/cosmos-sdk/types" types0 "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockTransferKeeper is a mock of TransferKeeper interface. diff --git a/middleware/packet-forward-middleware/test/setup.go b/middleware/packet-forward-middleware/test/setup.go index 31bccd1c..4f99257d 100644 --- a/middleware/packet-forward-middleware/test/setup.go +++ b/middleware/packet-forward-middleware/test/setup.go @@ -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"