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

feat(ica)!: support json tx encoding for interchain accounts #3796

Merged
merged 141 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
c9d13c7
feat(ica): added EncodingJson to supported encodings
srdtrk May 30, 2023
fc7b2d1
imp(ica): changed the type of cdc to Codec in ica/host
srdtrk May 30, 2023
65bca55
imp(ica): changed the type of cdc to Codec in ica/controller
srdtrk May 30, 2023
3b19ac3
imp(ica.test): added a test cases for EncodingJSON
srdtrk May 30, 2023
ba73e12
imp(ica): created invalid encoding err
srdtrk May 30, 2023
d5f02cf
feat(ica)!: first prototype of json supporting DeserializeCosmosTx
srdtrk May 30, 2023
836dbb7
docs(ica): updated godoc of DeserializeCosmosTx
srdtrk May 30, 2023
57dfd22
docs(ica): added comments to DeserializeCosmosTx
srdtrk May 30, 2023
90907d7
fix(ica.test): fixed tests for DeserializeCosmosTx
srdtrk May 30, 2023
4af1a83
fix(ica): fixed 'OnRecvPacket' in relay.go
srdtrk May 30, 2023
e16a575
fix(ica): fixed unhandled error
srdtrk May 30, 2023
c4b246a
style(ica): made DeserializeCosmosTx more compact
srdtrk May 30, 2023
d08d066
fix(ica/host.cli.test): fixed a cli test
srdtrk May 30, 2023
882fa52
style(ica): ran gofumpt
srdtrk May 30, 2023
2eb410a
style(ica): changed err message
srdtrk May 30, 2023
19c7dc5
feat(ica): first prototype of SerializeCosmosTx is implemented
srdtrk May 31, 2023
66fe43d
fix(ica): fixed codec tests
srdtrk May 31, 2023
345febf
fix(ica/host.test): fix test
srdtrk May 31, 2023
3d5f1c0
fix(ica/host.test): fix test
srdtrk May 31, 2023
e0cde18
fix(ica/host.cli): cli always uses protobuf
srdtrk May 31, 2023
9834a20
nil(ica/host.test): removed unneeded comment
srdtrk May 31, 2023
318f591
fix(ica/controller.test): fix test
srdtrk May 31, 2023
b8208fd
fix(ica/controller.test): fix test
srdtrk May 31, 2023
f7ccaf6
fix(ica/controller.test): fix test
srdtrk May 31, 2023
cc3e293
fix(fee.test): fix test
srdtrk May 31, 2023
ed1edf9
nit: temporary save commit
srdtrk Jun 1, 2023
ae13295
fix(ica): fixed json serde tests not passing
srdtrk Jun 1, 2023
8c34e7d
merge: remote-tracking branch 'origin' into serdar/issue#3246-json-de…
srdtrk Jun 1, 2023
88fe02b
fix(ica): fix panic if message does not implement sdk.Msg
srdtrk Jun 1, 2023
a42145b
imp(ica): improved json serde functions
srdtrk Jun 1, 2023
200b282
style(ica): pleased the linter
srdtrk Jun 1, 2023
9602b47
style(ica): ran gofumpt
srdtrk Jun 1, 2023
97de732
merge: remote-tracking branch 'origin' into serdar/issue#3246-json-de…
srdtrk Jun 1, 2023
f3d9879
fix(e2e): fix compilation errors by adding icatypes.EncodingProtobuf …
srdtrk Jun 1, 2023
a0485f2
feat(ica.test): added important wip test for deserializing directly f…
srdtrk Jun 1, 2023
7bc2f41
imp(ica.test): added a new test case to cw codec unit test
srdtrk Jun 1, 2023
8869b7a
imp(ica): added another test case
srdtrk Jun 1, 2023
7987739
imp(ica.test): added another test case
srdtrk Jun 1, 2023
fb15e55
imp(ica.test): added another test case
srdtrk Jun 1, 2023
cb18323
style(ica.test): improved test style
srdtrk Jun 1, 2023
fef3871
style(ica.test): improved test style
srdtrk Jun 1, 2023
4b8c62f
style(ica.test): ran gofumpt
srdtrk Jun 1, 2023
9ed13d8
imp(ica.test): added json encoding version string for testing
srdtrk Jun 2, 2023
e5d6c68
imp(ica.test): added new 'NewJSONICAPath' function
srdtrk Jun 2, 2023
483937d
imp(ica.test): added encoding field to ica test setup functions
srdtrk Jun 2, 2023
99fb8e8
fix(ica.test): fixed test setups using the new encoding field
srdtrk Jun 2, 2023
1ee1fa7
feat(ica.test): added json test case
srdtrk Jun 2, 2023
550a314
style(ica.test): ran gofumpt
srdtrk Jun 2, 2023
53aeadd
feat(ica.test): got two cases of cosmwasm tests working in relay
srdtrk Jun 2, 2023
3aee5f0
merge: branch 'main' into serdar/issue#3246-json-decoding-for-ica
srdtrk Jun 2, 2023
2dc24bd
style(ica.test): ran gofumpt
srdtrk Jun 2, 2023
f033903
feat(ica): started progress on recursive handling of Anys
srdtrk Jun 2, 2023
509b625
imp(ica.test): added a new test case for ica json encoding, this fails
srdtrk Jun 2, 2023
3daf6e2
feat(ica): achieved total json serialization (excluding any lists)
srdtrk Jun 3, 2023
1e8cbe3
refactor(ica): made function shorter and removed duplicated code
srdtrk Jun 3, 2023
2d50034
style(ica): ran gofumpt
srdtrk Jun 3, 2023
86e5407
imp(ica): added more err handling code
srdtrk Jun 4, 2023
da2801a
refactor(ica): made deserialize code shorter
srdtrk Jun 4, 2023
5785d02
style(ica): made linter a bit more happy
srdtrk Jun 4, 2023
3f389ea
fix(ica.test): fixed one codec test case
srdtrk Jun 4, 2023
e5d982e
feat(ica): added []Any handling code
srdtrk Jun 5, 2023
3bde3dc
fix(ica): added more safety
srdtrk Jun 5, 2023
db4fd5b
nit: deleted testing codec.go
srdtrk Jun 5, 2023
14b3f0d
feat(ica): all works
srdtrk Jun 5, 2023
12b20ec
style(ica): ran gofumpt
srdtrk Jun 5, 2023
e2ad1a1
style(ica): made linter happy
srdtrk Jun 5, 2023
437fd25
refactor(ica): reduced code duplication
srdtrk Jun 5, 2023
f732702
nit(ica): uncommented some test cases
srdtrk Jun 5, 2023
95ccad3
imp(ica.test): added more test cases
srdtrk Jun 5, 2023
ea3792d
feat(ica.test): finished test cases
srdtrk Jun 6, 2023
4f3e7d6
style(ica.test): reorganized test cases
srdtrk Jun 6, 2023
32e91e9
refactor(ica.test): combined the two test cases into one
srdtrk Jun 6, 2023
f9bab4c
style(ica.test): ran gofumpt
srdtrk Jun 6, 2023
6bd1b47
style(ica.test): renamed wallet address
srdtrk Jun 6, 2023
f0ca07d
merge: branch 'main' into serdar/issue#3246-json-decoding-for-ica
srdtrk Jun 6, 2023
e7eabe5
fix(ica.test): fixed test case names
srdtrk Jun 7, 2023
67d02f0
imp(ica.test): added more test cases
srdtrk Jun 7, 2023
ae8aa60
style(ica.test): ran gofumpt
srdtrk Jun 7, 2023
2d01c88
test(ica): added more codec test cases
srdtrk Jun 7, 2023
e331980
merge: branch 'main' into serdar/issue#3246-json-decoding-for-ica
srdtrk Jun 7, 2023
1bd9af7
style(ica.test): ran gofumpt
srdtrk Jun 7, 2023
59d9c2e
feat(ica): removed JSONAny and JSONCosmosTx types
srdtrk Jun 7, 2023
e657656
feat(ica): implemented json encoding using module codec
srdtrk Jun 8, 2023
92648d8
fix(ica.test): tests now match the new codec implementation
srdtrk Jun 8, 2023
d52962d
fix(ica.test): fixed the tests to the new implementation
srdtrk Jun 8, 2023
4749442
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 8, 2023
172879d
style(ica.test): reorgenized the order of tests so that git diff make…
srdtrk Jun 8, 2023
4e18bad
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 8, 2023
3b5b872
imp(ica/controller): controller codec need not be codec.Codec
srdtrk Jun 14, 2023
ade40de
imp(ica): replaced BinaryCodec with Codec
srdtrk Jun 14, 2023
12b556c
test(ica): fixed codec test
srdtrk Jun 14, 2023
5e530b8
docs(ica.test): codec comment updated
srdtrk Jun 14, 2023
575220c
docs(ica.test): updated comments
srdtrk Jun 14, 2023
dbaed63
style(ica.test): removed 'from cosmwasm' from test case name as it is…
srdtrk Jun 14, 2023
b8b41ac
style(ica.test): ran gofumpt
srdtrk Jun 14, 2023
6eff38c
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 14, 2023
2e3914c
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 15, 2023
4597a8b
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 17, 2023
1767dcc
fix: fix merge error
srdtrk Jun 17, 2023
b169aa7
deps(ica): replaced sdk.NewInt with sdkmath.NewInt
srdtrk Jun 17, 2023
5cd75c9
style(ica): ran 'gofumpt'
srdtrk Jun 17, 2023
48aa851
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 20, 2023
936e7a9
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 23, 2023
5123fba
imp(ica): removed redundant cosmwasm tests
srdtrk Jun 24, 2023
e893d21
revert: "imp(ica): removed redundant cosmwasm tests"
srdtrk Jun 26, 2023
2581cc1
imp(ica.test): made codec_test human readable
srdtrk Jun 26, 2023
a06a882
imp(ica.test): made relay_test human readable
srdtrk Jun 26, 2023
1bb2c9f
style(ica.test): ran 'golanci-lint run --fix'
srdtrk Jun 26, 2023
954f12e
Merge branch 'main' into serdar/issue#3246-alternative-approach
Jun 27, 2023
0dca4ae
merge: branch 'main' into fix-json-merge
srdtrk Jun 27, 2023
5a0cd81
merge: branch 'fix-json-merge' into serdar/issue#3246-alternative-app…
srdtrk Jun 27, 2023
10d79db
imp(ica/host): created 'GetAppMetadata' function
srdtrk Jun 27, 2023
2955eb9
refactor(ica/host): used GetAppMetadata function
srdtrk Jun 27, 2023
3ae45fa
imp(ica.test): removed unneeded encoding argument
srdtrk Jun 27, 2023
0813c59
imp(ica): removed ErrUnsupportedEncoding
srdtrk Jun 27, 2023
6b7ac18
imp(ica.test): used suite chainB height instead of clienttypes.NewHei…
srdtrk Jun 27, 2023
30dfe0f
imp(ica.test): add nil check for unsupported encoding
srdtrk Jun 27, 2023
f4112e7
imp(ica.test): added a empty/nil checks
srdtrk Jun 27, 2023
45bb7a7
style(ica.test): renamed version variable to TestVersionWithJSONEncoding
srdtrk Jun 27, 2023
9a87cee
imp(ica): wrapped some errors
srdtrk Jun 27, 2023
048bedd
style(ica): ran 'golanci-lint run --fix'
srdtrk Jun 27, 2023
704a99f
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jun 28, 2023
635a878
style(ica)!: renamed EncodingJSON to EncodingProto3JSON
srdtrk Jun 28, 2023
cb5d44d
docs(ica): improved godocs
srdtrk Jun 28, 2023
4408877
imp(ica): passing codec instead of binary codec
srdtrk Jun 28, 2023
7a66beb
style(ica): improved error messages and godocs
srdtrk Jun 28, 2023
85eb946
docs(ica.test): improved godocs for tests
srdtrk Jun 28, 2023
ab72e95
imp(ica.test): improved unsupported encoding test case slightly
srdtrk Jun 28, 2023
3b4e389
style(ica.test): test style improvements
srdtrk Jun 28, 2023
5b7c709
imp(ica.test): added expError to some codec tests
srdtrk Jun 28, 2023
b4cbe28
imp(ica.test): added more error type checks to codec tests
srdtrk Jun 28, 2023
7e2b841
style(ica.test): ran 'golangci-lint run --fix'
srdtrk Jun 28, 2023
985632f
imp(ica/host.test): added 'TestMetadataNotFound'
srdtrk Jun 28, 2023
b771d3f
imp(ica/host.test): reduce test size
srdtrk Jun 28, 2023
68db856
docs(ica/host.test): updated godocs for test
srdtrk Jul 2, 2023
d0b2483
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 2, 2023
f6abbb1
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 3, 2023
6a7c8f9
docs(ica/host): improved godoc
srdtrk Jul 3, 2023
9010228
imp(ica/host): made GetAppMetadata private
srdtrk Jul 3, 2023
9c3ef7e
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 3, 2023
e81ac1f
merge: branch 'main' into serdar/issue#3246-alternative-approach
srdtrk Jul 3, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func TestGeneratePacketData(t *testing.T) {
require.Equal(t, tc.memo, packetData.Memo)

data := packetData.Data
// cli tx commands always use protobuf encoding
messages, err := icatypes.DeserializeCosmosTx(cdc, data, icatypes.EncodingProtobuf)

require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ func (suite *KeeperTestSuite) TestGenesisParams() {
func (suite *KeeperTestSuite) TestExportGenesis() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
err := SetupICAPath(path, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (suite *KeeperTestSuite) openAndCloseChannel(path *ibctesting.Path) {
suite.Require().NoError(err)

path.EndpointA.ChannelID = ""
err = RegisterInterchainAccount(path.EndpointA, TestOwnerAddress)
err = RegisterInterchainAccount(path.EndpointA, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

// bump channel sequence as these test mock core IBC behaviour on ChanOpenTry
Expand Down Expand Up @@ -276,10 +276,10 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewICAPath(suite.chainA, suite.chainB)
path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress)
err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

// set the channel id on host
Expand Down Expand Up @@ -356,10 +356,10 @@ func (suite *KeeperTestSuite) TestOnChanOpenConfirm() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewICAPath(suite.chainA, suite.chainB)
path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress)
err := RegisterInterchainAccount(path.EndpointA, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

err = path.EndpointB.ChanOpenTry()
Expand Down Expand Up @@ -399,10 +399,10 @@ func (suite *KeeperTestSuite) TestOnChanCloseConfirm() {
suite.Run(tc.name, func() {
suite.SetupTest() // reset

path = NewICAPath(suite.chainA, suite.chainB)
path = NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
err := SetupICAPath(path, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

tc.malleate() // malleate mutates test data
Expand Down
60 changes: 45 additions & 15 deletions modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ var (
Encoding: icatypes.EncodingProtobuf,
TxType: icatypes.TxTypeSDKMultiMsg,
}))

// TestJSONVersion defines a reusable interchainaccounts version string that uses JSON encoding for testing purposes
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
TestJSONVersion = string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
Version: icatypes.Version,
ControllerConnectionId: ibctesting.FirstConnectionID,
HostConnectionId: ibctesting.FirstConnectionID,
Encoding: icatypes.EncodingJSON,
TxType: icatypes.TxTypeSDKMultiMsg,
}))
)

type KeeperTestSuite struct {
Expand All @@ -47,21 +56,32 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.chainC = suite.coordinator.GetChain(ibctesting.GetChainID(3))
}

func NewICAPath(chainA, chainB *ibctesting.TestChain) *ibctesting.Path {
func NewICAPath(chainA, chainB *ibctesting.TestChain, encoding string) *ibctesting.Path {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] is it worth using an enum or type alias for an encoding type instead of a string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't because the original proto didn't include an enum. I'll implement it if others agree

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to make this change, previously I don't think the encoding type as a string was exposed to any public interfaces, but these changes will make that the case. Also happy with a follow up PR making only these changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the enum type!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into using enums and will probably make this change soon but here is something I've noticed:

  • You cannot customise the stringer by using gogoproto extensions. But we need a custom stringer for backwards compatibility (this is because we need the ENCODING_PROTO3 enum variant to become "proto3"). Which means we must disable the default stringer (which is something the extensions can do), and write our own stringer in metadata.go.

This feels over-complicated for this functionality. Nevertheless, I'll make the change and see what happens.

Copy link
Member Author

@srdtrk srdtrk Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually sorry, this works: (but it looks weird due to using non-capitalized enum variants):

// Encoding defines the supported codec formats for interchain account transactions
enum Encoding {
  option (gogoproto.goproto_enum_prefix) = false;

  // Default zero value enumeration
  ENCODING_UNKNOWN_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNKNOWN"];
  // proto3 defines the proto3 protobuf encoding
  proto3 = 1 [(gogoproto.enumvalue_customname) = "PROTO3"];
  // proto3json defines the proto3 json encoding
  proto3json = 2 [(gogoproto.enumvalue_customname) = "PROTO3JSON"];
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, after attempting to implement this, I realized this would require reopening of the merged PR to the main, see #3967. Which leads me to think that it is best done in another PR to main, either after this is merged, or before. So I will not push the changes here. I will discuss this briefly in the engineering call

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree it should be discussed in a separate pr. As a side note, enums are encoded differently between standard json and proto3 json. Currently ICA uses proto3 json for encoding the metadata, if it used standard json this change wouldn't be backwards compatible

The enum string value for proto3 must be the same as the existing string otherwise we will break cross compatibility for opening channels

I would also not backport this change

path := ibctesting.NewPath(chainA, chainB)

var version string
switch encoding {
case icatypes.EncodingProtobuf:
version = TestVersion
case icatypes.EncodingJSON:
version = TestJSONVersion
default:
panic("unsupported encoding")
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
}

path.EndpointA.ChannelConfig.PortID = icatypes.HostPortID
path.EndpointB.ChannelConfig.PortID = icatypes.HostPortID
path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED
path.EndpointA.ChannelConfig.Version = TestVersion
path.EndpointB.ChannelConfig.Version = TestVersion
path.EndpointA.ChannelConfig.Version = version
path.EndpointB.ChannelConfig.Version = version

return path
}

// SetupICAPath invokes the InterchainAccounts entrypoint and subsequent channel handshake handlers
func SetupICAPath(path *ibctesting.Path, owner string) error {
if err := RegisterInterchainAccount(path.EndpointA, owner); err != nil {
func SetupICAPath(path *ibctesting.Path, owner string, encoding string) error {
if err := RegisterInterchainAccount(path.EndpointA, owner, encoding); err != nil {
return err
}

Expand All @@ -77,15 +97,25 @@ func SetupICAPath(path *ibctesting.Path, owner string) error {
}

// RegisterInterchainAccount is a helper function for starting the channel handshake
func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string) error {
func RegisterInterchainAccount(endpoint *ibctesting.Endpoint, owner string, encoding string) error {
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
portID, err := icatypes.NewControllerPortID(owner)
if err != nil {
return err
}

channelSequence := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.GetNextChannelSequence(endpoint.Chain.GetContext())

if err := endpoint.Chain.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, TestVersion); err != nil {
var version string
switch encoding {
case icatypes.EncodingProtobuf:
version = TestVersion
case icatypes.EncodingJSON:
version = TestJSONVersion
default:
return icatypes.ErrUnsupportedEncoding
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
}

if err := endpoint.Chain.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(endpoint.Chain.GetContext(), endpoint.ConnectionID, owner, version); err != nil {
srdtrk marked this conversation as resolved.
Show resolved Hide resolved
return err
}

Expand All @@ -106,10 +136,10 @@ func TestKeeperTestSuite(t *testing.T) {
func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
err := SetupICAPath(path, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

counterpartyPortID := path.EndpointA.ChannelConfig.PortID
Expand All @@ -131,10 +161,10 @@ func (suite *KeeperTestSuite) TestGetAllActiveChannels() {

suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
err := SetupICAPath(path, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

suite.chainB.GetSimApp().ICAHostKeeper.SetActiveChannelID(suite.chainB.GetContext(), ibctesting.FirstConnectionID, expectedPortID, expectedChannelID)
Expand Down Expand Up @@ -165,10 +195,10 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {

suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
err := SetupICAPath(path, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

interchainAccAddr, exists := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
Expand Down Expand Up @@ -197,10 +227,10 @@ func (suite *KeeperTestSuite) TestGetAllInterchainAccounts() {
func (suite *KeeperTestSuite) TestIsActiveChannel() {
suite.SetupTest()

path := NewICAPath(suite.chainA, suite.chainB)
path := NewICAPath(suite.chainA, suite.chainB, icatypes.EncodingProtobuf)
suite.coordinator.SetupConnections(path)

err := SetupICAPath(path, TestOwnerAddress)
err := SetupICAPath(path, TestOwnerAddress, icatypes.EncodingProtobuf)
suite.Require().NoError(err)

isActive := suite.chainB.GetSimApp().ICAHostKeeper.IsActiveChannel(suite.chainB.GetContext(), ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID)
Expand Down
12 changes: 11 additions & 1 deletion modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) ([]byt
return nil, errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain account packet data")
}

appVersion, found := k.GetAppVersion(ctx, packet.DestinationPort, packet.DestinationChannel)
if !found {
return nil, errorsmod.Wrapf(ibcerrors.ErrNotFound, "app version not found for port %s and channel %s", packet.DestinationPort, packet.DestinationChannel)
}
var metadata icatypes.Metadata
if err := icatypes.ModuleCdc.UnmarshalJSON([]byte(appVersion), &metadata); err != nil {
// UnmarshalJSON errors are indeterminate and therefore are not wrapped and included in failed acks
return nil, errorsmod.Wrapf(icatypes.ErrUnknownDataType, "cannot unmarshal ICS-27 interchain accounts metadata")
}
srdtrk marked this conversation as resolved.
Show resolved Hide resolved

switch data.Type {
case icatypes.EXECUTE_TX:
msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data, icatypes.EncodingProtobuf)
msgs, err := icatypes.DeserializeCosmosTx(k.cdc, data.Data, metadata.Encoding)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed to deserialize interchain account transaction")
}
Expand Down
Loading