diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dee6698e..0697b76c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,19 +37,13 @@ jobs: uses: actions/checkout@v3 with: submodules: true - # - name: Install stable toolchain - # uses: actions-rs/toolchain@v1 - # with: - # toolchain: 1.69.0 - # target: wasm32-unknown-unknown - # override: true - # profile: minimal + - name: Cache Rust dependencies uses: Swatinem/rust-cache@v2 - name: Compile WASM run: | - # rustup component add rustfmt --toolchain 1.69.0-x86_64-unknown-linux-gnu - # rustup component add clippy --toolchain 1.69.0-x86_64-unknown-linux-gnu + # rustup component add rustfmt --toolchain 1.78.0-x86_64-unknown-linux-gnu + # rustup component add clippy --toolchain 1.78.0-x86_64-unknown-linux-gnu bash ./scripts/optimize-cosmwasm.sh cd artifacts/archway && zip -r ../../cosmwasm-contracts.zip . -j diff --git a/Cargo.lock b/Cargo.lock index 6dc40bf8..ae3ea0de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,6 +43,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.11.0" @@ -55,6 +61,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64ct" version = "1.6.0" @@ -91,6 +103,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bnum" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" + [[package]] name = "borsh" version = "0.10.3" @@ -204,7 +222,7 @@ dependencies = [ "rustc-hex", "safe-regex", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "serde_json", "sha2 0.10.6", "sha3", @@ -234,22 +252,23 @@ dependencies = [ [[package]] name = "cosmwasm-crypto" -version = "1.2.6" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c0e41be7e6c7d7ab3c61cdc32fcfaa14f948491a401cbc1c74bb33b6f4b851" +checksum = "dd50718a2b6830ce9eb5d465de5a018a12e71729d66b70807ce97e6dd14f931d" dependencies = [ "digest 0.10.7", + "ecdsa 0.16.9", "ed25519-zebra", - "k256", + "k256 0.13.1", "rand_core 0.6.4", "thiserror", ] [[package]] name = "cosmwasm-derive" -version = "1.2.6" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a7ee2798c92c00dd17bebb4210f81d5f647e5e92d847959b7977e0fd29a3500" +checksum = "242e98e7a231c122e08f300d9db3262d1007b51758a8732cd6210b3e9faa4f3a" dependencies = [ "syn 1.0.109", ] @@ -280,11 +299,13 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.2.6" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5fdfd112b070055f068fad079d490117c8e905a588b92a5a7c9276d029930" +checksum = "78c1556156fdf892a55cced6115968b961eaaadd6f724a2c2cb7d1e168e32dd3" dependencies = [ - "base64 0.13.1", + "base64 0.21.7", + "bech32", + "bnum", "cosmwasm-crypto", "cosmwasm-derive", "derivative", @@ -292,10 +313,10 @@ dependencies = [ "hex", "schemars 0.8.12", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "sha2 0.10.6", + "static_assertions", "thiserror", - "uint", ] [[package]] @@ -335,6 +356,18 @@ dependencies = [ "zeroize", ] +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -386,7 +419,7 @@ dependencies = [ "hex", "schemars 0.8.12", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "thiserror", ] @@ -409,13 +442,13 @@ dependencies = [ "prost 0.11.9", "schemars 0.8.12", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "serde_json", ] [[package]] name = "cw-integration" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "common", @@ -427,7 +460,7 @@ dependencies = [ "cw-mock-ibc-core", "cw-multi-test 0.15.1", "cw-storage-plus 1.1.0", - "cw-xcall 0.2.0", + "cw-xcall 0.2.1", "cw-xcall-ibc-connection", "cw-xcall-lib 0.1.0", "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?tag=v0.1.0-alpha.5)", @@ -454,7 +487,7 @@ dependencies = [ "getrandom", "schemars 0.8.12", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "thiserror", ] @@ -474,7 +507,7 @@ dependencies = [ "getrandom", "schemars 0.8.12", "serde", - "serde-json-wasm 0.5.1", + "serde-json-wasm 0.5.2", "thiserror", ] @@ -489,7 +522,7 @@ dependencies = [ "cosmwasm-storage", "cw-common", "cw-storage-plus 1.1.0", - "cw-xcall 0.2.0 (git+https://github.com/icon-project/xCall.git?branch=main)", + "cw-xcall 0.2.0", "cw2 1.0.1", "hex", "schemars 0.8.12", @@ -528,7 +561,7 @@ dependencies = [ "cw-utils 1.0.1", "derivative", "itertools", - "k256", + "k256 0.11.6", "prost 0.9.0", "schemars 0.8.12", "serde", @@ -618,40 +651,40 @@ dependencies = [ [[package]] name = "cw-xcall" version = "0.2.0" +source = "git+https://github.com/icon-project/xCall.git?branch=main#1b64d8d3b932842bdc68d7fabc3842a7695860ed" dependencies = [ - "anyhow", "common", - "cosmwasm", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0", + "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?branch=main)", "cw2 1.0.1", "debug_print", - "getrandom", - "hex", "schemars 0.8.12", "serde", - "test-utils", "thiserror", ] [[package]] name = "cw-xcall" -version = "0.2.0" -source = "git+https://github.com/icon-project/xCall.git?branch=main#1b64d8d3b932842bdc68d7fabc3842a7695860ed" +version = "0.2.1" dependencies = [ + "anyhow", "common", + "cosmwasm", "cosmwasm-schema", "cosmwasm-std", "cosmwasm-storage", "cw-storage-plus 1.1.0", - "cw-xcall-lib 0.1.0 (git+https://github.com/icon-project/xCall.git?branch=main)", + "cw-xcall-lib 0.1.0", "cw2 1.0.1", "debug_print", + "getrandom", + "hex", "schemars 0.8.12", "serde", + "test-utils", "thiserror", ] @@ -771,6 +804,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "derivative" version = "2.2.0" @@ -809,6 +852,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", + "const-oid", "crypto-common", "subtle", ] @@ -842,10 +886,24 @@ version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" dependencies = [ - "der", - "elliptic-curve", - "rfc6979", - "signature", + "der 0.6.1", + "elliptic-curve 0.12.3", + "rfc6979 0.3.1", + "signature 1.6.4", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der 0.7.9", + "digest 0.10.7", + "elliptic-curve 0.13.8", + "rfc6979 0.4.0", + "signature 2.2.0", + "spki 0.7.3", ] [[package]] @@ -854,7 +912,7 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ - "signature", + "signature 1.6.4", ] [[package]] @@ -897,16 +955,35 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" dependencies = [ - "base16ct", - "crypto-bigint", - "der", + "base16ct 0.1.1", + "crypto-bigint 0.4.9", + "der 0.6.1", + "digest 0.10.7", + "ff 0.12.1", + "generic-array", + "group 0.12.1", + "pkcs8 0.9.0", + "rand_core 0.6.4", + "sec1 0.3.0", + "subtle", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct 0.2.0", + "crypto-bigint 0.5.5", "digest 0.10.7", - "ff", + "ff 0.13.0", "generic-array", - "group", - "pkcs8", + "group 0.13.0", + "pkcs8 0.10.2", "rand_core 0.6.4", - "sec1", + "sec1 0.7.3", "subtle", "zeroize", ] @@ -966,6 +1043,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "fixed-hash" version = "0.8.0" @@ -1065,6 +1152,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -1084,7 +1172,18 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" dependencies = [ - "ff", + "ff 0.12.1", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff 0.13.0", "rand_core 0.6.4", "subtle", ] @@ -1295,9 +1394,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" dependencies = [ "cfg-if", - "ecdsa", - "elliptic-curve", + "ecdsa 0.14.8", + "elliptic-curve 0.12.3", + "sha2 0.10.6", +] + +[[package]] +name = "k256" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +dependencies = [ + "cfg-if", + "ecdsa 0.16.9", + "elliptic-curve 0.13.8", + "once_cell", "sha2 0.10.6", + "signature 2.2.0", ] [[package]] @@ -1472,8 +1585,18 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" dependencies = [ - "der", - "spki", + "der 0.6.1", + "spki 0.6.0", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der 0.7.9", + "spki 0.7.3", ] [[package]] @@ -1684,11 +1807,21 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" dependencies = [ - "crypto-bigint", + "crypto-bigint 0.4.9", "hmac", "zeroize", ] +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + [[package]] name = "ripemd" version = "0.1.3" @@ -1865,10 +1998,24 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" dependencies = [ - "base16ct", - "der", + "base16ct 0.1.1", + "der 0.6.1", + "generic-array", + "pkcs8 0.9.0", + "subtle", + "zeroize", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct 0.2.0", + "der 0.7.9", "generic-array", - "pkcs8", + "pkcs8 0.10.2", "subtle", "zeroize", ] @@ -1899,9 +2046,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" dependencies = [ "serde", ] @@ -2014,6 +2161,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + [[package]] name = "snafu" version = "0.5.0" @@ -2042,7 +2199,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" dependencies = [ "base64ct", - "der", + "der 0.6.1", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der 0.7.9", ] [[package]] @@ -2158,7 +2325,7 @@ dependencies = [ "serde_json", "serde_repr", "sha2 0.10.6", - "signature", + "signature 1.6.4", "subtle", "subtle-encoding", "tendermint-proto", @@ -2513,9 +2680,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" dependencies = [ "zeroize_derive", ] diff --git a/Cargo.toml b/Cargo.toml index de108d13..4a6056b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,10 +7,10 @@ members = [ [workspace.package] authors = ["Icon Foundation"] repository = "https://github.com/icon-project/ibc-integration.git" -version="0.2.0" +version="0.2.1" [workspace.dependencies] -cosmwasm-std = {version="1.2.2",default-features = false,features = ["iterator", "staking"]} +cosmwasm-std = {version="1.5.5",default-features = false,features = ["iterator", "staking"]} cw-storage-plus = {git="https://github.com/icon-project/cw-storage-plus.git", branch="fix-raw"} cosmwasm-storage = "1.2.2" cosmwasm-schema = "1.2.2" diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs index 6bc36587..496a16dc 100644 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs +++ b/contracts/cosmwasm-vm/cw-centralized-connection/src/helper.rs @@ -58,7 +58,7 @@ impl<'a> CwCentralizedConnection<'a> { }; let call_message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: xcall_host.to_string(), - msg: to_binary(&xcall_msg).unwrap(), + msg: to_json_binary(&xcall_msg).unwrap(), funds: vec![], }); let sub_msg: SubMsg = SubMsg::reply_always(call_message, XCALL_HANDLE_MESSAGE_REPLY_ID); @@ -76,7 +76,7 @@ impl<'a> CwCentralizedConnection<'a> { }; let call_message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: xcall_host.to_string(), - msg: to_binary(&xcall_msg).unwrap(), + msg: to_json_binary(&xcall_msg).unwrap(), funds: vec![], }); let sub_msg: SubMsg = SubMsg::reply_always(call_message, XCALL_HANDLE_ERROR_REPLY_ID); diff --git a/contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs b/contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs index 8a356125..7122325a 100644 --- a/contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs +++ b/contracts/cosmwasm-vm/cw-centralized-connection/src/lib.rs @@ -7,11 +7,10 @@ pub mod types; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - entry_point, to_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Reply, + entry_point, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Reply, Response, StdError, StdResult, Storage, SubMsg, WasmMsg, }; -pub use contract::*; use cw2::set_contract_version; use cw_storage_plus::{Item, Map}; pub use errors::*; @@ -65,7 +64,7 @@ pub fn execute( pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { let centralized_connection = CwCentralizedConnection::default(); match msg { - QueryMsg::GetFee { nid, response } => to_binary( + QueryMsg::GetFee { nid, response } => to_json_binary( ¢ralized_connection .get_fee(deps.storage, nid, response) .unwrap(), @@ -74,10 +73,12 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { QueryMsg::GetReceipt { src_network, conn_sn, - } => to_binary(¢ralized_connection.get_receipt(deps.storage, src_network, conn_sn)), + } => { + to_json_binary(¢ralized_connection.get_receipt(deps.storage, src_network, conn_sn)) + } QueryMsg::Admin {} => { - to_binary(¢ralized_connection.admin().load(deps.storage).unwrap()) + to_json_binary(¢ralized_connection.admin().load(deps.storage).unwrap()) } } } diff --git a/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs b/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs index eb4101a4..cae79564 100644 --- a/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs +++ b/contracts/cosmwasm-vm/cw-integration/tests/test_xcall.rs @@ -360,7 +360,7 @@ fn test_rollback_reply() { } fn test_call_message( - mut ctx: &mut TestContext, + ctx: &mut TestContext, data: Vec, msg_type: MessageType, ) -> Result { diff --git a/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs index 5c02dbf2..e55dad62 100644 --- a/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/contract.rs @@ -64,7 +64,7 @@ impl<'a> CwMockService<'a> { }; let message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: address, - msg: to_binary(&msg).unwrap(), + msg: to_json_binary(&msg).unwrap(), funds: info.funds, }); let submessage = SubMsg { @@ -123,7 +123,7 @@ impl<'a> CwMockService<'a> { let msg = ExecuteMsg::SendCall { envelope, to }; let message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: address, - msg: to_binary(&msg).unwrap(), + msg: to_json_binary(&msg).unwrap(), funds: info.funds, }); @@ -154,7 +154,7 @@ impl<'a> CwMockService<'a> { let msg = ExecuteMsg::SendCall { to, envelope }; let message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: address, - msg: to_binary(&msg).unwrap(), + msg: to_json_binary(&msg).unwrap(), funds: info.funds, }); diff --git a/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/lib.rs b/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/lib.rs index bd7d5983..2258b5d7 100644 --- a/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/lib.rs +++ b/contracts/cosmwasm-vm/cw-mock-dapp-multi/src/lib.rs @@ -7,19 +7,16 @@ pub mod types; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - entry_point, to_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Response, - StdError, StdResult, Storage, WasmMsg, + entry_point, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, + Response, StdError, StdResult, Storage, WasmMsg, }; -pub use contract::*; use cw2::set_contract_version; use cw_storage_plus::{Item, Map}; pub use errors::*; -pub use helper::*; use msg::{ExecuteMsg, QueryMsg}; use state::{Connection, CwMockService}; use thiserror::Error; -use types::InstantiateMsg; pub use types::*; #[entry_point] @@ -85,6 +82,8 @@ pub fn execute( pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { let call_service = CwMockService::default(); match msg { - QueryMsg::GetSequence {} => to_binary(&call_service.get_sequence(deps.storage).unwrap()), + QueryMsg::GetSequence {} => { + to_json_binary(&call_service.get_sequence(deps.storage).unwrap()) + } } } diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs index 6be19f67..01aaa80a 100644 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-mock-dapp/src/contract.rs @@ -51,7 +51,7 @@ impl<'a> CwMockService<'a> { }; let message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: address, - msg: to_binary(&msg).unwrap(), + msg: to_json_binary(&msg).unwrap(), funds: info.funds, }); @@ -89,7 +89,7 @@ impl<'a> CwMockService<'a> { let msg = ExecuteMsg::SendCall { envelope, to }; let message: CosmosMsg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: address, - msg: to_binary(&msg).unwrap(), + msg: to_json_binary(&msg).unwrap(), funds: info.funds, }); diff --git a/contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs b/contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs index ede6cb50..6990cd6a 100644 --- a/contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs +++ b/contracts/cosmwasm-vm/cw-mock-dapp/src/lib.rs @@ -7,19 +7,16 @@ pub mod types; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - entry_point, to_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Response, - StdError, StdResult, Storage, SubMsg, WasmMsg, + entry_point, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, + Response, StdError, StdResult, Storage, SubMsg, WasmMsg, }; -pub use contract::*; use cw2::set_contract_version; use cw_storage_plus::{Item, Map}; pub use errors::*; -pub use helper::*; use msg::{ExecuteMsg, QueryMsg}; use state::CwMockService; use thiserror::Error; -use types::InstantiateMsg; pub use types::*; #[entry_point] @@ -71,12 +68,12 @@ pub fn execute( let fail = ExecuteMsg::FailureCall {}; let success_wasm = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: success_addr, - msg: to_binary(&success).map_err(ContractError::Std)?, + msg: to_json_binary(&success).map_err(ContractError::Std)?, funds: info.funds.clone(), }); let fail_wasm = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: fail_addr, - msg: to_binary(&fail).map_err(ContractError::Std)?, + msg: to_json_binary(&fail).map_err(ContractError::Std)?, funds: info.funds, }); let submessages = vec![ @@ -109,6 +106,8 @@ pub fn execute( pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { let call_service = CwMockService::default(); match msg { - QueryMsg::GetSequence {} => to_binary(&call_service.get_sequence(deps.storage).unwrap()), + QueryMsg::GetSequence {} => { + to_json_binary(&call_service.get_sequence(deps.storage).unwrap()) + } } } diff --git a/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs b/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs index 6ac91aad..e1e4c597 100644 --- a/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs +++ b/contracts/cosmwasm-vm/cw-xcall-lib/src/message/msg_type.rs @@ -43,15 +43,9 @@ mod tests { #[test] fn test_message_type_for_u8() { - assert_eq!(MessageType::from(MessageType::CallMessage), 0.into()); - assert_eq!( - MessageType::from(MessageType::CallMessagePersisted), - 2.into() - ); - assert_eq!( - MessageType::from(MessageType::CallMessageWithRollback), - 1.into() - ) + assert_eq!(MessageType::CallMessage, 0.into()); + assert_eq!(MessageType::CallMessagePersisted, 2.into()); + assert_eq!(MessageType::CallMessageWithRollback, 1.into()) } #[test] diff --git a/contracts/cosmwasm-vm/cw-xcall/src/assertion.rs b/contracts/cosmwasm-vm/cw-xcall/src/assertion.rs index bdeaadf2..9cf7e704 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/assertion.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/assertion.rs @@ -1,3 +1,5 @@ +use cosmwasm_std::to_json_binary; + use super::*; use crate::{ @@ -103,7 +105,7 @@ impl<'a> CwCallService<'a> { req_id: u128, message: &CSMessageRequest, ) -> Result<(), ContractError> { - let data = to_binary(message).unwrap(); + let data = to_json_binary(message).unwrap(); ensure!( !(data.is_empty()), ContractError::InvalidRequestId { id: req_id } @@ -130,7 +132,7 @@ impl<'a> CwCallService<'a> { sequence_no: u128, message: &Rollback, ) -> Result<(), ContractError> { - let data = to_binary(message).unwrap(); + let data = to_json_binary(message).unwrap(); ensure!( !(data.is_empty()), ContractError::InvalidSequenceId { id: sequence_no } diff --git a/contracts/cosmwasm-vm/cw-xcall/src/connection.rs b/contracts/cosmwasm-vm/cw-xcall/src/connection.rs index 6219bdf3..b2c1fca6 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/connection.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/connection.rs @@ -1,7 +1,7 @@ use crate::types::{message::CSMessage, LOG_PREFIX}; use common::rlp; use cosmwasm_std::{ - to_binary, Addr, Coin, CosmosMsg, Deps, DepsMut, QueryRequest, SubMsg, WasmMsg, + to_json_binary, Addr, Coin, CosmosMsg, Deps, DepsMut, QueryRequest, SubMsg, WasmMsg, }; use cosmwasm_std::{MessageInfo, Response}; use cw_xcall_lib::network_address::NetId; @@ -27,7 +27,7 @@ impl<'a> CwCallService<'a> { let cosm_msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: address.to_string(), - msg: to_binary(&message).map_err(ContractError::Std)?, + msg: to_json_binary(&message).map_err(ContractError::Std)?, funds: fee, }); let submessage = SubMsg { @@ -54,7 +54,7 @@ impl<'a> CwCallService<'a> { let query_request = QueryRequest::Wasm(cosmwasm_std::WasmQuery::Smart { contract_addr: address.to_string(), - msg: to_binary(&query_message).map_err(ContractError::Std)?, + msg: to_json_binary(&query_message).map_err(ContractError::Std)?, }); let fee: u128 = deps .querier diff --git a/contracts/cosmwasm-vm/cw-xcall/src/contract.rs b/contracts/cosmwasm-vm/cw-xcall/src/contract.rs index b5f6743e..3f08d520 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/contract.rs @@ -135,28 +135,30 @@ impl<'a> CwCallService<'a> { pub fn query(&self, deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { QueryMsg::GetAdmin {} => match self.query_admin(deps.storage) { - Ok(admin) => Ok(to_binary(&admin)?), + Ok(admin) => Ok(to_json_binary(&admin)?), Err(error) => Err(StdError::NotFound { kind: error.to_string(), }), }, - QueryMsg::GetProtocolFee {} => to_binary(&self.get_protocol_fee(deps.storage)), - QueryMsg::GetProtocolFeeHandler {} => to_binary(&self.get_protocol_feehandler(deps)), + QueryMsg::GetProtocolFee {} => to_json_binary(&self.get_protocol_fee(deps.storage)), + QueryMsg::GetProtocolFeeHandler {} => { + to_json_binary(&self.get_protocol_feehandler(deps)) + } QueryMsg::GetNetworkAddress {} => { - to_binary(&self.get_own_network_address(deps.storage, &env).unwrap()) + to_json_binary(&self.get_own_network_address(deps.storage, &env).unwrap()) } QueryMsg::VerifySuccess { sn } => { - to_binary(&self.get_successful_response(deps.storage, sn)) + to_json_binary(&self.get_successful_response(deps.storage, sn)) } QueryMsg::GetDefaultConnection { nid } => { - to_binary(&self.get_default_connection(deps.storage, nid).unwrap()) + to_json_binary(&self.get_default_connection(deps.storage, nid).unwrap()) } QueryMsg::GetFee { nid, rollback, sources, - } => to_binary( + } => to_json_binary( &self .get_fee(deps, nid, rollback, sources.unwrap_or(vec![])) .unwrap(), diff --git a/contracts/cosmwasm-vm/cw-xcall/src/dapp.rs b/contracts/cosmwasm-vm/cw-xcall/src/dapp.rs index 76455951..c09df03c 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/dapp.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/dapp.rs @@ -1,4 +1,6 @@ -use cosmwasm_std::{to_binary, Addr, Binary, CosmosMsg, MessageInfo, StdError, SubMsg, WasmMsg}; +use cosmwasm_std::{ + to_json_binary, Addr, Binary, CosmosMsg, MessageInfo, StdError, SubMsg, WasmMsg, +}; use cw_xcall_lib::{dapp_msg, dapp_multi_msg, network_address::NetworkAddress}; use crate::{error::ContractError, state::CwCallService}; @@ -38,7 +40,7 @@ impl<'a> CwCallService<'a> { ) -> Result { if protocols.is_empty() { let message = dapp_msg::ExecuteMsg::HandleCallMessage { from, data }; - let msg = to_binary(&message); + let msg = to_json_binary(&message); return msg; } let message = dapp_multi_msg::ExecuteMsg::HandleCallMessage { @@ -47,6 +49,6 @@ impl<'a> CwCallService<'a> { protocols, }; - to_binary(&message) + to_json_binary(&message) } } diff --git a/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs b/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs index e5ae04f9..0d8de537 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/handle_call_message.rs @@ -223,7 +223,7 @@ impl<'a> CwCallService<'a> { if protocols.contains(source) { return Ok(true); } - if protocols.len() == 0 { + if protocols.is_empty() { let default_conn = self.get_default_connection(store, src_net)?; Ok(source.clone() == default_conn) } else { diff --git a/contracts/cosmwasm-vm/cw-xcall/src/lib.rs b/contracts/cosmwasm-vm/cw-xcall/src/lib.rs index 7a7deb44..6501fe6a 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/lib.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/lib.rs @@ -35,7 +35,7 @@ use crate::{ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ - ensure, ensure_eq, entry_point, to_binary, Addr, Api, Binary, Deps, DepsMut, Env, Event, + ensure, ensure_eq, entry_point, to_json_binary, Addr, Api, Binary, Deps, DepsMut, Env, Event, MessageInfo, QuerierWrapper, Reply, Response, StdError, StdResult, Storage, SubMsg, }; diff --git a/contracts/cosmwasm-vm/cw-xcall/src/state.rs b/contracts/cosmwasm-vm/cw-xcall/src/state.rs index 4ce9efa0..757b7ce0 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/state.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/state.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{from_slice, to_vec, Order}; +use cosmwasm_std::{from_json, to_json_vec, Order}; use cw_storage_plus::{KeyDeserialize, PrimaryKey}; use cw_xcall_lib::network_address::NetId; use serde::de::DeserializeOwned; @@ -347,7 +347,7 @@ impl<'a> CwCallService<'a> { return Err(ContractError::CallAlreadyInProgress); } - let bytes = to_vec(data).map_err(ContractError::Std)?; + let bytes = to_json_vec(data).map_err(ContractError::Std)?; self.callback_data .save(store, id, &bytes) .map_err(ContractError::Std) @@ -370,7 +370,7 @@ impl<'a> CwCallService<'a> { .callback_data .load(store, id) .map_err(ContractError::Std)?; - let data = from_slice::(&bytes).map_err(ContractError::Std)?; + let data = from_json::(&bytes).map_err(ContractError::Std)?; Ok(data) } diff --git a/contracts/cosmwasm-vm/cw-xcall/src/types/mod.rs b/contracts/cosmwasm-vm/cw-xcall/src/types/mod.rs index f8fdb3d4..0e5197e3 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/types/mod.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/types/mod.rs @@ -11,6 +11,6 @@ use crate::error::ContractError; pub use common::rlp; use common::rlp::{Decodable, Encodable}; use cosmwasm_schema::cw_serde; -use cosmwasm_std::{to_binary, Binary}; +use cosmwasm_std::{to_json_binary, Binary}; use request::CSMessageRequest; use result::CSMessageResult; diff --git a/contracts/cosmwasm-vm/cw-xcall/src/types/result.rs b/contracts/cosmwasm-vm/cw-xcall/src/types/result.rs index cdb26b38..40c9ebd0 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/types/result.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/types/result.rs @@ -40,7 +40,7 @@ impl CSMessageResult { Self { sequence_no, response_code, - message: reply.unwrap_or(vec![]), + message: reply.unwrap_or_default(), } } @@ -88,7 +88,7 @@ impl Decodable for CSMessageResult { Ok(Self { sequence_no: rlp.val_at(0)?, response_code: CallServiceResponseType::try_from(code)?, - message: rlp.val_at(2).unwrap_or(vec![]), + message: rlp.val_at(2).unwrap_or_default(), }) } } diff --git a/contracts/cosmwasm-vm/cw-xcall/src/types/rollback.rs b/contracts/cosmwasm-vm/cw-xcall/src/types/rollback.rs index 4d16d73b..ecd994f4 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/types/rollback.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/types/rollback.rs @@ -51,7 +51,7 @@ impl Rollback { } pub fn is_null(&self) -> bool { - let r = to_binary(self).unwrap(); + let r = to_json_binary(self).unwrap(); r.is_empty() } pub fn set_enabled(&mut self) { diff --git a/contracts/cosmwasm-vm/cw-xcall/tests/setup.rs b/contracts/cosmwasm-vm/cw-xcall/tests/setup.rs index d9aef3c9..3d19443e 100644 --- a/contracts/cosmwasm-vm/cw-xcall/tests/setup.rs +++ b/contracts/cosmwasm-vm/cw-xcall/tests/setup.rs @@ -8,8 +8,8 @@ use cosmwasm_std::{ mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR, }, - to_binary, Addr, BlockInfo, ContractInfo, ContractResult, Empty, Env, MessageInfo, OwnedDeps, - Storage, SystemResult, Timestamp, TransactionInfo, WasmQuery, + to_json_binary, Addr, BlockInfo, ContractInfo, ContractResult, Empty, Env, MessageInfo, + OwnedDeps, Storage, SystemResult, Timestamp, TransactionInfo, WasmQuery, }; use cw_xcall::{ state::CwCallService, @@ -46,7 +46,7 @@ pub fn get_dummy_req_msg() -> CSMessageRequest { Addr::unchecked("dapp"), 1, MessageType::CallMessage, - keccak256(&vec![1, 2, 3]).to_vec(), + keccak256(&[1, 2, 3]).to_vec(), vec![], ) } @@ -98,7 +98,7 @@ pub fn mock_connection_fee_query(deps: &mut OwnedDeps SystemResult::Ok(ContractResult::Ok(to_binary(&10_u128).unwrap())), + } => SystemResult::Ok(ContractResult::Ok(to_json_binary(&10_u128).unwrap())), _ => todo!(), }); } @@ -216,23 +216,23 @@ impl TestContext { } pub fn init_context(&self, storage: &mut dyn Storage, contract: &CwCallService) { - self.store_config(storage, &contract); - self.set_admin(storage, &contract); - self.init_last_request_id(storage, &contract); - self.init_last_sequence_no(storage, &contract); - self.store_default_connection(storage, &contract); - self.store_protocol_fee_handler(storage, &contract) + self.store_config(storage, contract); + self.set_admin(storage, contract); + self.init_last_request_id(storage, contract); + self.init_last_sequence_no(storage, contract); + self.store_default_connection(storage, contract); + self.store_protocol_fee_handler(storage, contract) } pub fn init_execute_call(&self, storage: &mut dyn Storage, contract: &CwCallService) { - self.init_context(storage, &contract); - self.store_proxy_request(storage, &contract); + self.init_context(storage, contract); + self.store_proxy_request(storage, contract); } pub fn init_reply_state(&self, storage: &mut dyn Storage, contract: &CwCallService) { - self.init_context(storage, &contract); - self.store_proxy_request(storage, &contract); - self.store_execute_request_id(storage, &contract); + self.init_context(storage, contract); + self.store_proxy_request(storage, contract); + self.store_execute_request_id(storage, contract); } pub fn set_admin(&self, storage: &mut dyn Storage, contract: &CwCallService) { diff --git a/contracts/cosmwasm-vm/cw-xcall/tests/test_call_message.rs b/contracts/cosmwasm-vm/cw-xcall/tests/test_call_message.rs index af41ec05..df080a19 100644 --- a/contracts/cosmwasm-vm/cw-xcall/tests/test_call_message.rs +++ b/contracts/cosmwasm-vm/cw-xcall/tests/test_call_message.rs @@ -7,7 +7,7 @@ use std::{collections::HashMap, str::FromStr, vec}; use cosmwasm_std::{ testing::{mock_env, MOCK_CONTRACT_ADDR}, - to_binary, Addr, Binary, ContractInfoResponse, ContractResult, SystemError, SystemResult, + to_json_binary, Addr, Binary, ContractInfoResponse, ContractResult, SystemError, SystemResult, WasmQuery, }; use cw_xcall::{ @@ -94,7 +94,7 @@ fn send_packet_failure_due_data_len() { WasmQuery::ContractInfo { contract_addr } => { if *contract_addr == constract1 { let response = ContractInfoResponse::new(0, "test"); - SystemResult::Ok(ContractResult::Ok(to_binary(&response).unwrap())) + SystemResult::Ok(ContractResult::Ok(to_json_binary(&response).unwrap())) } else { SystemResult::Err(SystemError::NoSuchContract { addr: contract_addr.clone(), @@ -105,7 +105,7 @@ fn send_packet_failure_due_data_len() { WasmQuery::Smart { contract_addr: _, msg: _, - } => SystemResult::Ok(ContractResult::Ok(to_binary(&0_u128).unwrap())), + } => SystemResult::Ok(ContractResult::Ok(to_json_binary(&0_u128).unwrap())), _ => todo!(), } }); @@ -161,7 +161,7 @@ fn send_packet_failure_due_rollback_len() { WasmQuery::ContractInfo { contract_addr } => { if *contract_addr == constract1 { let response = ContractInfoResponse::new(0, "test"); - SystemResult::Ok(ContractResult::Ok(to_binary(&response).unwrap())) + SystemResult::Ok(ContractResult::Ok(to_json_binary(&response).unwrap())) } else { SystemResult::Err(SystemError::NoSuchContract { addr: contract_addr.clone(), @@ -171,7 +171,7 @@ fn send_packet_failure_due_rollback_len() { WasmQuery::Smart { contract_addr: _, msg: _, - } => SystemResult::Ok(ContractResult::Ok(to_binary(&0_u128).unwrap())), + } => SystemResult::Ok(ContractResult::Ok(to_json_binary(&0_u128).unwrap())), _ => todo!(), } }); @@ -237,7 +237,7 @@ fn send_packet_success_needresponse() { WasmQuery::ContractInfo { contract_addr } => { if *contract_addr == constract1 { let response = ContractInfoResponse::default(); - SystemResult::Ok(ContractResult::Ok(to_binary(&response).unwrap())) + SystemResult::Ok(ContractResult::Ok(to_json_binary(&response).unwrap())) } else { SystemResult::Err(SystemError::NoSuchContract { addr: contract_addr.clone(), @@ -247,7 +247,7 @@ fn send_packet_success_needresponse() { WasmQuery::Smart { contract_addr: _, msg: _, - } => SystemResult::Ok(ContractResult::Ok(to_binary(&10_u128).unwrap())), + } => SystemResult::Ok(ContractResult::Ok(to_json_binary(&10_u128).unwrap())), _ => todo!(), } }); @@ -312,7 +312,7 @@ fn send_packet_fail_insufficient_funds() { WasmQuery::ContractInfo { contract_addr } => { if *contract_addr == constract1 { let response = ContractInfoResponse::new(0, "test"); - SystemResult::Ok(ContractResult::Ok(to_binary(&response).unwrap())) + SystemResult::Ok(ContractResult::Ok(to_json_binary(&response).unwrap())) } else { SystemResult::Err(SystemError::NoSuchContract { addr: contract_addr.clone(), @@ -322,7 +322,7 @@ fn send_packet_fail_insufficient_funds() { WasmQuery::Smart { contract_addr: _, msg: _, - } => SystemResult::Ok(ContractResult::Ok(to_binary(&10_u128).unwrap())), + } => SystemResult::Ok(ContractResult::Ok(to_json_binary(&10_u128).unwrap())), _ => todo!(), } }); @@ -388,7 +388,7 @@ fn test_is_reply_returns_false_on_mismatch_network_id() { ctx.init_reply_state(deps.as_mut().storage, &contract); let res = contract.is_reply(deps.as_ref(), ctx.nid, &vec![]); - assert_eq!(res, false) + assert!(!res) } #[test] @@ -399,7 +399,7 @@ fn test_is_reply_returns_false_on_proxy_request_not_found() { let ctx = TestContext::default(); let res = contract.is_reply(deps.as_ref(), ctx.nid, &vec![]); - assert_eq!(res, false) + assert!(!res) } #[test] @@ -415,7 +415,7 @@ fn test_is_reply_returns_false_on_mismatch_array_len() { NetId::from_str("archway").unwrap(), &vec!["src_1".to_string()], ); - assert_eq!(res, false) + assert!(!res) } #[test] @@ -443,5 +443,5 @@ fn test_is_reply_returns_false_on_mismatch_protocols() { NetId::from_str("archway").unwrap(), &vec!["src_1".to_string()], ); - assert_eq!(res, false) + assert!(!res) } diff --git a/contracts/cosmwasm-vm/cw-xcall/tests/test_call_service.rs b/contracts/cosmwasm-vm/cw-xcall/tests/test_call_service.rs index b8eddb27..9ce51d5c 100644 --- a/contracts/cosmwasm-vm/cw-xcall/tests/test_call_service.rs +++ b/contracts/cosmwasm-vm/cw-xcall/tests/test_call_service.rs @@ -9,7 +9,7 @@ use std::str::FromStr; use cosmwasm_std::{ testing::{mock_env, MOCK_CONTRACT_ADDR}, - to_binary, Addr, Event, Reply, SubMsgResponse, SubMsgResult, + to_json_binary, Addr, Event, Reply, SubMsgResponse, SubMsgResult, }; use cw_xcall::{ execute, instantiate, migrate, @@ -96,7 +96,7 @@ fn test_reply_fail_for_unknown_reply_id() { id: 5, result: SubMsgResult::Ok(SubMsgResponse { events: vec![Event::new("empty")], - data: Some(to_binary(&vec![1]).unwrap()), + data: Some(to_json_binary(&vec![1]).unwrap()), }), }; reply(deps.as_mut(), ctx.env, msg).unwrap(); @@ -284,7 +284,7 @@ fn test_query_get_admin() { let msg = QueryMsg::GetAdmin {}; let res = query(deps.as_ref(), ctx.env, msg).unwrap(); - assert_eq!(res, to_binary("admin").unwrap()) + assert_eq!(res, to_json_binary("admin").unwrap()) } #[test] @@ -300,7 +300,7 @@ fn test_query_get_network_address() { let expected_network_address = NetworkAddress::new("icon", ctx.env.contract.address.clone().as_str()); - assert_eq!(res, to_binary(&expected_network_address).unwrap()) + assert_eq!(res, to_json_binary(&expected_network_address).unwrap()) } #[test] @@ -330,7 +330,10 @@ fn test_query_get_default_connection() { nid: NetId::from_str("archway").unwrap(), }; let res = query(deps.as_ref(), ctx.env, msg).unwrap(); - assert_eq!(res, to_binary(&Addr::unchecked("centralized")).unwrap()); + assert_eq!( + res, + to_json_binary(&Addr::unchecked("centralized")).unwrap() + ); } #[test] @@ -358,7 +361,7 @@ fn test_execute_call_reply() { Addr::unchecked("xcall"), u128::default(), MessageType::CallMessageWithRollback, - keccak256(&vec![1, 2, 3]).to_vec(), + keccak256(&[1, 2, 3]).to_vec(), vec![], ); contract @@ -375,7 +378,7 @@ fn test_execute_call_reply() { id: 1, result: SubMsgResult::Ok(SubMsgResponse { events: vec![Event::new("empty")], - data: Some(to_binary(&vec![1]).unwrap()), + data: Some(to_json_binary(&vec![1]).unwrap()), }), }; diff --git a/contracts/cosmwasm-vm/cw-xcall/tests/test_fee_handler.rs b/contracts/cosmwasm-vm/cw-xcall/tests/test_fee_handler.rs index a4518ad1..21a2bfe8 100644 --- a/contracts/cosmwasm-vm/cw-xcall/tests/test_fee_handler.rs +++ b/contracts/cosmwasm-vm/cw-xcall/tests/test_fee_handler.rs @@ -1,9 +1,9 @@ use std::str::FromStr; use cosmwasm_std::{ - from_binary, + from_json, testing::{mock_dependencies, mock_env, mock_info}, - to_binary, Addr, Coin, ContractResult, SystemResult, WasmQuery, + to_json_binary, Addr, Coin, ContractResult, SystemResult, WasmQuery, }; use cw_xcall::{msg::QueryMsg, state::CwCallService}; pub mod account; @@ -91,7 +91,7 @@ fn get_protocol_fee_handler() { let result = contract .query(deps.as_ref(), env, QueryMsg::GetProtocolFeeHandler {}) .unwrap(); - let result: String = from_binary(&result).unwrap(); + let result: String = from_json(result).unwrap(); assert_eq!("xyz".to_string(), result); } @@ -146,7 +146,7 @@ fn get_protocol_fee() { let result = contract .query(deps.as_ref(), env, QueryMsg::GetProtocolFee {}) .unwrap(); - let result: u128 = from_binary(&result).unwrap(); + let result: u128 = from_json(result).unwrap(); assert_eq!("123", result.to_string()); } @@ -179,7 +179,7 @@ fn get_fee() { WasmQuery::Smart { contract_addr: _, msg: _, - } => SystemResult::Ok(ContractResult::Ok(to_binary(&100_u128).unwrap())), + } => SystemResult::Ok(ContractResult::Ok(to_json_binary(&100_u128).unwrap())), _ => todo!(), }); let result = contract @@ -202,6 +202,6 @@ fn get_fee() { }, ) .unwrap(); - let result: u128 = from_binary(&result).unwrap(); + let result: u128 = from_json(result).unwrap(); assert_eq!("223", result.to_string()); } diff --git a/contracts/cosmwasm-vm/cw-xcall/tests/test_handle_call_message.rs b/contracts/cosmwasm-vm/cw-xcall/tests/test_handle_call_message.rs index 3ae84995..e30abc42 100644 --- a/contracts/cosmwasm-vm/cw-xcall/tests/test_handle_call_message.rs +++ b/contracts/cosmwasm-vm/cw-xcall/tests/test_handle_call_message.rs @@ -9,9 +9,9 @@ use setup::*; use std::str::FromStr; use cosmwasm_std::{ - from_binary, + from_json, testing::{mock_dependencies, mock_env, mock_info}, - to_binary, Addr, Coin, CosmosMsg, Reply, SubMsgResponse, SubMsgResult, WasmMsg, + to_json_binary, Addr, Coin, CosmosMsg, Reply, SubMsgResponse, SubMsgResult, WasmMsg, }; use cw_xcall::{ state::{CwCallService, EXECUTE_CALL_ID}, @@ -279,7 +279,7 @@ fn execute_rollback_failure() { msg, funds: _, }) => { - let r: Vec = from_binary(&msg).unwrap(); + let r: Vec = from_json(msg).unwrap(); assert_eq!(vec![1, 2, 3], r) } @@ -332,7 +332,7 @@ fn test_persisted_message_removed_on_success() { id: EXECUTE_CALL_ID, result: SubMsgResult::Ok(SubMsgResponse { events: vec![], - data: to_binary(&1).ok(), + data: to_json_binary(&1).ok(), }), }; @@ -392,7 +392,7 @@ fn test_handle_reply_fail() { Addr::unchecked("dapp"), 1, MessageType::CallMessage, - keccak256(&vec![1, 2, 3]).to_vec(), + keccak256(&[1, 2, 3]).to_vec(), vec![], ); let rollback = get_dummy_rollback_data(); @@ -447,13 +447,13 @@ fn test_handle_request_from_multiple_protocols() { Addr::unchecked("dapp"), 1, MessageType::CallMessage, - keccak256(&vec![1, 2, 3]).to_vec(), + keccak256(&[1, 2, 3]).to_vec(), vec!["centralized".to_string(), "ibc".to_string()], ); let nid = NetId::from_str("archway").unwrap(); for protocol in request.protocols() { - let info = create_mock_info(&protocol, "icx", 100); + let info = create_mock_info(protocol, "icx", 100); let res = contract .handle_request(deps.as_mut(), info, nid.clone(), &request.as_bytes()) .unwrap(); @@ -525,7 +525,7 @@ fn test_handle_result_from_multiple_protocols() { let msg = get_dummy_result_message().as_bytes(); for protocol in rollback.protocols() { - let info = create_mock_info(&protocol, "arch", 100); + let info = create_mock_info(protocol, "arch", 100); let res = contract.handle_result(deps.as_mut(), info, &msg).unwrap(); if protocol == "centralized" { assert_eq!(res.attributes.len(), 0); diff --git a/contracts/javascore/xcall/src/main/java/foundation/icon/xcall/CallServiceImpl.java b/contracts/javascore/xcall/src/main/java/foundation/icon/xcall/CallServiceImpl.java index 7038e645..99854d3a 100644 --- a/contracts/javascore/xcall/src/main/java/foundation/icon/xcall/CallServiceImpl.java +++ b/contracts/javascore/xcall/src/main/java/foundation/icon/xcall/CallServiceImpl.java @@ -270,10 +270,9 @@ public void setDefaultConnection(String _nid, Address _connection) { defaultConnection.set(_nid, _connection); } - @External - public void getDefaultConnection(String _nid, Address _connection) { - checkCallerOrThrow(admin(), "OnlyAdmin"); - defaultConnection.set(_nid, _connection); + @External(readonly = true) + public Address getDefaultConnection(String _nid) { + return defaultConnection.get(_nid); } @External(readonly = true) diff --git a/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java b/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java index a2852b6e..55f0c733 100644 --- a/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java +++ b/contracts/javascore/xcall/src/test/java/foundation/icon/xcall/CallServiceTest.java @@ -26,6 +26,7 @@ import com.iconloop.score.test.ServiceManager; import com.iconloop.score.test.TestBase; +import score.Address; import foundation.icon.xcall.messages.CallMessageWithRollback; import foundation.icon.xcall.messages.Message; import foundation.icon.xcall.messages.PersistentMessage; @@ -810,6 +811,17 @@ public void getFee_default() throws Exception { assertEquals(fee1.add(protocolFee), fee); } + @Test + public void setGetDefaultCOnnection() throws Exception { + // Arrange + String nid = "nid"; + + xcall.invoke(owner, "setDefaultConnection", nid, baseConnection.getAddress()); + Address connection = xcall.call(Address.class, "getDefaultConnection", nid); + // Assert + assertEquals(connection, baseConnection.getAddress()); + } + @Test public void getFee_defaultProtocol_notSet() throws Exception { // Arrange @@ -818,6 +830,8 @@ public void getFee_defaultProtocol_notSet() throws Exception { // Act & Assert UserRevertedException e = assertThrows(UserRevertedException.class, ()-> xcall.call(BigInteger.class, "getFee", nid, true)); assertEquals("Reverted(0): NoDefaultConnection", e.getMessage()); + + } @Test diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d9f00d75..3d35e3fa 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.69.0" +channel = "1.78.0" components = ["rustfmt", "clippy"] targets = ["wasm32-unknown-unknown"] profile = "minimal" diff --git a/scripts/optimize-cosmwasm.sh b/scripts/optimize-cosmwasm.sh index 434b672f..769704fa 100755 --- a/scripts/optimize-cosmwasm.sh +++ b/scripts/optimize-cosmwasm.sh @@ -1,11 +1,11 @@ #!/bin/bash set -e -BINARYEN_VERS=110 +BINARYEN_VERS=116 BINARYEN_DWN="https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERS}/binaryen-version_${BINARYEN_VERS}-x86_64-linux.tar.gz" -WASMOPT_VERS="110" -RUSTC_VERS="1.69.0" +WASMOPT_VERS="116" +RUSTC_VERS="1.78.0" MAX_WASM_SIZE=800 # 800 KB @@ -33,7 +33,7 @@ cargo fmt --all cargo clean rustup target add wasm32-unknown-unknown -cargo install cosmwasm-check@1.4.1 --locked +cargo install cosmwasm-check@2.1.1 --locked RUSTFLAGS='-C link-arg=-s' cargo build --workspace --exclude test-utils --release --lib --target wasm32-unknown-unknown @@ -42,7 +42,7 @@ for WASM in ./target/wasm32-unknown-unknown/release/*.wasm; do echo "Creating intermediate hash for $NAME ..." sha256sum -- "$WASM" | tee -a artifacts/archway/checksums_intermediate.txt echo "Optimizing $NAME ..." - wasm-opt -Oz "$WASM" -o "artifacts/archway/$NAME" + wasm-opt -Os --signext-lowering "$WASM" -o "artifacts/archway/$NAME" done # check all generated wasm files