From 2659d239976b42ec540d261665bec4fb56f89d09 Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Tue, 3 Sep 2024 16:47:56 +0200 Subject: [PATCH 1/3] added more tests for managed decimal var --- .../scenarios/managed_decimal.scen.json | 88 ++++++++++++++++- .../managed_decimal_logarithm.scen.json | 94 ++++++++++++++++++- .../src/managed_decimal_features.rs | 43 +++++++++ .../basic_features_managed_decimal_test.rs | 5 + .../basic-features/wasm/src/lib.rs | 9 +- framework/snippets/src/imports.rs | 5 +- 6 files changed, 236 insertions(+), 8 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json b/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json index b723c07b6d..e23747e4fb 100644 --- a/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json @@ -141,6 +141,92 @@ "gas": "*", "refund": "*" } + }, + { + "step": "scCall", + "id": "6", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_addition_var", + "arguments": [ + "0x000000010400000002", + "0x000000010500000002" + ], + "gasLimit": "1,000,000,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x000000010900000002" + ] + } + }, + { + "step": "scCall", + "id": "7", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_subtraction_var", + "arguments": [ + "0x000000010900000002", + "0x000000010400000002" + ], + "gasLimit": "1,000,000,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x000000010500000002" + ] + } + }, + { + "step": "scCall", + "id": "8", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_subtraction_var", + "arguments": [ + "0x000000010200000002", + "0x000000010800000002" + ], + "gasLimit": "1,000,000,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "4", + "message": "str:cannot subtract because result would be negative", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "9", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_eq_var", + "arguments": [ + "0x000000010d00000002", + "0x000000010d00000002" + ], + "gasLimit": "1,000,000,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x01" + ], + "status": "", + "message": "*", + "gas": "*", + "refund": "*" + } } ] -} +} \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json b/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json index 193517275c..6ee41eaa4d 100644 --- a/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/managed_decimal_logarithm.scen.json @@ -105,6 +105,98 @@ "gas": "*", "refund": "*" } + }, + { + "step": "scCall", + "id": "managed_decimal_log2_var(23)", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_log2_var", + "arguments": [ + "0x00000005055ae8260000000009" + ], + "gasLimit": "1,000,000,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "4,523648008" + ], + "status": "", + "message": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "managed_decimal_ln_var(23)", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_ln_var", + "arguments": [ + "0x00000005055ae8260000000009" + ], + "gasLimit": "25,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "+3,135553845" + ], + "status": "", + "message": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "managed_decimal_ln_var(378,298)", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_ln_var", + "arguments": [ + "0x00000005581451628000000009" + ], + "gasLimit": "1,000,000,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x0161cc16aa" + ], + "status": "", + "message": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "managed_decimal_log2_var(218,345)", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "function": "managed_decimal_log2_var", + "arguments": [ + "0x0000000532d6604c4000000009" + ], + "gasLimit": "1,000,000,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "7,770385327" + ], + "status": "", + "message": "*", + "gas": "*", + "refund": "*" + } } ] -} +} \ No newline at end of file diff --git a/contracts/feature-tests/basic-features/src/managed_decimal_features.rs b/contracts/feature-tests/basic-features/src/managed_decimal_features.rs index 556641cdc9..4bb3233c70 100644 --- a/contracts/feature-tests/basic-features/src/managed_decimal_features.rs +++ b/contracts/feature-tests/basic-features/src/managed_decimal_features.rs @@ -56,4 +56,47 @@ pub trait ManagedDecimalFeatures { ) -> ManagedDecimalSigned> { x.log2().unwrap_or_else(|| sc_panic!("cannot be zero")) } + + #[endpoint] + fn managed_decimal_addition_var( + &self, + first: ManagedDecimal, + second: ManagedDecimal, + ) -> ManagedDecimal { + first + second + } + + #[endpoint] + fn managed_decimal_subtraction_var( + &self, + first: ManagedDecimal, + second: ManagedDecimal, + ) -> ManagedDecimal { + first - second + } + + #[endpoint] + fn managed_decimal_eq_var( + &self, + first: ManagedDecimal, + second: ManagedDecimal, + ) -> bool { + first.eq(&second) + } + + #[endpoint] + fn managed_decimal_ln_var( + &self, + x: ManagedDecimal, + ) -> ManagedDecimalSigned> { + x.ln().unwrap_or_else(|| sc_panic!("cannot be zero")) + } + + #[endpoint] + fn managed_decimal_log2_var( + &self, + x: ManagedDecimal, + ) -> ManagedDecimalSigned> { + x.log2().unwrap_or_else(|| sc_panic!("cannot be zero")) + } } diff --git a/contracts/feature-tests/basic-features/tests/basic_features_managed_decimal_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_managed_decimal_test.rs index d4257fe078..238e4f0f4e 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_managed_decimal_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_managed_decimal_test.rs @@ -13,3 +13,8 @@ fn world() -> ScenarioWorld { fn managed_decimal_test() { world().run("scenarios/managed_decimal.scen.json"); } + +#[test] +fn managed_decimal_logarithm_test() { + world().run("scenarios/managed_decimal_logarithm.scen.json"); +} diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index 887b75bcd5..7b988da222 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 403 +// Endpoints: 408 // Async Callback: 1 -// Total number of exported functions: 405 +// Total number of exported functions: 410 #![no_std] @@ -421,6 +421,11 @@ multiversx_sc_wasm_adapter::endpoints! { managed_decimal_into_raw_units => managed_decimal_into_raw_units managed_decimal_ln => managed_decimal_ln managed_decimal_log2 => managed_decimal_log2 + managed_decimal_addition_var => managed_decimal_addition_var + managed_decimal_subtraction_var => managed_decimal_subtraction_var + managed_decimal_eq_var => managed_decimal_eq_var + managed_decimal_ln_var => managed_decimal_ln_var + managed_decimal_log2_var => managed_decimal_log2_var ) } diff --git a/framework/snippets/src/imports.rs b/framework/snippets/src/imports.rs index a35e880c78..a22c969887 100644 --- a/framework/snippets/src/imports.rs +++ b/framework/snippets/src/imports.rs @@ -4,10 +4,7 @@ pub use crate::{ dns_address_for_name, test_wallets, Interactor, InteractorPrepareAsync, StepBuffer, }; -pub use multiversx_sdk::{ - wallet::Wallet, - data::keystore::InsertPassword, -}; +pub use multiversx_sdk::{data::keystore::InsertPassword, wallet::Wallet}; pub use env_logger; pub use tokio; From d2d2d15fa5eacc8f9040ebbeb8e7e95d70804af7 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Wed, 4 Sep 2024 08:52:58 +0300 Subject: [PATCH 2/3] mandos refactor --- .../scenarios/managed_decimal.scen.json | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json b/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json index e23747e4fb..479b8931c3 100644 --- a/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/managed_decimal.scen.json @@ -150,15 +150,15 @@ "to": "sc:basic-features", "function": "managed_decimal_addition_var", "arguments": [ - "0x000000010400000002", - "0x000000010500000002" + "biguint:4|u32:2", + "biguint:5|u32:2" ], "gasLimit": "1,000,000,000,000", "gasPrice": "0" }, "expect": { "out": [ - "0x000000010900000002" + "biguint:9|u32:2" ] } }, @@ -170,15 +170,15 @@ "to": "sc:basic-features", "function": "managed_decimal_subtraction_var", "arguments": [ - "0x000000010900000002", - "0x000000010400000002" + "biguint:9|u32:2", + "biguint:4|u32:2" ], "gasLimit": "1,000,000,000,000", "gasPrice": "0" }, "expect": { "out": [ - "0x000000010500000002" + "biguint:5|u32:2" ] } }, @@ -190,8 +190,8 @@ "to": "sc:basic-features", "function": "managed_decimal_subtraction_var", "arguments": [ - "0x000000010200000002", - "0x000000010800000002" + "biguint:2|u32:2", + "biguint:8|u32:2" ], "gasLimit": "1,000,000,000,000", "gasPrice": "0" @@ -212,15 +212,15 @@ "to": "sc:basic-features", "function": "managed_decimal_eq_var", "arguments": [ - "0x000000010d00000002", - "0x000000010d00000002" + "biguint:11|u32:2", + "biguint:11|u32:2" ], "gasLimit": "1,000,000,000,000", "gasPrice": "0" }, "expect": { "out": [ - "0x01" + "true" ], "status": "", "message": "*", From 1aa35d69293d2109fd655260ab68f69601f5b43a Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Wed, 4 Sep 2024 09:39:56 +0300 Subject: [PATCH 3/3] dependency upgrade --- Cargo.lock | 32 ++++++++++++++++---------------- data/codec-derive/Cargo.toml | 2 +- framework/derive/Cargo.toml | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb45b11227..19a7d86bac 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -392,9 +392,9 @@ checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.1.14" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d2eb3cd3d1bf4529e31c215ee6f93ec5a3d536d9f578f93d9d33ee19562932" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" dependencies = [ "shlex", ] @@ -1559,9 +1559,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", @@ -2309,9 +2309,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.3" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -2930,18 +2930,18 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ "bitflags", "errno", @@ -2981,9 +2981,9 @@ checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" [[package]] name = "rustls-webpki" -version = "0.102.6" +version = "0.102.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" +checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" dependencies = [ "ring", "rustls-pki-types", @@ -3357,9 +3357,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.76" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -3481,9 +3481,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.39.3" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", diff --git a/data/codec-derive/Cargo.toml b/data/codec-derive/Cargo.toml index 707de3c33a..a738579380 100644 --- a/data/codec-derive/Cargo.toml +++ b/data/codec-derive/Cargo.toml @@ -23,5 +23,5 @@ default = ["syn/full", "syn/parsing", "syn/extra-traits"] [dependencies] proc-macro2 = "=1.0.86" quote = "=1.0.37" -syn = "=2.0.76" +syn = "=2.0.77" hex = "=0.4.3" diff --git a/framework/derive/Cargo.toml b/framework/derive/Cargo.toml index d4246c314b..111a7447c7 100644 --- a/framework/derive/Cargo.toml +++ b/framework/derive/Cargo.toml @@ -16,7 +16,7 @@ categories = ["cryptography::cryptocurrencies", "development-tools::procedural-m [dependencies] proc-macro2 = "=1.0.86" quote = "=1.0.37" -syn = "=2.0.76" +syn = "=2.0.77" hex = "=0.4.3" radix_trie = "=0.2.1"