Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICS 20 Cleanup and Tests #5577

Merged
merged 23 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d3ee967
Add comments, remove unused code and attempt to point to places where…
jackzampolin Jan 27, 2020
6adb6ed
Merge branch 'ibc-alpha' of https://github.com/cosmos/cosmos-sdk into…
fedekunze Jan 31, 2020
c6e2321
close channel when transfer fails
fedekunze Jan 31, 2020
965440f
rename packer data transfer to align to spec; refactor table tests
fedekunze Feb 3, 2020
05fee3f
ICS 20 implementation cleanup work (#5602)
cwgoes Feb 3, 2020
4ddaf28
Merge branch 'ibc-alpha' into jack/ics-20
cwgoes Feb 3, 2020
f068bf8
merge ibc-alpha
fedekunze Feb 18, 2020
61b7eee
Merge branch 'ibc-alpha' of https://github.com/cosmos/cosmos-sdk into…
fedekunze Feb 18, 2020
7dfd6b9
Merge PR #5603: Remove acknowledgement interface in favour of []byte
cwgoes Feb 18, 2020
6f5ad5c
fixes and cleanup
fedekunze Feb 19, 2020
f9fcce8
ibc alpha changes
fedekunze Feb 19, 2020
f56fd31
spec compliance
fedekunze Feb 19, 2020
1068bb5
refactor relay prefixes and tests
fedekunze Feb 19, 2020
37436b1
Fix test compilation
jackzampolin Feb 19, 2020
dac12e8
Merge branch 'ibc-alpha' of https://github.com/cosmos/cosmos-sdk into…
fedekunze Feb 20, 2020
05b3e48
cleanup; add notes and additional test case
fedekunze Feb 20, 2020
4f9763e
Receive transfer test
fedekunze Feb 20, 2020
4db79ba
Apply suggestions from code review
cwgoes Feb 20, 2020
e8cca15
Fix autolinter application
cwgoes Feb 20, 2020
4d14d36
Add testcase with incorrect prefix
cwgoes Feb 20, 2020
b31d01b
golangcibot fixes
fedekunze Feb 20, 2020
06fa17c
timeout test
fedekunze Feb 20, 2020
74815b6
delete extra comment
fedekunze Feb 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ func (coins Coins) Sort() Coins {
// Parsing

var (
// Denominations can be 3 ~ 32 characters long.
reDnmString = `[a-z][a-z0-9/]{2,31}`
// Denominations can be 3 ~ 64 characters long.
reDnmString = `[a-z][a-z0-9/]{2,63}`
reAmt = `[[:digit:]]+`
reDecAmt = `[[:digit:]]*\.[[:digit:]]+`
reSpc = `[[:space:]]*`
Expand Down
8 changes: 3 additions & 5 deletions x/ibc/20-transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ var (
testAddr1 = sdk.AccAddress([]byte("testaddr1"))
testAddr2 = sdk.AccAddress([]byte("testaddr2"))

testCoins, _ = sdk.ParseCoins("100atom")
destCoins = sdk.NewCoins(sdk.NewInt64Coin("bank/firstchannel/atom", 1000))
destCoins2 = sdk.NewCoins(sdk.NewInt64Coin("testportid/secondchannel/atom", 100))
testPrefixedCoins1, _ = sdk.ParseCoins(fmt.Sprintf("100%satom", types.GetDenomPrefix(testPort1, testChannel1)))
testPrefixedCoins2, _ = sdk.ParseCoins(fmt.Sprintf("100%satom", types.GetDenomPrefix(testPort2, testChannel2)))
testCoins, _ = sdk.ParseCoins("100atom")
prefixCoins = sdk.NewCoins(sdk.NewCoin("bank/firstchannel/atom", sdk.NewInt(100)))
prefixCoins2 = sdk.NewCoins(sdk.NewCoin("testportid/secondchannel/atom", sdk.NewInt(100)))
)

type KeeperTestSuite struct {
Expand Down
24 changes: 12 additions & 12 deletions x/ibc/20-transfer/keeper/relay.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -29,20 +30,20 @@ func (k Keeper) SendTransfer(
receiver sdk.AccAddress,
isSourceChain bool, // is the packet sender the source chain of the token?
) error {
// get the port and channel of the counterparty
sourceChan, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel)
sourceChannelEnd, found := k.channelKeeper.GetChannel(ctx, sourcePort, sourceChannel)
if !found {
return sdkerrors.Wrap(channel.ErrChannelNotFound, sourceChannel)
}

destinationPort := sourceChan.Counterparty.PortID
destinationChannel := sourceChan.Counterparty.ChannelID
destinationPort := sourceChannelEnd.Counterparty.PortID
destinationChannel := sourceChannelEnd.Counterparty.ChannelID

// get the next sequence
sequence, found := k.channelKeeper.GetNextSequenceSend(ctx, sourcePort, sourceChannel)
if !found {
return channel.ErrSequenceSendNotFound
}

return k.createOutgoingPacket(ctx, sequence, sourcePort, sourceChannel, destinationPort, destinationChannel, destHeight, amount, sender, receiver, isSourceChain)
}

Expand All @@ -60,14 +61,11 @@ func (k Keeper) TimeoutTransfer(ctx sdk.Context, packet channel.Packet, data typ
func (k Keeper) createOutgoingPacket(
ctx sdk.Context,
seq uint64,
sourcePort,
sourceChannel,
destinationPort,
destinationChannel string,
sourcePort, sourceChannel,
destinationPort, destinationChannel string,
destHeight uint64,
amount sdk.Coins,
sender sdk.AccAddress,
receiver sdk.AccAddress,
sender, receiver sdk.AccAddress,
isSourceChain bool,
) error {
// NOTE:
Expand All @@ -87,10 +85,12 @@ func (k Keeper) createOutgoingPacket(
if strings.HasPrefix(coin.Denom, prefix) {
coins[i] = sdk.NewCoin(coin.Denom[len(prefix):], coin.Amount)
} else {
coins[i] = amount[i]
coins[i] = coin
}
}

fmt.Println(coins)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved

// escrow tokens if the destination chain is the same as the sender's
escrowAddress := types.GetEscrowAddress(sourcePort, sourceChannel)

Expand Down Expand Up @@ -151,7 +151,7 @@ func (k Keeper) onRecvPacket(ctx sdk.Context, packet channel.Packet, data types.
// NOTE: packet data type already checked in handler.go

if data.Source {
prefix := types.GetDenomPrefix(packet.GetDestChannel(), packet.GetDestChannel())
prefix := types.GetDenomPrefix(packet.GetDestPort(), packet.GetDestChannel())
for _, coin := range data.Amount {
if !strings.HasPrefix(coin.Denom, prefix) {
return sdkerrors.Wrapf(
Expand Down
48 changes: 40 additions & 8 deletions x/ibc/20-transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func (suite *KeeperTestSuite) TestSendTransfer() {
testCoins2 := sdk.NewCoins(sdk.NewCoin("testportid/secondchannel/atom", sdk.NewInt(100)))
testCases := []struct {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
msg string
amount sdk.Coins
Expand All @@ -24,16 +25,18 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
suite.createChannel(testPort1, testChannel1, testConnection, testPort2, testChannel2, channelexported.OPEN)
suite.app.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.ctx, testPort1, testChannel1, 1)
}, true},
{"sucess transfer from source chain with denom prefix", destCoins2,
{"sucess transfer from source chain with denom prefix", testCoins2,
cwgoes marked this conversation as resolved.
Show resolved Hide resolved
true, func() {
suite.app.BankKeeper.AddCoins(suite.ctx, testAddr1, testCoins)
_, err := suite.app.BankKeeper.AddCoins(suite.ctx, testAddr1, testCoins)
suite.Require().NoError(err)
suite.createChannel(testPort1, testChannel1, testConnection, testPort2, testChannel2, channelexported.OPEN)
suite.app.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.ctx, testPort1, testChannel1, 1)
}, true},
{"sucess transfer from external chain", testCoins,
cwgoes marked this conversation as resolved.
Show resolved Hide resolved
false, func() {
suite.app.SupplyKeeper.SetSupply(suite.ctx, supply.NewSupply(destCoins))
suite.app.BankKeeper.AddCoins(suite.ctx, testAddr1, destCoins)
suite.app.SupplyKeeper.SetSupply(suite.ctx, supply.NewSupply(prefixCoins))
_, err := suite.app.BankKeeper.AddCoins(suite.ctx, testAddr1, prefixCoins)
suite.Require().NoError(err)
suite.createChannel(testPort1, testChannel1, testConnection, testPort2, testChannel2, channelexported.OPEN)
suite.app.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.ctx, testPort1, testChannel1, 1)
}, true},
Expand All @@ -51,7 +54,7 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
suite.app.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.ctx, testPort1, testChannel1, 1)
}, false},
// - receiving chain
{"send from module account dailed", testCoins,
{"send from module account failed", testCoins,
false, func() {
suite.createChannel(testPort1, testChannel1, testConnection, testPort2, testChannel2, channelexported.OPEN)
suite.app.IBCKeeper.ChannelKeeper.SetNextSequenceSend(suite.ctx, testPort1, testChannel1, 1)
Expand Down Expand Up @@ -79,13 +82,42 @@ func (suite *KeeperTestSuite) TestSendTransfer() {
}

func (suite *KeeperTestSuite) TestReceiveTransfer() {
var packet channeltypes.Packet
var data types.FungibleTokenPacketData
data := types.NewFungibleTokenPacketData(prefixCoins2, testAddr1, testAddr2, true, 100)

testCases := []struct {
msg string
malleate func()
expPass bool
}{}
}{
{"sucess receive from source chain",
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func() {}, true},
// onRecvPacket
// - source chain
{"no dest prefix on coin denom",
func() {
data.Amount = testCoins
}, false},
{"mint failed",
func() {
data.Amount = prefixCoins2
data.Amount[0].Amount = sdk.ZeroInt()
}, false},
// - receiving chain
{"no source prefix on coin denom",
func() {
data.Source = false
}, false},
{"sucess receive from external chain",
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func() {
data.Source = false
data.Amount = prefixCoins
escrow := types.GetEscrowAddress(testPort2, testChannel2)
_, err := suite.app.BankKeeper.AddCoins(suite.ctx, escrow, testCoins)
suite.Require().NoError(err)
}, true},
}

packet := channeltypes.NewPacket(data, 1, testPort1, testChannel1, testPort2, testChannel2)

for i, tc := range testCases {
tc := tc
Expand Down