Skip to content

Commit

Permalink
refactor: remove the ability to take a fee for each forwarded packet (#…
Browse files Browse the repository at this point in the history
…202)

* refactor: remove the ability to take a fee that is sent to the community pool

* fix: mocks

* fix: remove WithFee unit test (no longer used due to fee refactor)

* fix(e2e): upgrade test

---------

Co-authored-by: Reece Williams <[email protected]>
(cherry picked from commit 26d8080)

# Conflicts:
#	middleware/packet-forward-middleware/e2e/forward_timeout_test.go
#	middleware/packet-forward-middleware/e2e/upgrade_test.go
#	middleware/packet-forward-middleware/go.mod
#	middleware/packet-forward-middleware/packetforward/client/cli/cli.go
#	middleware/packet-forward-middleware/packetforward/keeper/genesis.go
#	middleware/packet-forward-middleware/packetforward/keeper/grpc_query.go
#	middleware/packet-forward-middleware/packetforward/keeper/keeper.go
#	middleware/packet-forward-middleware/packetforward/keeper/params.go
#	middleware/packet-forward-middleware/packetforward/module.go
#	middleware/packet-forward-middleware/packetforward/module_test.go
#	middleware/packet-forward-middleware/packetforward/types/codec.go
#	middleware/packet-forward-middleware/packetforward/types/expected_keepers.go
#	middleware/packet-forward-middleware/packetforward/types/genesis.pb.go
#	middleware/packet-forward-middleware/packetforward/types/params.go
#	middleware/packet-forward-middleware/packetforward/types/query.pb.go
#	middleware/packet-forward-middleware/packetforward/types/query.pb.gw.go
#	middleware/packet-forward-middleware/proto/packetforward/v1/genesis.proto
#	middleware/packet-forward-middleware/proto/packetforward/v1/query.proto
#	middleware/packet-forward-middleware/test/mock/bank_keeper.go
#	middleware/packet-forward-middleware/test/mock/channel_keeper.go
#	middleware/packet-forward-middleware/test/mock/distribution_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
#	middleware/packet-forward-middleware/testing/simapp/app.go
#	middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go
  • Loading branch information
jtieri authored and mergify[bot] committed Jul 23, 2024
1 parent 5099c03 commit 7b58b87
Show file tree
Hide file tree
Showing 22 changed files with 1,870 additions and 242 deletions.
3 changes: 1 addition & 2 deletions middleware/packet-forward-middleware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ 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
go install go.uber.org/mock/mockgen@v0.4.0
mockgen -package=mock -destination=./test/mock/transfer_keeper.go $(GOMOD)/packetforward/types TransferKeeper
mockgen -package=mock -destination=./test/mock/distribution_keeper.go $(GOMOD)/packetforward/types DistributionKeeper
mockgen -package=mock -destination=./test/mock/bank_keeper.go $(GOMOD)/packetforward/types BankKeeper
mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/packetforward/types ChannelKeeper
mockgen -package=mock -destination=./test/mock/ics4_wrapper.go github.com/cosmos/ibc-go/v5/modules/core/05-port/types ICS4Wrapper
Expand Down
287 changes: 287 additions & 0 deletions middleware/packet-forward-middleware/e2e/forward_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,291 @@ func TestTimeoutOnForward(t *testing.T) {
require.True(t, firstHopEscrowBalance.Equal(zeroBal))
require.True(t, secondHopEscrowBalance.Equal(zeroBal))
require.True(t, thirdHopEscrowBalance.Equal(zeroBal))
<<<<<<< HEAD
=======

// Send IBC transfer from ChainA -> ChainB -> ChainC -> ChainD that will succeed
secondHopMetadata = &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userD.FormattedAddress(),
Channel: cdChan.ChannelID,
Port: cdChan.PortID,
},
}
nextBz, err = json.Marshal(secondHopMetadata)
require.NoError(t, err)
next = string(nextBz)

firstHopMetadata = &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userC.FormattedAddress(),
Channel: bcChan.ChannelID,
Port: bcChan.PortID,
Next: &next,
},
}

memo, err = json.Marshal(firstHopMetadata)
require.NoError(t, err)

opts = ibc.TransferOptions{
Memo: string(memo),
}

chainAHeight, err = chainA.Height(ctx)
require.NoError(t, err)

transferTx, err = chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, opts)
require.NoError(t, err)

_, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+30, transferTx.Packet)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 10, chainA)
require.NoError(t, err)

// Assert balances are updated to reflect tokens now being on ChainD
chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)

chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)

chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)

chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)

require.True(t, chainABalance.Equal(initBal.Sub(transferAmount)))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainDBalance.Equal(transferAmount))

firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)

secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)

thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)

require.True(t, firstHopEscrowBalance.Equal(transferAmount))
require.True(t, secondHopEscrowBalance.Equal(transferAmount))
require.True(t, thirdHopEscrowBalance.Equal(transferAmount))

// Compose IBC tx that will attempt to go from ChainD -> ChainC -> ChainB -> ChainA but timeout between ChainB->ChainA
transfer = ibc.WalletAmount{
Address: userC.FormattedAddress(),
Denom: thirdHopDenom,
Amount: transferAmount,
}

secondHopMetadata = &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userA.FormattedAddress(),
Channel: baChan.ChannelID,
Port: baChan.PortID,
Timeout: 1 * time.Second,
},
}
nextBz, err = json.Marshal(secondHopMetadata)
require.NoError(t, err)
next = string(nextBz)

firstHopMetadata = &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userB.FormattedAddress(),
Channel: cbChan.ChannelID,
Port: cbChan.PortID,
Next: &next,
},
}

memo, err = json.Marshal(firstHopMetadata)
require.NoError(t, err)

chainDHeight, err := chainD.Height(ctx)
require.NoError(t, err)

transferTx, err = chainD.SendIBCTransfer(ctx, dcChan.ChannelID, userD.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)

_, err = testutil.PollForAck(ctx, chainD, chainDHeight, chainDHeight+25, transferTx.Packet)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 5, chainD)
require.NoError(t, err)

// Assert balances to ensure timeout happened and user funds are still present on ChainD
chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)

chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)

chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)

chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)

require.True(t, chainABalance.Equal(initBal.Sub(transferAmount)))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainDBalance.Equal(transferAmount))

firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)

secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)

thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)

require.True(t, firstHopEscrowBalance.Equal(transferAmount))
require.True(t, secondHopEscrowBalance.Equal(transferAmount))
require.True(t, thirdHopEscrowBalance.Equal(transferAmount))

// ---

// Compose IBC tx that will go from ChainD -> ChainC -> ChainB -> ChainA and succeed.
transfer = ibc.WalletAmount{
Address: userC.FormattedAddress(),
Denom: thirdHopDenom,
Amount: transferAmount,
}

secondHopMetadata = &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userA.FormattedAddress(),
Channel: baChan.ChannelID,
Port: baChan.PortID,
},
}
nextBz, err = json.Marshal(secondHopMetadata)
require.NoError(t, err)
next = string(nextBz)

firstHopMetadata = &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userB.FormattedAddress(),
Channel: cbChan.ChannelID,
Port: cbChan.PortID,
Next: &next,
},
}

memo, err = json.Marshal(firstHopMetadata)
require.NoError(t, err)

chainDHeight, err = chainD.Height(ctx)
require.NoError(t, err)

transferTx, err = chainD.SendIBCTransfer(ctx, dcChan.ChannelID, userD.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)

_, err = testutil.PollForAck(ctx, chainD, chainDHeight, chainDHeight+25, transferTx.Packet)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 5, chainD)
require.NoError(t, err)

// Assert balances to ensure timeout happened and user funds are still present on ChainD
chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)

chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)

chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)

chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)

require.True(t, chainABalance.Equal(initBal))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainDBalance.Equal(zeroBal))

firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)

secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)

thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)

require.True(t, firstHopEscrowBalance.Equal(zeroBal))
require.True(t, secondHopEscrowBalance.Equal(zeroBal))
require.True(t, thirdHopEscrowBalance.Equal(zeroBal))

// ----- 2

// Compose IBC tx that will go from ChainD -> ChainC -> ChainB -> ChainA and succeed.
transfer = ibc.WalletAmount{
Address: userB.FormattedAddress(),
Denom: chainA.Config().Denom,
Amount: transferAmount,
}

firstHopMetadata = &PacketMetadata{
Forward: &ForwardMetadata{
Receiver: userA.FormattedAddress(),
Channel: baChan.ChannelID,
Port: baChan.PortID,
Timeout: 1 * time.Second,
},
}

memo, err = json.Marshal(firstHopMetadata)
require.NoError(t, err)

chainAHeight, err = chainA.Height(ctx)
require.NoError(t, err)

transferTx, err = chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)})
require.NoError(t, err)

_, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+25, transferTx.Packet)
require.NoError(t, err)

err = testutil.WaitForBlocks(ctx, 5, chainA)
require.NoError(t, err)

// Assert balances to ensure timeout happened and user funds are still present on ChainD
chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom)
require.NoError(t, err)

chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom)
require.NoError(t, err)

chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom)
require.NoError(t, err)

chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom)
require.NoError(t, err)

require.True(t, chainABalance.Equal(initBal))
require.True(t, chainBBalance.Equal(zeroBal))
require.True(t, chainCBalance.Equal(zeroBal))
require.True(t, chainDBalance.Equal(zeroBal))

firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom)
require.NoError(t, err)

secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom)
require.NoError(t, err)

thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom)
require.NoError(t, err)

require.True(t, firstHopEscrowBalance.Equal(zeroBal))
require.True(t, secondHopEscrowBalance.Equal(zeroBal))
require.True(t, thirdHopEscrowBalance.Equal(zeroBal))
>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202))
}
Loading

0 comments on commit 7b58b87

Please sign in to comment.