diff --git a/Cargo.lock b/Cargo.lock index 69fa88d..34cec2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,6 +13,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "anybuf" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb5f1dee23caf80904249463cc4493b6789c2250f88c8f8d9160de5c6099bfe7" + [[package]] name = "anyhow" version = "1.0.86" @@ -130,9 +136,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.98" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +checksum = "5208975e568d83b6b05cc0a063c8e7e9acc2b43bee6da15616a5b73e109d7437" [[package]] name = "cfg-if" @@ -341,6 +347,7 @@ dependencies = [ name = "cw-ibc-lite-ics26-router" version = "0.1.0" dependencies = [ + "anybuf", "cosmwasm-schema", "cosmwasm-std", "cw-ibc-lite-ics02-client", @@ -357,6 +364,7 @@ dependencies = [ name = "cw-ibc-lite-shared" version = "0.1.0" dependencies = [ + "anybuf", "cosmwasm-schema", "cosmwasm-std", "cw-ibc-lite-derive", @@ -485,7 +493,7 @@ checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -517,7 +525,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -580,9 +588,9 @@ dependencies = [ [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" @@ -1055,7 +1063,7 @@ source = "git+https://github.com/srdtrk/ibc-rs?branch=serdar/xxx-allow-ibc-lite- dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -1227,9 +1235,9 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1254,7 +1262,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -1336,7 +1344,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -1361,9 +1369,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] @@ -1379,22 +1387,22 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -1405,14 +1413,14 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" dependencies = [ "itoa", "ryu", @@ -1427,7 +1435,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -1492,9 +1500,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "subtle-encoding" @@ -1524,9 +1532,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.66" +version = "2.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "201fcda3845c23e8212cd466bfebf0bd20694490fc0356ae8e428e0824a915a6" dependencies = [ "proc-macro2", "quote", @@ -1608,7 +1616,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] [[package]] @@ -1682,5 +1690,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.69", ] diff --git a/Cargo.toml b/Cargo.toml index 64d5257..31bd6e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ cw-ibc-lite-ics02-client = { version = "0.1.0", path = "./contracts/ics02-client cw-ibc-lite-ics26-router = { version = "0.1.0", path = "./contracts/ics26-router/", default-features = false } sha2 = "0.10.8" ibc-proto = { version = "0.46.0", default-features = false } +anybuf = "0.5.0" derive_more = { version = "0.99.18", default-features = false, features = [ "from", "into", "display", "try_into" ] } proc-macro2 = "1.0" quote = "1.0" diff --git a/contracts/ics20-transfer/src/ibc/relay.rs b/contracts/ics20-transfer/src/ibc/relay.rs index eef1688..2dea4af 100644 --- a/contracts/ics20-transfer/src/ibc/relay.rs +++ b/contracts/ics20-transfer/src/ibc/relay.rs @@ -79,8 +79,8 @@ pub fn on_recv_packet( let ics20_packet: Ics20Packet = cosmwasm_std::from_json(packet.data)?; let base_denom = utils::transfer::parse_voucher_denom( &ics20_packet.denom, - port_id.as_str(), - packet.destination_channel.as_str(), + packet.source_port.as_str(), + packet.source_channel.as_str(), )?; // Subtract amount from the escrowed balance. diff --git a/contracts/ics26-router/Cargo.toml b/contracts/ics26-router/Cargo.toml index 5bf4284..395e9e1 100644 --- a/contracts/ics26-router/Cargo.toml +++ b/contracts/ics26-router/Cargo.toml @@ -27,3 +27,4 @@ cw-ibc-lite-shared = { workspace = true } cw-ibc-lite-ics02-client = { workspace = true } ibc-client-cw = { workspace = true } cw-ownable = { workspace = true } +anybuf = { workspace = true } diff --git a/contracts/ics26-router/src/contract.rs b/contracts/ics26-router/src/contract.rs index af9afc7..1ce2604 100644 --- a/contracts/ics26-router/src/contract.rs +++ b/contracts/ics26-router/src/contract.rs @@ -400,12 +400,11 @@ mod reply { ) -> Result { match result { SubMsgResult::Ok(resp) => { - // TODO: allow depracated until we have working tests and then change it. - #[allow(deprecated)] - let ack: ibc::Acknowledgement = resp - .data - .ok_or(ContractError::RecvPacketCallbackNoResponse)? - .try_into()?; + let ack = ibc::Acknowledgement::new( + anybuf::Bufany::deserialize(&resp.msg_responses[0].value)? + .bytes(1) + .unwrap(), + ); let packet: ibc::Packet = cosmwasm_std::from_json(payload)?; state::helpers::commit_packet_ack(deps.storage, &packet, &ack)?; diff --git a/e2e/interchaintestv8/chainconfig/chain_config.go b/e2e/interchaintestv8/chainconfig/chain_config.go index 932a351..1561f62 100644 --- a/e2e/interchaintestv8/chainconfig/chain_config.go +++ b/e2e/interchaintestv8/chainconfig/chain_config.go @@ -39,7 +39,7 @@ var DefaultChainSpecs = []*interchaintest.ChainSpec{ Images: []ibc.DockerImage{ { Repository: "ghcr.io/cosmos/ibc-go-simd", // FOR LOCAL IMAGE USE: Docker Image Name - Version: "serdar-xxx-ibc-lite-e2e-image", // FOR LOCAL IMAGE USE: Docker Image Tag + Version: "serdar-xxx-ibc-lite-e2e-debug", // FOR LOCAL IMAGE USE: Docker Image Tag UidGid: "1025:1025", }, }, diff --git a/e2e/interchaintestv8/ibclite_test.go b/e2e/interchaintestv8/ibclite_test.go index 7d0f929..dab79b3 100644 --- a/e2e/interchaintestv8/ibclite_test.go +++ b/e2e/interchaintestv8/ibclite_test.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" "testing" + "time" "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" @@ -16,6 +17,7 @@ import ( sdkmath "cosmossdk.io/math" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" abci "github.com/cometbft/cometbft/abci/types" @@ -121,6 +123,8 @@ func (s *IBCLiteTestSuite) SetupSuite(ctx context.Context) { s.Require().Len(resp.Contracts, 1) s.Require().NotEmpty(resp.Contracts[0]) + // ics02Client is instantiated by ics26Router, so we need to fetch it from the response + // and cast it to the correct type s.ics02Client, err = ics02client.NewContract(resp.Contracts[0], ics02CodeId, wasmd) s.Require().NoError(err) })) @@ -158,7 +162,6 @@ func (s *IBCLiteTestSuite) SetupSuite(ctx context.Context) { CounterpartyInfo: &ics02client.CounterpartyInfo{ ClientId: ibctesting.FirstClientID, MerklePathPrefix: &ics02client.MerklePath{ - // TODO: make sure this is correct KeyPath: []string{ibcexported.StoreKey, ""}, }, }, @@ -283,7 +286,7 @@ func (s *IBCLiteTestSuite) TestCW20Transfer() { res, err := s.cw20Base.Execute(ctx, s.UserA.KeyName(), cw20SendMsg, "--gas", "500000") s.Require().NoError(err) - packet, err = s.ExtractPacketFromWasmEvents(res.Events) + packet, err = s.ExtractPacketFromEvents(res.Events) s.Require().NoError(err) })) @@ -326,7 +329,10 @@ func (s *IBCLiteTestSuite) TestCW20Transfer() { s.Require().Equal(expCommitment, value) })) - var acknowledgement []byte + var ( + acknowledgement []byte + simdCoin *sdk.Coin + ) s.Require().True(s.Run("RecvPacket", func() { recvMsg := &channeltypes.MsgRecvPacket{ Packet: packet, @@ -338,24 +344,27 @@ func (s *IBCLiteTestSuite) TestCW20Transfer() { txResp, err := s.BroadcastMessages(ctx, simd, s.UserB, 200_000, recvMsg) s.Require().NoError(err) - ibcDenom := transfertypes.ParseDenomTrace( - fmt.Sprintf("%s/%s/%s", transfertypes.PortID, ibctesting.FirstClientID, s.cw20Base.Address), - ).IBCDenom() - - // Check the balance of UserB - resp, err := e2esuite.GRPCQuery[banktypes.QueryBalanceResponse](ctx, simd, &banktypes.QueryBalanceRequest{ - Address: s.UserB.FormattedAddress(), - Denom: ibcDenom, - }) - s.Require().NoError(err) - s.Require().NotNil(resp.Balance) - s.Require().Equal(int64(sendAmount), resp.Balance.Amount.Int64()) - s.Require().Equal(ibcDenom, resp.Balance.Denom) - - // Check the balance of UserA - cw20Resp, err := s.cw20Base.QueryClient().Balance(ctx, &cw20base.QueryMsg_Balance{Address: s.UserA.FormattedAddress()}) - s.Require().NoError(err) - s.Require().Equal(strconv.FormatInt(testvalues.StartingTokenAmount-sendAmount, 10), string(cw20Resp.Balance)) + s.Require().True(s.Run("Check balances", func() { + ibcDenom := transfertypes.ParseDenomTrace( + fmt.Sprintf("%s/%s/%s", transfertypes.PortID, ibctesting.FirstClientID, s.cw20Base.Address), + ).IBCDenom() + + // Check the balance of UserB + resp, err := e2esuite.GRPCQuery[banktypes.QueryBalanceResponse](ctx, simd, &banktypes.QueryBalanceRequest{ + Address: s.UserB.FormattedAddress(), + Denom: ibcDenom, + }) + s.Require().NoError(err) + s.Require().NotNil(resp.Balance) + s.Require().Equal(int64(sendAmount), resp.Balance.Amount.Int64()) + s.Require().Equal(ibcDenom, resp.Balance.Denom) + simdCoin = resp.Balance + + // Check the balance of UserA + cw20Resp, err := s.cw20Base.QueryClient().Balance(ctx, &cw20base.QueryMsg_Balance{Address: s.UserA.FormattedAddress()}) + s.Require().NoError(err) + s.Require().Equal(strconv.FormatInt(testvalues.StartingTokenAmount-sendAmount, 10), string(cw20Resp.Balance)) + })) ackHex, found := s.ExtractValueFromEvents(txResp.Events, channeltypes.EventTypeWriteAck, channeltypes.AttributeKeyAckHex) s.Require().True(found) @@ -415,6 +424,133 @@ func (s *IBCLiteTestSuite) TestCW20Transfer() { _, err := s.ics26Router.Execute(ctx, s.UserA.KeyName(), ackMsg, "--gas", "500000") s.Require().NoError(err) })) + + // Now we send the packet back + var packet2 channeltypes.Packet + s.Require().True(s.Run("SendPacket2", func() { + msgTransfer := transfertypes.MsgTransfer{ + SourcePort: transfertypes.PortID, + SourceChannel: ibctesting.FirstClientID, + Token: *simdCoin, + Sender: s.UserB.FormattedAddress(), + Receiver: s.UserA.FormattedAddress(), + DestPort: s.ics20Transfer.Port(), + DestChannel: testvalues.FirstWasmClientID, + TimeoutTimestamp: uint64(time.Now().Add(10 * time.Minute).UnixNano()), + } + + txResp, err := s.BroadcastMessages(ctx, simd, s.UserB, 200_000, &msgTransfer) + s.Require().NoError(err) + + packet2, err = s.ExtractPacketFromEvents(txResp.Events) + s.Require().NoError(err) + s.Require().Equal(s.ics20Transfer.Port(), packet2.DestinationPort) + s.Require().Equal(testvalues.FirstWasmClientID, packet2.DestinationChannel) + s.Require().Equal(transfertypes.PortID, packet2.SourcePort) + s.Require().Equal(ibctesting.FirstClientID, packet2.SourceChannel) + })) + + s.UpdateClientContract(ctx, s.ics07Tendermint, simd) + + s.Require().True(s.Run("Generate Packet2 Proof", func() { + var err error + key := host.PacketCommitmentPath(packet2.SourcePort, packet2.SourceChannel, packet2.Sequence) + merklePath = commitmenttypes.NewMerklePath([]byte(key)) + merklePath, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(ibcexported.StoreKey)), merklePath) + s.Require().NoError(err) + + value, proof, proofHeight, err = s.QueryProofs(ctx, simd, ibcexported.StoreKey, []byte(key), int64(s.trustedHeight.RevisionHeight)) + s.Require().NoError(err) + s.Require().NotEmpty(proof) + s.Require().NotEmpty(value) + s.Require().Equal(int64(s.trustedHeight.RevisionHeight), proofHeight) + expCommitment := channeltypes.CommitLitePacket(simd.Config().EncodingConfig.Codec, packet2) + s.Require().Equal(expCommitment, value) + })) + + var acknowledgement2 []byte + s.Require().True(s.Run("RecvPacket2", func() { + recvMsg := ics26router.ExecuteMsg{ + RecvPacket: &ics26router.ExecuteMsg_RecvPacket{ + Packet: ics26router.ToPacket(packet2), + ProofCommitment: ics26router.ToBinary(proof), + ProofHeight: ics26router.Height{ + RevisionHeight: int(s.trustedHeight.RevisionHeight), + RevisionNumber: int(s.trustedHeight.RevisionNumber), + }, + }, + } + + txResp, err := s.ics26Router.Execute(ctx, s.UserA.KeyName(), recvMsg, "--gas", "700000") + s.Require().NoError(err) + + s.Require().True(s.Run("Check balances", func() { + // Check the balance of UserB + resp, err := e2esuite.GRPCQuery[banktypes.QueryBalanceResponse](ctx, simd, &banktypes.QueryBalanceRequest{ + Address: s.UserB.FormattedAddress(), + Denom: simdCoin.Denom, + }) + s.Require().NoError(err) + s.Require().NotNil(resp.Balance) + s.Require().Equal(int64(0), resp.Balance.Amount.Int64()) + + // Check the balance of UserA + cw20Resp, err := s.cw20Base.QueryClient().Balance(ctx, &cw20base.QueryMsg_Balance{Address: s.UserA.FormattedAddress()}) + s.Require().NoError(err) + s.Require().Equal(strconv.FormatInt(testvalues.StartingTokenAmount, 10), string(cw20Resp.Balance)) + })) + + ackHex, found := s.ExtractValueFromEvents(txResp.Events, wasmtypes.CustomContractEventPrefix+channeltypes.EventTypeWriteAck, channeltypes.AttributeKeyAckHex) + s.Require().True(found) + + acknowledgement2, err = hex.DecodeString(ackHex) + s.Require().NoError(err) + s.Require().Equal([]byte(`{"result":"AQ=="}`), acknowledgement2) + })) + + s.Require().NoError(s.Relayer.UpdateClients(ctx, s.ExecRep, s.PathName)) + s.Require().NoError(testutil.WaitForBlocks(ctx, 3, simd)) + + s.Require().True(s.Run("Generate ack proof", func() { + resp, err := e2esuite.GRPCQuery[clienttypes.QueryClientStateResponse](ctx, simd, &clienttypes.QueryClientStateRequest{ + ClientId: ibctesting.FirstClientID, + }) + s.Require().NoError(err) + + err = proto.Unmarshal(resp.ClientState.Value, clientState) + s.Require().NoError(err) + + contractAddr, err := s.ics26Router.AccAddress() + s.Require().NoError(err) + + prefixStoreKey := wasmtypes.GetContractStorePrefix(contractAddr) + packetKey := host.PacketAcknowledgementKey(packet2.DestinationPort, packet2.DestinationChannel, packet2.Sequence) + key := cloneAppend(prefixStoreKey, packetKey) + merklePath = commitmenttypes.NewMerklePath(key) + merklePath, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(wasmtypes.StoreKey)), merklePath) + s.Require().NoError(err) + + commitmentBz := channeltypes.CommitAcknowledgement(acknowledgement2) + value, proof, proofHeight, err = s.QueryProofs(ctx, wasmd, wasmtypes.StoreKey, key, int64(clientState.LatestHeight.RevisionHeight)) + s.Require().NoError(err) + s.Require().NotEmpty(proof) + s.Require().NotEmpty(value) + s.Require().Equal(int64(clientState.LatestHeight.RevisionHeight), proofHeight) + s.Require().Equal(commitmentBz, value) + })) + + s.Require().True(s.Run("AckPacket2", func() { + ackMsg := channeltypes.MsgAcknowledgement{ + Packet: packet2, + Acknowledgement: acknowledgement2, + ProofAcked: proof, + ProofHeight: clientState.LatestHeight, + Signer: s.UserB.FormattedAddress(), + } + + _, err := s.BroadcastMessages(ctx, simd, s.UserB, 200_000, &ackMsg) + s.Require().NoError(err) + })) } // This is a test to verify that go clients can prove the state of cosmwasm contracts @@ -508,7 +644,7 @@ func cloneAppend(bz []byte, tail []byte) (res []byte) { return } -func (s *IBCLiteTestSuite) ExtractPacketFromWasmEvents(events []abci.Event) (channeltypes.Packet, error) { +func (s *IBCLiteTestSuite) ExtractPacketFromEvents(events []abci.Event) (channeltypes.Packet, error) { var ( err error sourceCh string @@ -520,7 +656,7 @@ func (s *IBCLiteTestSuite) ExtractPacketFromWasmEvents(events []abci.Event) (cha timeout uint64 ) for _, event := range events { - if !strings.HasPrefix(event.Type, wasmtypes.CustomContractEventPrefix) { + if !strings.HasPrefix(event.Type, wasmtypes.CustomContractEventPrefix) && event.Type != channeltypes.EventTypeSendPacket { continue } diff --git a/packages/shared/Cargo.toml b/packages/shared/Cargo.toml index 3350b57..d1f9301 100644 --- a/packages/shared/Cargo.toml +++ b/packages/shared/Cargo.toml @@ -20,3 +20,4 @@ sha2 = { workspace = true } ibc-proto = { workspace = true } derive_more = { workspace = true } cw-ibc-lite-derive = { workspace = true } +anybuf = { workspace = true } diff --git a/packages/shared/src/types/error.rs b/packages/shared/src/types/error.rs index d10455c..7fafc46 100644 --- a/packages/shared/src/types/error.rs +++ b/packages/shared/src/types/error.rs @@ -20,6 +20,8 @@ pub enum ContractError { IdentifierError(#[from] ibc_core_host::types::error::IdentifierError), #[error("{0}")] TransferError(#[from] super::transfer::error::TransferError), + #[error("{0}")] + BufanyError(#[from] anybuf::BufanyError), #[error("unauthorized")] Unauthorized, diff --git a/packages/shared/src/types/ibc.rs b/packages/shared/src/types/ibc.rs index 0b479fd..fae164f 100644 --- a/packages/shared/src/types/ibc.rs +++ b/packages/shared/src/types/ibc.rs @@ -139,3 +139,19 @@ impl From for ibc_proto::ibc::core::client::v1::Height { } } } + +#[cfg(test)] +mod tests { + use crate::types::transfer::packet::Ics20Ack; + + use super::*; + + #[test] + fn packet_acknowledgement() { + let ics20_ack = Ics20Ack::success(); + let bin = Binary::from(ics20_ack.to_vec()); + + let ack = Acknowledgement::try_from(bin).unwrap(); + assert_eq!(ack.as_slice(), br#"{"result":"AQ=="}"#); + } +} diff --git a/packages/shared/src/types/transfer/packet.rs b/packages/shared/src/types/transfer/packet.rs index 99d2949..d9416c5 100644 --- a/packages/shared/src/types/transfer/packet.rs +++ b/packages/shared/src/types/transfer/packet.rs @@ -104,3 +104,17 @@ impl Ics20Packet { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn ack_success() { + let ack = Ics20Ack::success(); + assert_eq!(ack, Ics20Ack::Result(vec![1].into())); + + let serialized = ack.to_vec(); + assert_eq!(serialized, br#"{"result":"AQ=="}"#); + } +}