-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: adding MsgServer for RegisterCounterPartyAddress & EscrowPacketFree * test: adding test for ValidateBasic * fix: removing validate basic check * fix: removing empty file * Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update modules/apps/29-fee/types/msgs.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update modules/apps/29-fee/types/keys.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * Update modules/apps/29-fee/keeper/keeper.go Co-authored-by: Aditya <adityasripal@gmail.com> * fix: fixing typos, variable names, comments * fix: updating import comments * test: adding test for KeyRelayerAddress * update: comments & key_test * Update modules/apps/29-fee/keeper/msg_server.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * fix: error message * docs: updating RegisterCounterpartyAddress fn description Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Aditya <adityasripal@gmail.com>
- Loading branch information
1 parent
c63af4a
commit e3704c6
Showing
12 changed files
with
222 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
package keeper | ||
|
||
// TODO | ||
//var _ types.MsgServer = Keeper{} | ||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
) | ||
|
||
var _ types.MsgServer = Keeper{} | ||
|
||
// RegisterCounterpartyAddress is called by the relayer on each channelEnd and allows them to specify their counterparty address before relaying | ||
// This ensures they will be properly compensated for forward relaying on the source chain since the destination chain must send back relayer's source address (counterparty address) in acknowledgement | ||
// This function may be called more than once by relayers, in which case, the previous counterparty address will be overwritten by the new counterparty address | ||
func (k Keeper) RegisterCounterpartyAddress(goCtx context.Context, msg *types.MsgRegisterCounterpartyAddress) (*types.MsgRegisterCounterpartyAddressResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
k.SetCounterpartyAddress( | ||
ctx, msg.Address, msg.CounterpartyAddress, | ||
) | ||
|
||
k.Logger(ctx).Info("Registering counterparty address for relayer.", "Address:", msg.Address, "Counterparty Address:", msg.CounterpartyAddress) | ||
|
||
return &types.MsgRegisterCounterpartyAddressResponse{}, nil | ||
} | ||
|
||
// EscrowPacketFee defines a rpc handler method for MsgEscrowPacketFee | ||
// EscrowPacketFee is an open callback that may be called by any module/user that wishes to escrow funds in order to | ||
// incentivize the relaying of the given packet. | ||
func (k Keeper) EscrowPacketFee(goCtx context.Context, msg *types.MsgEscrowPacketFee) (*types.MsgEscrowPacketFeeResponse, error) { | ||
return &types.MsgEscrowPacketFeeResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
package types | ||
|
||
// standard library imports | ||
import "fmt" | ||
|
||
const ( | ||
// ModuleName defines the 29-fee name | ||
ModuleName = "ibcfee" | ||
|
||
// StoreKey is the store key string for IBC transfer | ||
StoreKey = ModuleName | ||
|
||
// PortKey is the port id that is wrapped by fee middleware | ||
PortKey = "feetransfer" | ||
|
||
// RouterKey is the message route for IBC transfer | ||
RouterKey = ModuleName | ||
|
||
// QuerierRoute is the querier route for IBC transfer | ||
QuerierRoute = ModuleName | ||
|
||
// RelayerAddressKeyPrefix is the key prefix for relayer address mapping | ||
RelayerAddressKeyPrefix = "relayerAddress" | ||
) | ||
|
||
// KeyRelayerAddress returns the key for relayer address -> counteryparty address mapping | ||
func KeyRelayerAddress(address string) []byte { | ||
return []byte(fmt.Sprintf("%s/%s", RelayerAddressKeyPrefix, address)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package types_test | ||
|
||
import ( | ||
fmt "fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
) | ||
|
||
func TestKeyRelayerAddress(t *testing.T) { | ||
var ( | ||
relayerAddress = "relayer_address" | ||
) | ||
|
||
key := types.KeyRelayerAddress(relayerAddress) | ||
require.Equal(t, string(key), fmt.Sprintf("%s/relayer_address", types.RelayerAddressKeyPrefix)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
package types | ||
|
||
/* | ||
import ( | ||
"strings" | ||
// external library imports | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" | ||
host "github.com/cosmos/ibc-go/modules/core/24-host" | ||
) | ||
|
||
// NewMsg | ||
func NewMsg() *Msg { | ||
return &Msg{ | ||
// msg types | ||
const ( | ||
TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress" | ||
) | ||
|
||
// NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress | ||
func NewMsgRegisterCounterpartyAddress(address, counterpartyAddress string) *MsgRegisterCounterpartyAddress { | ||
return &MsgRegisterCounterpartyAddress{ | ||
Address: address, | ||
CounterpartyAddress: counterpartyAddress, | ||
} | ||
} | ||
|
||
// ValidateBasic performs a basic check of the Msg fields. | ||
func (msg Msg) ValidateBasic() error { | ||
// ValidateBasic performs a basic check of the MsgRegisterCounterpartyAddress fields | ||
func (msg MsgRegisterCounterpartyAddress) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Address) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "failed to convert msg.Address into sdk.AccAddress") | ||
} | ||
|
||
_, err = sdk.AccAddressFromBech32(msg.CounterpartyAddress) | ||
if err != nil { | ||
return sdkerrors.Wrap(err, "failed to convert msg.CounterpartyAddress into sdk.AccAddress") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetSigners implements sdk.Msg | ||
func (msg MsgTransfer) GetSigners() []sdk.AccAddress { | ||
signer, err := sdk.AccAddressFromBech32(msg.Sender) | ||
func (msg MsgRegisterCounterpartyAddress) GetSigners() []sdk.AccAddress { | ||
signer, err := sdk.AccAddressFromBech32(msg.Address) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{signer} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
package types | ||
|
||
/* | ||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
) | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
var ( | ||
validAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()).String() | ||
invalidAddr = "invalid_address" | ||
) | ||
|
||
func (suite *TypesTestSuite) TestMsgValidateBasic() { | ||
// TestMsgTransferValidation tests ValidateBasic for MsgTransfer | ||
func TestMsgRegisterCountepartyAddressValidation(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
msg *types.Msg | ||
msg *MsgRegisterCounterpartyAddress | ||
expPass bool | ||
}{ | ||
{"", types.NewMsg(), true}, | ||
{"validate with correct sdk.AccAddress", NewMsgRegisterCounterpartyAddress(validAddr, validAddr), true}, | ||
{"validate with incorrect destination relayer address", NewMsgRegisterCounterpartyAddress(invalidAddr, validAddr), false}, | ||
{"validate with incorrect counterparty relayer address", NewMsgRegisterCounterpartyAddress(validAddr, invalidAddr), false}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
suite.Run(tc.name, func() { | ||
err := tc.msg.ValidateBasic() | ||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
} else { | ||
suite.Require().Error(err) | ||
} | ||
}) | ||
for i, tc := range testCases { | ||
err := tc.msg.ValidateBasic() | ||
if tc.expPass { | ||
require.NoError(t, err, "valid test case %d failed: %s", i, tc.name) | ||
} else { | ||
require.Error(t, err, "invalid test case %d passed: %s", i, tc.name) | ||
} | ||
} | ||
} | ||
*/ |
Oops, something went wrong.