Skip to content

Commit

Permalink
E2E: Failed token transfer receiver address is not valid (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton authored Aug 16, 2022
1 parent 7a34f6c commit b85c80f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/e2e-manual.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on:
default: main
options:
- main
- v4.0.0-rc3
- v4.0.0
- v3.0.0
- v2.2.0
- v2.1.0
Expand All @@ -41,7 +41,7 @@ on:
type: choice
options:
- main
- v4.0.0-rc3
- v4.0.0
- v3.0.0
- v2.2.0
- v2.1.0
Expand Down
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export CHAIN_A_SIMD_TAG="main"
# We can also specify different values for the chains if needed.
# they will default to the same as chain a.
# export CHAIN_B_SIMD_IMAGE="ghcr.io/cosmos/ibc-go-simd"
# export CHAIN_B_SIMD_TAG="pr-1650"
# export CHAIN_B_SIMD_TAG="main"

export RLY_TAG="v2.0.0-rc2"
make e2e-test suite=FeeMiddlewareTestSuite test=TestMultiMsg_MsgPayPacketFeeSingleSender
Expand Down
6 changes: 3 additions & 3 deletions e2e/scripts/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ set -euo pipefail

SUITE="${1}"
TEST="${2}"
export SIMD_TAG="${CHAIN_A_SIMD_TAG:-latest}"
export SIMD_IMAGE="${CHAIN_A_SIMD_IMAGE:-ibc-go-simd}"
export CHAIN_A_SIMD_TAG="${CHAIN_A_SIMD_TAG:-latest}"
export CHAIN_A_SIMD_IMAGE="${CHAIN_A_SIMD_IMAGE:-ibc-go-simd}"

# In CI, the docker images will be built separately.
# context for building the image is one directory up.
if [ "${CI:-}" != "true" ]
then
(cd ..; docker build . -t "${SIMD_IMAGE}:${SIMD_TAG}")
(cd ..; docker build . -t "${CHAIN_A_SIMD_IMAGE}:${CHAIN_A_SIMD_TAG}")
fi

go test -v ./ --run ${SUITE} -testify.m ^${TEST}$
47 changes: 47 additions & 0 deletions e2e/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,53 @@ func (s *TransferTestSuite) TestMsgTransfer_Succeeds_Nonincentivized() {
})
}

// TestMsgTransfer_Fails_InvalidAddress attempts to send an IBC transfer to an invalid address and ensures
// that the tokens on the sending chain are unescrowed.
func (s *TransferTestSuite) TestMsgTransfer_Fails_InvalidAddress() {
t := s.T()
ctx := context.TODO()

relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, transferChannelOptions())
chainA, chainB := s.GetChains()

chainADenom := chainA.Config().Denom

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.Bech32Address(chainA.Config().Bech32Prefix)

s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")

t.Run("native IBC token transfer from chainA to invalid address", func(t *testing.T) {
transferTxResp, err := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, testvalues.InvalidAddress, s.GetTimeoutHeight(ctx, chainB), 0)
s.Require().NoError(err)
s.AssertValidTxResponse(transferTxResp)
})

t.Run("tokens are escrowed", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)

expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance)
})

t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})

t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.PortID, channelA.ChannelID, 1)
})

t.Run("token transfer amount unescrowed", func(t *testing.T) {
actualBalance, err := s.GetChainANativeBalance(ctx, chainAWallet)
s.Require().NoError(err)

expected := testvalues.StartingTokenAmount
s.Require().Equal(expected, actualBalance)
})
}

// transferChannelOptions configures both of the chains to have non-incentivized transfer channels.
func transferChannelOptions() func(options *ibc.CreateChannelOptions) {
return func(opts *ibc.CreateChannelOptions) {
Expand Down

0 comments on commit b85c80f

Please sign in to comment.