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

chore: implement required FungibleTokenPacketData v3 interface methods #6126

Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dbe408a
chore: adding proto files for ics20-v2
chatton Apr 8, 2024
845b269
chore: add newline
chatton Apr 8, 2024
69b2643
chore: modify MsgTransfer to accept coins instead of coin
chatton Apr 8, 2024
8f4eaaa
Merge branch 'feat/ics20-v2' into cian/issue#5799-update-msg-transfer
chatton Apr 8, 2024
d8bfd45
chore: reverted unintentional comment changes
chatton Apr 8, 2024
e32a13d
chore: reverted unintentional comment changes
chatton Apr 8, 2024
e1b52c3
chore: adding test for conversion fn
chatton Apr 8, 2024
0e0e478
chore: fix e2e linter
chatton Apr 8, 2024
00e6c10
chore: adding docs
chatton Apr 8, 2024
8b5eb77
chore: addressing PR feedback
chatton Apr 8, 2024
62d76e9
chore: remove duplicate import
chatton Apr 8, 2024
2cc1804
chore: addressing PR feedback
chatton Apr 9, 2024
4b42e80
Merge branch 'cian/issue#5799-update-msg-transfer' into cian/issue#61…
chatton Apr 9, 2024
3da8e01
chore: moved extration logic into internal package
chatton Apr 9, 2024
dee5a30
chore: commented out failing test
chatton Apr 9, 2024
f7e5792
chore: adding link to issue
chatton Apr 9, 2024
bd34b69
Merge branch 'feat/ics20-v2' into cian/issue#6114-add-conversion-func…
chatton Apr 9, 2024
880b24d
chore: remove duplicate import
chatton Apr 9, 2024
8cad136
chore: fix linting errors
chatton Apr 9, 2024
5ebba40
FungibleTokenPacketData interface methods + tests
charleenfei Apr 9, 2024
867746f
linter
charleenfei Apr 9, 2024
24ed388
wip: token validation
charleenfei Apr 11, 2024
a666243
Merge branch 'cian/issue#6114-add-conversion-function' into charly/is…
charleenfei Apr 11, 2024
a85fa71
update trace identifier validation in Token + tests
charleenfei Apr 15, 2024
e10863e
rm Printf
charleenfei Apr 15, 2024
81c4d50
update with pr review
charleenfei Apr 15, 2024
15d949f
Merge branch 'feat/ics20-v2' into cian/issue#6114-add-conversion-func…
charleenfei Apr 16, 2024
555d2f2
pr review
charleenfei Apr 16, 2024
3b421b3
linter
charleenfei Apr 16, 2024
3f87adf
Merge branch 'cian/issue#6114-add-conversion-function' into charly/is…
charleenfei Apr 16, 2024
aa33c88
Merge branch 'feat/ics20-v2' into charly/issue#5795-implement-require…
charleenfei Apr 16, 2024
06ff045
rm unused function: linter
charleenfei Apr 16, 2024
1f6c780
wip pr feedback
charleenfei Apr 17, 2024
bae7e4f
fix test
charleenfei Apr 17, 2024
fa6c1ce
pr review
charleenfei Apr 18, 2024
8cb5d19
lintttttt
charleenfei Apr 18, 2024
3669a6c
update pr review
charleenfei Apr 22, 2024
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
Prev Previous commit
Next Next commit
chore: addressing PR feedback
chatton committed Apr 9, 2024

Verified

This commit was signed with the committer’s verified signature.
chatton Cian Hatton
commit 2cc1804e5400c3effbbe849ee2db8f24da685b47
88 changes: 48 additions & 40 deletions e2e/tests/transfer/authz_test.go
Original file line number Diff line number Diff line change
@@ -104,16 +104,18 @@ func (suite *AuthzTransferTestSuite) TestAuthz_MsgTransfer_Succeeds() {
t.Run("broadcast MsgGrant", createMsgGrantFn)

t.Run("broadcast MsgExec for ibc MsgTransfer", func(t *testing.T) {
transferMsg := transfertypes.MsgTransfer{
SourcePort: channelA.PortID,
SourceChannel: channelA.ChannelID,
Token: testvalues.DefaultTransferAmount(chainADenom),
Sender: granterAddress,
Receiver: receiverWalletAddress,
TimeoutHeight: suite.GetTimeoutHeight(ctx, chainB),
}

protoAny, err := codectypes.NewAnyWithValue(&transferMsg)
transferMsg := transfertypes.NewMsgTransfer(
channelA.PortID,
channelA.ChannelID,
testvalues.DefaultTransferCoins(chainADenom),
granterAddress,
receiverWalletAddress,
suite.GetTimeoutHeight(ctx, chainB),
0,
"",
)

protoAny, err := codectypes.NewAnyWithValue(transferMsg)
suite.Require().NoError(err)

msgExec := &authz.MsgExec{
@@ -161,16 +163,18 @@ func (suite *AuthzTransferTestSuite) TestAuthz_MsgTransfer_Succeeds() {
})

t.Run("exec unauthorized MsgTransfer", func(t *testing.T) {
transferMsg := transfertypes.MsgTransfer{
SourcePort: channelA.PortID,
SourceChannel: channelA.ChannelID,
Token: testvalues.DefaultTransferAmount(chainADenom),
Sender: granterAddress,
Receiver: receiverWalletAddress,
TimeoutHeight: suite.GetTimeoutHeight(ctx, chainB),
}

protoAny, err := codectypes.NewAnyWithValue(&transferMsg)
transferMsg := transfertypes.NewMsgTransfer(
channelA.PortID,
channelA.ChannelID,
testvalues.DefaultTransferCoins(chainADenom),
granterAddress,
receiverWalletAddress,
suite.GetTimeoutHeight(ctx, chainB),
0,
"",
)

protoAny, err := codectypes.NewAnyWithValue(transferMsg)
suite.Require().NoError(err)

msgExec := &authz.MsgExec{
@@ -241,16 +245,18 @@ func (suite *AuthzTransferTestSuite) TestAuthz_InvalidTransferAuthorizations() {
const invalidSpendAmount = spendLimit + 1

t.Run("broadcast MsgExec for ibc MsgTransfer", func(t *testing.T) {
transferMsg := transfertypes.MsgTransfer{
SourcePort: channelA.PortID,
SourceChannel: channelA.ChannelID,
Token: sdk.Coin{Denom: chainADenom, Amount: sdkmath.NewInt(invalidSpendAmount)},
Sender: granterAddress,
Receiver: receiverWalletAddress,
TimeoutHeight: suite.GetTimeoutHeight(ctx, chainB),
}

protoAny, err := codectypes.NewAnyWithValue(&transferMsg)
transferMsg := transfertypes.NewMsgTransfer(
channelA.PortID,
channelA.ChannelID,
sdk.NewCoins(sdk.Coin{Denom: chainADenom, Amount: sdkmath.NewInt(invalidSpendAmount)}),
granterAddress,
receiverWalletAddress,
suite.GetTimeoutHeight(ctx, chainB),
0,
"",
)

protoAny, err := codectypes.NewAnyWithValue(transferMsg)
suite.Require().NoError(err)

msgExec := &authz.MsgExec{
@@ -298,16 +304,18 @@ func (suite *AuthzTransferTestSuite) TestAuthz_InvalidTransferAuthorizations() {
invalidWalletAddress := invalidWallet.FormattedAddress()

t.Run("broadcast MsgExec for ibc MsgTransfer", func(t *testing.T) {
transferMsg := transfertypes.MsgTransfer{
SourcePort: channelA.PortID,
SourceChannel: channelA.ChannelID,
Token: sdk.Coin{Denom: chainADenom, Amount: sdkmath.NewInt(spendLimit)},
Sender: granterAddress,
Receiver: invalidWalletAddress,
TimeoutHeight: suite.GetTimeoutHeight(ctx, chainB),
}

protoAny, err := codectypes.NewAnyWithValue(&transferMsg)
transferMsg := transfertypes.NewMsgTransfer(
channelA.PortID,
channelA.ChannelID,
sdk.NewCoins(sdk.Coin{Denom: chainADenom, Amount: sdkmath.NewInt(spendLimit)}),
granterAddress,
invalidWalletAddress,
suite.GetTimeoutHeight(ctx, chainB),
0,
"",
)

protoAny, err := codectypes.NewAnyWithValue(transferMsg)
suite.Require().NoError(err)

msgExec := &authz.MsgExec{
4 changes: 4 additions & 0 deletions e2e/testvalues/values.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,10 @@ func DefaultTransferAmount(denom string) sdk.Coin {
return sdk.Coin{Denom: denom, Amount: sdkmath.NewInt(IBCTransferAmount)}
}

func DefaultTransferCoins(denom string) sdk.Coins {
return sdk.NewCoins(DefaultTransferAmount(denom))
}

func TransferAmount(amount int64, denom string) sdk.Coin {
return sdk.Coin{Denom: denom, Amount: sdkmath.NewInt(amount)}
}
38 changes: 20 additions & 18 deletions modules/apps/27-interchain-accounts/host/keeper/relay_test.go
Original file line number Diff line number Diff line change
@@ -342,15 +342,16 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

msg := &transfertypes.MsgTransfer{
SourcePort: transferPath.EndpointA.ChannelConfig.PortID,
SourceChannel: transferPath.EndpointA.ChannelID,
Token: sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100)),
Sender: interchainAccountAddr,
Receiver: suite.chainA.SenderAccount.GetAddress().String(),
TimeoutHeight: suite.chainB.GetTimeoutHeight(),
TimeoutTimestamp: uint64(0),
}
msg := transfertypes.NewMsgTransfer(
transferPath.EndpointA.ChannelConfig.PortID,
transferPath.EndpointA.ChannelID,
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100))),
interchainAccountAddr,
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainB.GetTimeoutHeight(),
0,
"",
)

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{msg}, encoding)
suite.Require().NoError(err)
@@ -376,15 +377,16 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
interchainAccountAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
suite.Require().True(found)

msg := &transfertypes.MsgTransfer{
SourcePort: transferPath.EndpointA.ChannelConfig.PortID,
SourceChannel: transferPath.EndpointA.ChannelID,
Token: sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100)),
Sender: interchainAccountAddr,
Receiver: "",
TimeoutHeight: suite.chainB.GetTimeoutHeight(),
TimeoutTimestamp: uint64(0),
}
msg := transfertypes.NewMsgTransfer(
transferPath.EndpointA.ChannelConfig.PortID,
transferPath.EndpointA.ChannelID,
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100))),
interchainAccountAddr,
"",
suite.chainB.GetTimeoutHeight(),
0,
"",
)

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []proto.Message{msg}, encoding)
suite.Require().NoError(err)
7 changes: 5 additions & 2 deletions modules/apps/transfer/types/transfer_authorization.go
Original file line number Diff line number Diff line change
@@ -44,6 +44,9 @@ func (a TransferAuthorization) Accept(ctx context.Context, msg proto.Message) (a
return authz.AcceptResponse{}, errorsmod.Wrap(ibcerrors.ErrInvalidType, "type mismatch")
}

// TODO: replace with correct usage in https://github.com/cosmos/ibc-go/issues/5802
token := msgTransfer.GetTokens()[0]

for index, allocation := range a.Allocations {
if !(allocation.SourceChannel == msgTransfer.SourceChannel && allocation.SourcePort == msgTransfer.SourcePort) {
continue
@@ -59,11 +62,11 @@ func (a TransferAuthorization) Accept(ctx context.Context, msg proto.Message) (a
}

// If the spend limit is set to the MaxUint256 sentinel value, do not subtract the amount from the spend limit.
if allocation.SpendLimit.AmountOf(msgTransfer.Token.Denom).Equal(UnboundedSpendLimit()) {
if allocation.SpendLimit.AmountOf(token.Denom).Equal(UnboundedSpendLimit()) {
return authz.AcceptResponse{Accept: true, Delete: false, Updated: nil}, nil
}

limitLeft, isNegative := allocation.SpendLimit.SafeSub(msgTransfer.Token)
limitLeft, isNegative := allocation.SpendLimit.SafeSub(token)
if isNegative {
return authz.AcceptResponse{}, errorsmod.Wrapf(ibcerrors.ErrInsufficientFunds, "requested amount is more than spend limit")
}
22 changes: 12 additions & 10 deletions modules/apps/transfer/types/transfer_authorization_test.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ const testMemo = `{"wasm":{"contract":"osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p

func (suite *TypesTestSuite) TestTransferAuthorizationAccept() {
var (
msgTransfer types.MsgTransfer
msgTransfer *types.MsgTransfer
transferAuthz types.TransferAuthorization
)

@@ -247,18 +247,20 @@ func (suite *TypesTestSuite) TestTransferAuthorizationAccept() {
},
}

msgTransfer = types.MsgTransfer{
SourcePort: path.EndpointA.ChannelConfig.PortID,
SourceChannel: path.EndpointA.ChannelID,
Token: ibctesting.TestCoin,
Sender: suite.chainA.SenderAccount.GetAddress().String(),
Receiver: ibctesting.TestAccAddress,
TimeoutHeight: suite.chainB.GetTimeoutHeight(),
}
msgTransfer = types.NewMsgTransfer(
path.EndpointA.ChannelConfig.PortID,
path.EndpointA.ChannelID,
sdk.NewCoins(ibctesting.TestCoin),
suite.chainA.SenderAccount.GetAddress().String(),
ibctesting.TestAccAddress,
suite.chainB.GetTimeoutHeight(),
0,
"",
)

tc.malleate()

res, err := transferAuthz.Accept(suite.chainA.GetContext(), &msgTransfer)
res, err := transferAuthz.Accept(suite.chainA.GetContext(), msgTransfer)
tc.assertResult(res, err)
})
}