Skip to content

Commit

Permalink
chore: Remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Jan 16, 2025
1 parent d10eb1a commit c666b00
Show file tree
Hide file tree
Showing 2 changed files with 418 additions and 24 deletions.
48 changes: 24 additions & 24 deletions tests/e2e/ibc_fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ func TestIBCFeesTransfer(t *testing.T) {
// when an ics-29 fee is attached to an ibc package
// then the relayer's payee is receiving the fee(s) on success
marshaler := app.MakeEncodingConfig(t).Codec
coord := wasmibctesting.NewCoordinator(t, 2)
chainA := coord.GetChain(wasmibctesting.GetChainID(1))
chainB := coord.GetChain(wasmibctesting.GetChainID(2))
coord := wasmibctesting.NewCoordinator2(t, 2)
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(1)))
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(wasmibctesting.GetChainID(2)))

actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address())
actorChainB := sdk.AccAddress(chainB.SenderPrivKey.PubKey().Address())
actorChainA := sdk.AccAddress(chainA.IbcChain.SenderPrivKey.PubKey().Address())
actorChainB := sdk.AccAddress(chainB.IbcChain.SenderPrivKey.PubKey().Address())
receiver := sdk.AccAddress(bytes.Repeat([]byte{1}, address.Len))
payee := sdk.AccAddress(bytes.Repeat([]byte{2}, address.Len))
oneToken := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1)))

path := wasmibctesting.NewPath(chainA, chainB)
path := ibctesting.NewPath(chainA.IbcChain, chainB.IbcChain)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: ibctransfertypes.PortID,
Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.V2})),
Expand All @@ -73,7 +73,7 @@ func TestIBCFeesTransfer(t *testing.T) {
}
// with an ics-20 transfer channel setup between both chains
coord.Setup(path)
appA := chainA.App.(*app.WasmApp)
appA := chainA.GetWasmApp()
require.True(t, appA.IBCFeeKeeper.IsFeeEnabled(chainA.GetContext(), ibctransfertypes.PortID, path.EndpointA.ChannelID))
// and with a payee registered on both chains
_, err := chainA.SendMsgs(ibcfee.NewMsgRegisterPayee(ibctransfertypes.PortID, path.EndpointA.ChannelID, actorChainA.String(), payee.String()))
Expand All @@ -86,14 +86,14 @@ func TestIBCFeesTransfer(t *testing.T) {
ibcPayloadMsg := ibctransfertypes.NewMsgTransfer(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, []sdk.Coin{transferCoin}, actorChainA.String(), receiver.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()), "testing", &ibctransfertypes.Forwarding{Unwind: false, Hops: []ibctransfertypes.Hop{}})
ibcPackageFee := ibcfee.NewFee(oneToken, oneToken, sdk.Coins{})
feeMsg := ibcfee.NewMsgPayPacketFee(ibcPackageFee, ibctransfertypes.PortID, path.EndpointA.ChannelID, actorChainA.String(), nil)
_, err = chainA.SendMsgs(feeMsg, ibcPayloadMsg)
result, err := chainA.SendMsgs(feeMsg, ibcPayloadMsg)
require.NoError(t, err)
pendingIncentivisedPackages := appA.IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(chainA.GetContext(), ibctransfertypes.PortID, path.EndpointA.ChannelID)
assert.Len(t, pendingIncentivisedPackages, 1)

require.NoError(t, err) // message committed

require.NoError(t, coord.RelayAndAckPendingPackets(path))
wasmibctesting.RelayAndAckPacket(t, path, result)

// then
expBalance := GetTransferCoin(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, transferCoin.Denom, transferCoin.Amount)
Expand All @@ -112,14 +112,14 @@ func TestIBCFeesTransfer(t *testing.T) {
ibcPayloadMsg = ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, []sdk.Coin{transferCoin}, actorChainB.String(), receiver.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()), "more testing", &ibctransfertypes.Forwarding{Unwind: false, Hops: []ibctransfertypes.Hop{}})
ibcPackageFee = ibcfee.NewFee(oneToken, oneToken, sdk.Coins{})
feeMsg = ibcfee.NewMsgPayPacketFee(ibcPackageFee, ibctransfertypes.PortID, path.EndpointB.ChannelID, actorChainB.String(), nil)
_, err = chainB.SendMsgs(feeMsg, ibcPayloadMsg)
result, err = chainB.SendMsgs(feeMsg, ibcPayloadMsg)
require.NoError(t, err)
appB := chainB.App.(*app.WasmApp)
appB := chainB.GetWasmApp()
pendingIncentivisedPackages = appB.IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(chainB.GetContext(), ibctransfertypes.PortID, path.EndpointB.ChannelID)
assert.Len(t, pendingIncentivisedPackages, 1)

// when packages relayed
require.NoError(t, coord.RelayAndAckPendingPackets(path))
wasmibctesting.RelayAndAckPacket(t, path, result)

// then
expBalance = GetTransferCoin(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, transferCoin.Denom, transferCoin.Amount)
Expand All @@ -136,11 +136,11 @@ func TestIBCFeesWasm(t *testing.T) {
// when an ics-29 fee is attached to an ibc package
// then the relayer's payee is receiving the fee(s) on success
marshaler := app.MakeEncodingConfig(t).Codec
coord := wasmibctesting.NewCoordinator(t, 2)
chainA := coord.GetChain(ibctesting.GetChainID(1))
chainB := coord.GetChain(ibctesting.GetChainID(2))
actorChainA := sdk.AccAddress(chainA.SenderPrivKey.PubKey().Address())
actorChainB := sdk.AccAddress(chainB.SenderPrivKey.PubKey().Address())
coord := wasmibctesting.NewCoordinator2(t, 2)
chainA := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(1)))
chainB := wasmibctesting.NewWasmTestChain(coord.GetChain(ibctesting.GetChainID(2)))
actorChainA := sdk.AccAddress(chainA.IbcChain.SenderPrivKey.PubKey().Address())
actorChainB := sdk.AccAddress(chainB.IbcChain.SenderPrivKey.PubKey().Address())

// setup chain A
codeID := chainA.StoreCodeFile("./testdata/cw20_base.wasm.gz").CodeID
Expand All @@ -156,7 +156,7 @@ func TestIBCFeesWasm(t *testing.T) {
payee := sdk.AccAddress(bytes.Repeat([]byte{2}, address.Len))
oneToken := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(1)))

path := wasmibctesting.NewPath(chainA, chainB)
path := ibctesting.NewPath(chainA.IbcChain, chainB.IbcChain)
path.EndpointA.ChannelConfig = &ibctesting.ChannelConfig{
PortID: ibcContractPortID,
Version: string(marshaler.MustMarshalJSON(&ibcfee.Metadata{FeeVersion: ibcfee.Version, AppVersion: ibctransfertypes.V1})),
Expand All @@ -169,8 +169,8 @@ func TestIBCFeesWasm(t *testing.T) {
}
// with an ics-29 fee enabled channel setup between both chains
coord.Setup(path)
appA := chainA.App.(*app.WasmApp)
appB := chainB.App.(*app.WasmApp)
appA := chainA.GetWasmApp()
appB := chainB.GetWasmApp()
require.True(t, appA.IBCFeeKeeper.IsFeeEnabled(chainA.GetContext(), ibcContractPortID, path.EndpointA.ChannelID))
require.True(t, appB.IBCFeeKeeper.IsFeeEnabled(chainB.GetContext(), ibctransfertypes.PortID, path.EndpointB.ChannelID))
// and with a payee registered for A -> B
Expand All @@ -189,13 +189,13 @@ func TestIBCFeesWasm(t *testing.T) {
}
ibcPackageFee := ibcfee.NewFee(oneToken, oneToken, sdk.Coins{})
feeMsg := ibcfee.NewMsgPayPacketFee(ibcPackageFee, ibcContractPortID, path.EndpointA.ChannelID, actorChainA.String(), nil)
_, err = chainA.SendMsgs(feeMsg, &execMsg)
result, err := chainA.SendMsgs(feeMsg, &execMsg)
require.NoError(t, err)
pendingIncentivisedPackages := appA.IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(chainA.GetContext(), ibcContractPortID, path.EndpointA.ChannelID)
assert.Len(t, pendingIncentivisedPackages, 1)

// and packages relayed
require.NoError(t, coord.RelayAndAckPendingPackets(path))
wasmibctesting.RelayAndAckPacket(t, path, result)

// then
// on chain A
Expand All @@ -221,13 +221,13 @@ func TestIBCFeesWasm(t *testing.T) {
ibcPayloadMsg := ibctransfertypes.NewMsgTransfer(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, []sdk.Coin{gotBalance}, actorChainB.String(), actorChainA.String(), clienttypes.Height{}, uint64(time.Now().Add(time.Minute).UnixNano()), "even more tests", &ibctransfertypes.Forwarding{Unwind: false, Hops: []ibctransfertypes.Hop{}})
ibcPackageFee = ibcfee.NewFee(oneToken, oneToken, sdk.Coins{})
feeMsg = ibcfee.NewMsgPayPacketFee(ibcPackageFee, ibctransfertypes.PortID, path.EndpointB.ChannelID, actorChainB.String(), nil)
_, err = chainB.SendMsgs(feeMsg, ibcPayloadMsg)
result, err = chainB.SendMsgs(feeMsg, ibcPayloadMsg)
require.NoError(t, err)
pendingIncentivisedPackages = appB.IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(chainB.GetContext(), ibctransfertypes.PortID, path.EndpointB.ChannelID)
assert.Len(t, pendingIncentivisedPackages, 1)

// when packages relayed
require.NoError(t, coord.RelayAndAckPendingPackets(path))
wasmibctesting.RelayAndAckPacket(t, path, result)

// then
// on chain A
Expand Down
Loading

0 comments on commit c666b00

Please sign in to comment.