From 3538039e82643d7cb8fe68adb16acc217970bb56 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 8 Jul 2024 18:53:38 +0800 Subject: [PATCH] works --- Cargo.lock | 64 +++++++++++-------- Cargo.toml | 1 + contracts/ics26-router/Cargo.toml | 1 + contracts/ics26-router/src/contract.rs | 11 ++-- .../chainconfig/chain_config.go | 2 +- e2e/interchaintestv8/ibclite_test.go | 1 + packages/shared/Cargo.toml | 1 + packages/shared/src/types/error.rs | 2 + packages/shared/src/types/ibc.rs | 16 +++++ packages/shared/src/types/transfer/packet.rs | 14 ++++ 10 files changed, 78 insertions(+), 35 deletions(-) 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/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 0d8f5c2..dab79b3 100644 --- a/e2e/interchaintestv8/ibclite_test.go +++ b/e2e/interchaintestv8/ibclite_test.go @@ -505,6 +505,7 @@ func (s *IBCLiteTestSuite) TestCW20Transfer() { 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)) 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=="}"#); + } +}