Skip to content

Commit 0fbc6bb

Browse files
committed
fix build
1 parent 120fd76 commit 0fbc6bb

File tree

10 files changed

+53
-87
lines changed

10 files changed

+53
-87
lines changed

modules/apps/29-fee/fee_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ package fee_test
33
import (
44
"testing"
55

6-
"github.com/stretchr/testify/suite"
7-
86
sdk "github.com/cosmos/cosmos-sdk/types"
7+
"github.com/stretchr/testify/suite"
98

109
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
1110
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
1211
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
1312
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
14-
ibctesting "github.com/cosmos/ibc-go/testing"
13+
ibctesting "github.com/cosmos/ibc-go/v3/testing"
1514
)
1615

1716
type FeeTestSuite struct {
@@ -47,7 +46,7 @@ func (suite *FeeTestSuite) CreateICS20Packet(coin sdk.Coin) channeltypes.Packet
4746

4847
fungibleTokenPacket := transfertypes.NewFungibleTokenPacketData(
4948
coin.Denom,
50-
sdk.NewInt(100).Uint64(),
49+
sdk.NewInt(100).String(),
5150
suite.chainA.SenderAccount.GetAddress().String(),
5251
suite.chainB.SenderAccount.GetAddress().String(),
5352
)

modules/apps/29-fee/ibc_module.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,33 @@ func (im IBCModule) OnChanOpenTry(
6464
channelID string,
6565
chanCap *capabilitytypes.Capability,
6666
counterparty channeltypes.Counterparty,
67-
version,
6867
counterpartyVersion string,
69-
) error {
70-
mwVersion, appVersion := channeltypes.SplitChannelVersion(version)
68+
) (string, error) {
7169
cpMwVersion, cpAppVersion := channeltypes.SplitChannelVersion(counterpartyVersion)
7270

7371
// Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
7472
// lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
7573
// application.
7674
// If an invalid fee version was passed, we expect the underlying application to fail on its version negotiation.
77-
if mwVersion == types.Version || cpMwVersion == types.Version {
78-
if cpMwVersion != mwVersion {
79-
return sdkerrors.Wrapf(types.ErrInvalidVersion, "fee versions do not match. self version: %s, counterparty version: %s", mwVersion, cpMwVersion)
80-
}
81-
75+
if cpMwVersion == types.Version {
8276
im.keeper.SetFeeEnabled(ctx, portID, channelID)
8377
} else {
8478
// middleware versions are not the expected version for this midddleware. Pass the full version strings along,
8579
// if it not valid version for any other lower middleware, an error will be returned by base application.
86-
appVersion = version
8780
cpAppVersion = counterpartyVersion
8881
}
8982

9083
// call underlying app's OnChanOpenTry callback with the app versions
91-
return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID,
92-
chanCap, counterparty, appVersion, cpAppVersion)
84+
appVersion, err := im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, cpAppVersion)
85+
if err != nil {
86+
return "", err
87+
}
88+
89+
if im.keeper.IsFeeEnabled(ctx, portID, channelID) {
90+
return channeltypes.MergeChannelVersions(types.Version, appVersion), nil
91+
}
92+
93+
return appVersion, nil
9394
}
9495

9596
// OnChanOpenAck implements the IBCModule interface

modules/apps/29-fee/ibc_module_test.go

+24-62
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
1111
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
1212
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
13-
ibctesting "github.com/cosmos/ibc-go/testing"
14-
"github.com/cosmos/ibc-go/testing/simapp"
13+
ibctesting "github.com/cosmos/ibc-go/v3/testing"
14+
"github.com/cosmos/ibc-go/v3/testing/simapp"
1515
)
1616

1717
var (
@@ -107,85 +107,37 @@ func (suite *FeeTestSuite) TestOnChanOpenInit() {
107107
func (suite *FeeTestSuite) TestOnChanOpenTry() {
108108
testCases := []struct {
109109
name string
110-
version string
111110
cpVersion string
112111
crossing bool
113112
expPass bool
114113
}{
115114
{
116-
"valid fee middleware and transfer version",
117-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
115+
"valid fee middleware version",
118116
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
119117
false,
120118
true,
121119
},
122120
{
123-
"valid transfer version on try and counterparty",
124-
transfertypes.Version,
121+
"valid transfer version",
125122
transfertypes.Version,
126123
false,
127124
true,
128125
},
129126
{
130-
"valid fee middleware and transfer version, crossing hellos",
131-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
127+
"crossing hellos: valid fee middleware",
132128
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
133129
true,
134130
true,
135131
},
136132
{
137133
"invalid fee middleware version",
138-
channeltypes.MergeChannelVersions("otherfee28-1", transfertypes.Version),
139-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
140-
false,
141-
false,
142-
},
143-
{
144-
"invalid counterparty fee middleware version",
145-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
146134
channeltypes.MergeChannelVersions("wrongfee29-1", transfertypes.Version),
147135
false,
148136
false,
149137
},
150138
{
151139
"invalid transfer version",
152140
channeltypes.MergeChannelVersions(types.Version, "wrongics20-1"),
153-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
154-
false,
155-
false,
156-
},
157-
{
158-
"invalid counterparty transfer version",
159-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
160-
channeltypes.MergeChannelVersions(types.Version, "wrongics20-1"),
161-
false,
162-
false,
163-
},
164-
{
165-
"transfer version not wrapped",
166-
types.Version,
167-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
168-
false,
169-
false,
170-
},
171-
{
172-
"counterparty transfer version not wrapped",
173-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
174-
types.Version,
175-
false,
176-
false,
177-
},
178-
{
179-
"fee version not included on try, but included in counterparty",
180-
transfertypes.Version,
181-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
182-
false,
183-
false,
184-
},
185-
{
186-
"fee version not included",
187-
channeltypes.MergeChannelVersions(types.Version, transfertypes.Version),
188-
transfertypes.Version,
189141
false,
190142
false,
191143
},
@@ -222,7 +174,7 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() {
222174
Ordering: channeltypes.UNORDERED,
223175
Counterparty: counterparty,
224176
ConnectionHops: []string{suite.path.EndpointA.ConnectionID},
225-
Version: tc.version,
177+
Version: tc.cpVersion,
226178
}
227179

228180
module, _, err := suite.chainA.App.GetIBCKeeper().PortKeeper.LookupModuleByPort(suite.chainA.GetContext(), ibctesting.TransferPort)
@@ -231,13 +183,13 @@ func (suite *FeeTestSuite) TestOnChanOpenTry() {
231183
cbs, ok := suite.chainA.App.GetIBCKeeper().Router.GetRoute(module)
232184
suite.Require().True(ok)
233185

234-
err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(),
235-
suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, chanCap, counterparty, tc.version, tc.cpVersion)
186+
_, err = cbs.OnChanOpenTry(suite.chainA.GetContext(), channel.Ordering, channel.GetConnectionHops(),
187+
suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, chanCap, counterparty, tc.cpVersion)
236188

237189
if tc.expPass {
238-
suite.Require().NoError(err, "unexpected error from version: %s", tc.version)
190+
suite.Require().NoError(err)
239191
} else {
240-
suite.Require().Error(err, "error not returned for version: %s", tc.version)
192+
suite.Require().Error(err)
241193
}
242194
})
243195
}
@@ -656,17 +608,22 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
656608

657609
if tc.expPass {
658610
suite.Require().NoError(err, "unexpected error for case: %s", tc.name)
611+
612+
expectedAmt, ok := sdk.NewIntFromString("10000000000000000000")
613+
suite.Require().True(ok)
659614
suite.Require().Equal(
660615
sdk.Coin{
661616
Denom: ibctesting.TestCoin.Denom,
662-
Amount: sdk.NewInt(100000000000000),
617+
Amount: expectedAmt,
663618
},
664619
suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom))
665620
} else {
621+
expectedAmt, ok := sdk.NewIntFromString("9999999999999999400")
622+
suite.Require().True(ok)
666623
suite.Require().Equal(
667624
sdk.Coin{
668625
Denom: ibctesting.TestCoin.Denom,
669-
Amount: sdk.NewInt(99999999999400),
626+
Amount: expectedAmt,
670627
},
671628
suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom))
672629
}
@@ -762,17 +719,22 @@ func (suite *FeeTestSuite) TestOnTimeoutPacket() {
762719

763720
if tc.expPass {
764721
suite.Require().NoError(err, "unexpected error for case: %s", tc.name)
722+
723+
expectedAmt, ok := sdk.NewIntFromString("10000000000000000100")
724+
suite.Require().True(ok)
765725
suite.Require().Equal(
766726
sdk.Coin{
767727
Denom: ibctesting.TestCoin.Denom,
768-
Amount: sdk.NewInt(100000000000100),
728+
Amount: expectedAmt,
769729
},
770730
suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom))
771731
} else {
732+
expectedAmt, ok := sdk.NewIntFromString("9999999999999999500")
733+
suite.Require().True(ok)
772734
suite.Require().Equal(
773735
sdk.Coin{
774736
Denom: ibctesting.TestCoin.Denom,
775-
Amount: sdk.NewInt(99999999999500),
737+
Amount: expectedAmt,
776738
},
777739
suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), suite.chainA.SenderAccount.GetAddress(), ibctesting.TestCoin.Denom))
778740
}

modules/apps/29-fee/keeper/genesis_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
55
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
66
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
7-
ibctesting "github.com/cosmos/ibc-go/testing"
7+
ibctesting "github.com/cosmos/ibc-go/v3/testing"
88
)
99

1010
func (suite *KeeperTestSuite) TestInitGenesis() {

modules/apps/29-fee/keeper/grpc_query_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
1010
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
1111
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
12-
ibctesting "github.com/cosmos/ibc-go/testing"
12+
ibctesting "github.com/cosmos/ibc-go/v3/testing"
1313
)
1414

1515
func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() {

modules/apps/29-fee/keeper/keeper_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/stretchr/testify/suite"
8-
97
"github.com/cosmos/cosmos-sdk/baseapp"
108
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"github.com/stretchr/testify/suite"
10+
1111
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
1212
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
1313
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
14-
ibctesting "github.com/cosmos/ibc-go/testing"
14+
ibctesting "github.com/cosmos/ibc-go/v3/testing"
1515
)
1616

1717
var (

modules/apps/29-fee/types/genesis_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/cosmos/ibc-go/v3/modules/apps/29-fee/types"
1111
transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
1212
channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
13-
ibctesting "github.com/cosmos/ibc-go/testing"
13+
ibctesting "github.com/cosmos/ibc-go/v3/testing"
1414
)
1515

1616
var (

modules/apps/29-fee/types/keys_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package types_test
22

33
import (
4-
fmt "fmt"
4+
"fmt"
55
"testing"
66

77
"github.com/stretchr/testify/require"

modules/apps/transfer/types/expected_keepers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type ChannelKeeper interface {
3838

3939
// ClientKeeper defines the expected IBC client keeper
4040
type ClientKeeper interface {
41-
GetClientConsensusState(ctx sdk.Context, clientID string) (connection exported.ConsensusState, found bool)
41+
GetClientConsensusState(ctx sdk.Context, clientID string) (connection ibcexported.ConsensusState, found bool)
4242
}
4343

4444
// ConnectionKeeper defines the expected IBC connection keeper

testing/simapp/app.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ type SimApp struct {
207207
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
208208
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
209209
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
210+
ScopedFeeMockKeeper capabilitykeeper.ScopedKeeper
210211
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
211212
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
212213
ScopedIBCMockKeeper capabilitykeeper.ScopedKeeper
@@ -286,6 +287,7 @@ func NewSimApp(
286287
// NOTE: the IBC mock keeper and application module is used only for testing core IBC. Do
287288
// not replicate if you do not need to test core IBC or light clients.
288289
scopedIBCMockKeeper := app.CapabilityKeeper.ScopeToModule(ibcmock.ModuleName)
290+
scopedFeeMockKeeper := app.CapabilityKeeper.ScopeToModule(ibcmock.ModuleName + ibcfeetypes.ModuleName)
289291
scopedICAMockKeeper := app.CapabilityKeeper.ScopeToModule(ibcmock.ModuleName + icacontrollertypes.SubModuleName)
290292

291293
// seal capability keeper after scoping modules
@@ -356,8 +358,10 @@ func NewSimApp(
356358
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
357359
)
358360
transferModule := transfer.NewAppModule(app.TransferKeeper)
361+
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
362+
359363
// create fee-wrapped transfer module
360-
feeTransferModule := ibcfee.NewIBCModule(app.IBCFeeKeeper, transferModule)
364+
feeTransferModule := ibcfee.NewIBCModule(app.IBCFeeKeeper, transferIBCModule)
361365

362366
feeModule := ibcfee.NewAppModule(app.IBCFeeKeeper)
363367

@@ -366,7 +370,7 @@ func NewSimApp(
366370
// Pass IBCFeeKeeper for PortKeeper since fee middleware will wrap the IBCKeeper for underlying application.
367371
mockModule := ibcmock.NewAppModule(scopedIBCMockKeeper, &app.IBCFeeKeeper)
368372
// create fee wrapped mock module
369-
feeMockModule := ibcfee.NewIBCModule(app.IBCFeeKeeper, &ibcmock.MockIBCApp{})
373+
feeMockModule := ibcfee.NewIBCModule(app.IBCFeeKeeper, ibcmock.NewIBCModule(nil, scopedFeeMockKeeper))
370374

371375
mockIBCModule := ibcmock.NewIBCModule(&ibcmock.MockIBCApp{}, scopedIBCMockKeeper)
372376

0 commit comments

Comments
 (0)