-
Notifications
You must be signed in to change notification settings - Fork 656
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
feat: ParseKeyCounterpartyRelayer function #1047
Changes from 1 commit
0547b2c
e5c014b
ce027d7
73ee75d
21b6315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,11 +71,27 @@ func ParseKeyFeeEnabled(key string) (portID, channelID string, err error) { | |
return portID, channelID, nil | ||
} | ||
|
||
// KeyCounterpartyRelayer returns the key for relayer address -> counteryparty address mapping | ||
// KeyCounterpartyRelayer returns the key for relayer address -> counterparty address mapping | ||
func KeyCounterpartyRelayer(address, channelID string) []byte { | ||
return []byte(fmt.Sprintf("%s/%s/%s", CounterpartyRelayerAddressKeyPrefix, address, channelID)) | ||
} | ||
|
||
// ParseKeyCounterpartyRelayer returns the registered relayer address -> counterparty address mapping | ||
func ParseKeyCounterpartyRelayer(key string, counterpartyAddress string) (RegisteredRelayerAddress, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this function should just parse the key. It should be up to the caller to construct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed |
||
keySplit := strings.Split(key, "/") | ||
if len(keySplit) != 3 { | ||
return RegisteredRelayerAddress{}, sdkerrors.Wrapf( | ||
sdkerrors.ErrLogic, "key provided is incorrect: the key split has incorrect length, expected %d, got %d", 3, len(keySplit), | ||
) | ||
} | ||
|
||
return RegisteredRelayerAddress{ | ||
Address: keySplit[1], | ||
CounterpartyAddress: counterpartyAddress, | ||
ChannelId: keySplit[2], | ||
}, nil | ||
} | ||
|
||
// KeyForwardRelayerAddress returns the key for packetID -> forwardAddress mapping | ||
func KeyForwardRelayerAddress(packetId channeltypes.PacketId) []byte { | ||
return []byte(fmt.Sprintf("%s/%s/%s/%d", ForwardRelayerPrefix, packetId.PortId, packetId.ChannelId, packetId.Sequence)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,3 +134,39 @@ func TestParseKeyForwardRelayerAddress(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestParseKeyCounterpartyRelayer(t *testing.T) { | ||
var ( | ||
relayerAddress = "relayer_address" | ||
counterpartyRelayerAddress = "counterparty_address" | ||
) | ||
|
||
testCases := []struct { | ||
name string | ||
key string | ||
expPass bool | ||
}{ | ||
{ | ||
"success", | ||
string(types.KeyCounterpartyRelayer(relayerAddress, ibctesting.FirstChannelID)), | ||
true, | ||
}, | ||
{ | ||
"incorrect key - key split has incorrect length", | ||
"relayerAddress/relayer_address/transfer/channel-0", | ||
false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
registeredAddr, err := types.ParseKeyCounterpartyRelayer(tc.key, counterpartyRelayerAddress) | ||
validRegisteredAddr := types.RegisteredRelayerAddress{relayerAddress, counterpartyRelayerAddress, ibctesting.FirstChannelID} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could probably be removed now and you could do the require checks using the channelID and relayerAddress directly |
||
|
||
if tc.expPass { | ||
require.NoError(t, err) | ||
require.Equal(t, validRegisteredAddr, registeredAddr) | ||
} else { | ||
require.Error(t, err) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this
registeredArr
. I expect a variable likeaddr
being a byte array or string not a structThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll just have the function return the address and channel-id values from the key