From a07db3584864f31f7312425fa2bb105f74ae751b Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Tue, 10 Oct 2023 01:54:33 +0300 Subject: [PATCH 1/8] overflow + enable poe test on biguint --- .../scenarios/big_uint_overflow.scen.json | 48 +++++++++++++++++++ ...g_uint_pow.json => big_uint_pow.scen.json} | 0 .../tests/basic_features_scenario_go_test.rs | 10 ++++ .../tests/basic_features_scenario_rs_test.rs | 10 ++++ 4 files changed, 68 insertions(+) create mode 100644 contracts/feature-tests/basic-features/scenarios/big_uint_overflow.scen.json rename contracts/feature-tests/basic-features/scenarios/{big_uint_pow.json => big_uint_pow.scen.json} (100%) diff --git a/contracts/feature-tests/basic-features/scenarios/big_uint_overflow.scen.json b/contracts/feature-tests/basic-features/scenarios/big_uint_overflow.scen.json new file mode 100644 index 0000000000..c7cfe8dd09 --- /dev/null +++ b/contracts/feature-tests/basic-features/scenarios/big_uint_overflow.scen.json @@ -0,0 +1,48 @@ +{ + "name": "overflow", + "gasSchedule": "v3", + "steps": [ + { + "step": "setState", + "accounts": { + "sc:basic-features": { + "nonce": "0", + "balance": "0", + "storage": {}, + "code": "file:../output/basic-features.wasm" + }, + "address:an_account": { + "nonce": "0", + "balance": "0", + "storage": {}, + "code": "" + } + } + }, + { + "step": "scCall", + "id": "pow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "pow_big_uint", + "arguments": [ + "10", + "80" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "100000000000000000000000000000000000000000000000000000000000000000000000000000000" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + } + ] +} diff --git a/contracts/feature-tests/basic-features/scenarios/big_uint_pow.json b/contracts/feature-tests/basic-features/scenarios/big_uint_pow.scen.json similarity index 100% rename from contracts/feature-tests/basic-features/scenarios/big_uint_pow.json rename to contracts/feature-tests/basic-features/scenarios/big_uint_pow.scen.json diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs index 95d0566f8b..55c4063c80 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs @@ -34,6 +34,16 @@ fn big_uint_sqrt_go() { world().run("scenarios/big_uint_sqrt.scen.json"); } +#[test] +fn big_uint_pow_go() { + world().run("scenarios/big_uint_pow.scen.json"); +} + +#[test] +fn big_uint_overflow_go() { + world().run("scenarios/big_uint_overflow.scen.json"); +} + #[test] fn big_uint_to_u_64_go() { world().run("scenarios/big_uint_to_u64.scen.json"); diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs index de5da320e3..08283808b4 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs @@ -43,9 +43,19 @@ fn big_uint_from_u_64_rs() { #[test] fn big_uint_sqrt_rs() { + world().run("scenarios/big_uint_pow.scen.json"); +} + +#[test] +fn big_uint_pow_rs() { world().run("scenarios/big_uint_sqrt.scen.json"); } +#[test] +fn big_uint_overflow_rs() { + world().run("scenarios/big_uint_overflow.scen.json"); +} + #[test] fn big_uint_to_u_64_rs() { world().run("scenarios/big_uint_to_u64.scen.json"); From 00a59cedf5c43cc8f539094303d6a4af8b22f401 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Tue, 31 Oct 2023 07:16:57 +0200 Subject: [PATCH 2/8] more derives for EsdtTokenType --- ...scen.json => small_int_overflow.scen.json} | 0 .../basic-features/src/basic_features_main.rs | 1 + .../src/small_num_overflow_test_ops.rs | 31 +++++++++++++++++++ 3 files changed, 32 insertions(+) rename contracts/feature-tests/basic-features/scenarios/{big_uint_overflow.scen.json => small_int_overflow.scen.json} (100%) create mode 100644 contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs diff --git a/contracts/feature-tests/basic-features/scenarios/big_uint_overflow.scen.json b/contracts/feature-tests/basic-features/scenarios/small_int_overflow.scen.json similarity index 100% rename from contracts/feature-tests/basic-features/scenarios/big_uint_overflow.scen.json rename to contracts/feature-tests/basic-features/scenarios/small_int_overflow.scen.json diff --git a/contracts/feature-tests/basic-features/src/basic_features_main.rs b/contracts/feature-tests/basic-features/src/basic_features_main.rs index 56b1eb8bff..4111b7a5e7 100644 --- a/contracts/feature-tests/basic-features/src/basic_features_main.rs +++ b/contracts/feature-tests/basic-features/src/basic_features_main.rs @@ -18,6 +18,7 @@ pub mod managed_address_features; pub mod managed_buffer_features; pub mod managed_vec_features; pub mod non_zero_features; +pub mod small_num_overflow_test_ops; pub mod storage_direct_load; pub mod storage_direct_store; pub mod storage_mapper_fungible_token; diff --git a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs new file mode 100644 index 0000000000..466e55bfbd --- /dev/null +++ b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs @@ -0,0 +1,31 @@ +multiversx_sc::imports!(); + +/// Checks that BigUint/BigInt operators work as expected. +#[multiversx_sc::module] +#[allow(clippy::redundant_clone)] +pub trait SmallIntOperators { + #[endpoint] + fn add_usize(&self, a: usize, b: usize) -> usize { + a + b + } + + #[endpoint] + fn add_u8(&self, a: u8, b: u8) -> u8 { + a + b + } + + #[endpoint] + fn add_u16(&self, a: u16, b: u16) -> u16 { + a + b + } + + #[endpoint] + fn add_u32(&self, a: u32, b: u32) -> u32 { + a + b + } + + #[endpoint] + fn add_u64(&self, a: u64, b: u64) -> u64 { + a + b + } +} From 21b14d18c810f38882a7caf8586a21a2fbb8e116 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Wed, 15 Nov 2023 15:31:28 +0200 Subject: [PATCH 3/8] small int overflow --- .../scenarios/small_int_overflow.scen.json | 48 --- .../scenarios/small_num_overflow.scen.json | 359 ++++++++++++++++++ .../basic-features/src/basic_features_main.rs | 1 + .../src/small_num_overflow_test_ops.rs | 108 +++++- .../tests/basic_features_scenario_rs_test.rs | 5 + .../basic-features/wasm/src/lib.rs | 24 +- 6 files changed, 483 insertions(+), 62 deletions(-) delete mode 100644 contracts/feature-tests/basic-features/scenarios/small_int_overflow.scen.json create mode 100644 contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json diff --git a/contracts/feature-tests/basic-features/scenarios/small_int_overflow.scen.json b/contracts/feature-tests/basic-features/scenarios/small_int_overflow.scen.json deleted file mode 100644 index c7cfe8dd09..0000000000 --- a/contracts/feature-tests/basic-features/scenarios/small_int_overflow.scen.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "overflow", - "gasSchedule": "v3", - "steps": [ - { - "step": "setState", - "accounts": { - "sc:basic-features": { - "nonce": "0", - "balance": "0", - "storage": {}, - "code": "file:../output/basic-features.wasm" - }, - "address:an_account": { - "nonce": "0", - "balance": "0", - "storage": {}, - "code": "" - } - } - }, - { - "step": "scCall", - "id": "pow", - "tx": { - "from": "address:an_account", - "to": "sc:basic-features", - "value": "0", - "function": "pow_big_uint", - "arguments": [ - "10", - "80" - ], - "gasLimit": "50,000,000", - "gasPrice": "0" - }, - "expect": { - "out": [ - "100000000000000000000000000000000000000000000000000000000000000000000000000000000" - ], - "status": "0", - "logs": "*", - "gas": "*", - "refund": "*" - } - } - ] -} diff --git a/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json b/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json new file mode 100644 index 0000000000..fadfd8710a --- /dev/null +++ b/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json @@ -0,0 +1,359 @@ +{ + "name": "overflow", + "gasSchedule": "v3", + "steps": [ + { + "step": "setState", + "accounts": { + "sc:basic-features": { + "nonce": "0", + "balance": "0", + "storage": {}, + "code": "file:../output/basic-features.wasm" + }, + "address:an_account": { + "nonce": "0", + "balance": "0", + "storage": {}, + "code": "" + } + } + }, + { + "step": "scCall", + "id": "u8", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u8", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "u8_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u8_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i8", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i8", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i8_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i8_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x80" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "u16", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u16", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "u16_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u16_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i16", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i16", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i16_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i16_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x8000" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "u32", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u32", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "u32_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u32_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i32", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i32", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i32_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i32_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x80000000" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "u64", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u64", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "u64_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "u64_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i64", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i64", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "i64_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "i64_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0x8000000000000000" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + } + ] +} diff --git a/contracts/feature-tests/basic-features/src/basic_features_main.rs b/contracts/feature-tests/basic-features/src/basic_features_main.rs index 4111b7a5e7..2523546192 100644 --- a/contracts/feature-tests/basic-features/src/basic_features_main.rs +++ b/contracts/feature-tests/basic-features/src/basic_features_main.rs @@ -70,6 +70,7 @@ pub trait BasicFeatures: + storage_mapper_non_fungible_token::NonFungibleTokenMapperFeatures + storage_mapper_unique_id_mapper::UniqueIdMapperFeatures + struct_eq::StructEquals + + small_num_overflow_test_ops::SmallIntOverflow + token_identifier_features::TokenIdentifierFeatures + non_zero_features::TypeFeatures + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule diff --git a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs index 466e55bfbd..23cdd4eca8 100644 --- a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs +++ b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs @@ -1,31 +1,115 @@ multiversx_sc::imports!(); -/// Checks that BigUint/BigInt operators work as expected. +/// Used for testing overflow on small int types #[multiversx_sc::module] #[allow(clippy::redundant_clone)] -pub trait SmallIntOperators { +pub trait SmallIntOverflow { #[endpoint] - fn add_usize(&self, a: usize, b: usize) -> usize { - a + b + #[allow(arithmetic_overflow)] + fn usize(&self) -> usize { + usize::MAX + 1 } #[endpoint] - fn add_u8(&self, a: u8, b: u8) -> u8 { - a + b + #[allow(arithmetic_overflow)] + fn u8(&self) -> u8 { + u8::MAX + 1 } #[endpoint] - fn add_u16(&self, a: u16, b: u16) -> u16 { - a + b + #[allow(arithmetic_overflow)] + fn u16(&self) -> u16 { + u16::MAX + 1 } #[endpoint] - fn add_u32(&self, a: u32, b: u32) -> u32 { - a + b + #[allow(arithmetic_overflow)] + fn u32(&self) -> u32 { + u32::MAX + 1 } #[endpoint] - fn add_u64(&self, a: u64, b: u64) -> u64 { - a + b + #[allow(arithmetic_overflow)] + fn u64(&self) -> u64 { + u64::MAX + 1 + } + #[endpoint] + fn usize_overflow(&self) -> usize { + usize::MAX.wrapping_add(1) + } + + #[endpoint] + fn u8_overflow(&self) -> u8 { + u8::MAX.wrapping_add(1) + } + + #[endpoint] + fn u16_overflow(&self) -> u16 { + u16::MAX.wrapping_add(1) + } + + #[endpoint] + fn u32_overflow(&self) -> u32 { + u32::MAX.wrapping_add(1) + } + + #[endpoint] + fn u64_overflow(&self) -> u64 { + u64::MAX.wrapping_add(1) + } + + #[endpoint] + #[allow(arithmetic_overflow)] + fn isize(&self) -> isize { + isize::MAX + 1 + } + + #[endpoint] + #[allow(arithmetic_overflow)] + fn i8(&self) -> i8 { + i8::MAX + 1 + } + + #[endpoint] + #[allow(arithmetic_overflow)] + fn i16(&self) -> i16 { + i16::MAX + 1 + } + + #[endpoint] + #[allow(arithmetic_overflow)] + fn i32(&self) -> i32 { + i32::MAX + 1 + } + + #[endpoint] + #[allow(arithmetic_overflow)] + fn i64(&self) -> i64 { + i64::MAX + 1 + } + + #[endpoint] + fn isize_overflow(&self) -> isize { + isize::MAX.wrapping_add(1) + } + + #[endpoint] + fn i8_overflow(&self) -> i8 { + i8::MAX.wrapping_add(1) + } + + #[endpoint] + fn i16_overflow(&self) -> i16 { + i16::MAX.wrapping_add(1) + } + + #[endpoint] + fn i32_overflow(&self) -> i32 { + i32::MAX.wrapping_add(1) + } + + #[endpoint] + fn i64_overflow(&self) -> i64 { + i64::MAX.wrapping_add(1) } } diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs index 08283808b4..c5ec7fee12 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs @@ -36,6 +36,11 @@ fn big_uint_eq_u_64_rs() { world().run("scenarios/big_uint_eq_u64.scen.json"); } +#[test] +fn small_num_overflow_rs() { + world().run("scenarios/small_num_overflow.scen.json"); +} + #[test] fn big_uint_from_u_64_rs() { world().run("scenarios/big_uint_from_u64.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 f0319f6e1f..243ed86d47 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: 340 +// Endpoints: 360 // Async Callback: 1 -// Total number of exported functions: 342 +// Total number of exported functions: 362 #![no_std] @@ -357,6 +357,26 @@ multiversx_sc_wasm_adapter::endpoints! { unique_id_mapper_set => unique_id_mapper_set unique_id_mapper => unique_id_mapper managed_struct_eq => managed_struct_eq + usize => usize + u8 => u8 + u16 => u16 + u32 => u32 + u64 => u64 + usize_overflow => usize_overflow + u8_overflow => u8_overflow + u16_overflow => u16_overflow + u32_overflow => u32_overflow + u64_overflow => u64_overflow + isize => isize + i8 => i8 + i16 => i16 + i32 => i32 + i64 => i64 + isize_overflow => isize_overflow + i8_overflow => i8_overflow + i16_overflow => i16_overflow + i32_overflow => i32_overflow + i64_overflow => i64_overflow token_identifier_egld => token_identifier_egld token_identifier_is_valid_1 => token_identifier_is_valid_1 token_identifier_is_valid_2 => token_identifier_is_valid_2 From 15193a1bd2a219ca70eb8913e780c126c016ab24 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Wed, 15 Nov 2023 15:36:23 +0200 Subject: [PATCH 4/8] test all int and uint types --- .../scenarios/small_num_overflow.scen.json | 92 ++++++++++++++++++- .../src/small_num_overflow_test_ops.rs | 20 ++-- 2 files changed, 98 insertions(+), 14 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json b/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json index fadfd8710a..3ec613769c 100644 --- a/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json @@ -95,7 +95,7 @@ }, "expect": { "out": [ - "0x80" + "-2" ], "status": "0", "logs": "*", @@ -179,7 +179,7 @@ }, "expect": { "out": [ - "0x8000" + "-2" ], "status": "0", "logs": "*", @@ -263,7 +263,7 @@ }, "expect": { "out": [ - "0x80000000" + "-2" ], "status": "0", "logs": "*", @@ -347,7 +347,91 @@ }, "expect": { "out": [ - "0x8000000000000000" + "-2" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "usize", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "usize", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "usize_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "usize_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "0" + ], + "status": "0", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "isize", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "isize", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "4", + "message": "str:panic occurred", + "logs": "*", + "gas": "*", + "refund": "*" + } + }, + { + "step": "scCall", + "id": "isize_overflow", + "tx": { + "from": "address:an_account", + "to": "sc:basic-features", + "value": "0", + "function": "isize_overflow", + "arguments": [], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [ + "-2" ], "status": "0", "logs": "*", diff --git a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs index 23cdd4eca8..58423fd404 100644 --- a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs +++ b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs @@ -61,55 +61,55 @@ pub trait SmallIntOverflow { #[endpoint] #[allow(arithmetic_overflow)] fn isize(&self) -> isize { - isize::MAX + 1 + isize::MAX + isize::MAX } #[endpoint] #[allow(arithmetic_overflow)] fn i8(&self) -> i8 { - i8::MAX + 1 + i8::MAX + i8::MAX } #[endpoint] #[allow(arithmetic_overflow)] fn i16(&self) -> i16 { - i16::MAX + 1 + i16::MAX + i16::MAX } #[endpoint] #[allow(arithmetic_overflow)] fn i32(&self) -> i32 { - i32::MAX + 1 + i32::MAX + i32::MAX } #[endpoint] #[allow(arithmetic_overflow)] fn i64(&self) -> i64 { - i64::MAX + 1 + i64::MAX + i64::MAX } #[endpoint] fn isize_overflow(&self) -> isize { - isize::MAX.wrapping_add(1) + isize::MAX.wrapping_add(isize::MAX) } #[endpoint] fn i8_overflow(&self) -> i8 { - i8::MAX.wrapping_add(1) + i8::MAX.wrapping_add(i8::MAX) } #[endpoint] fn i16_overflow(&self) -> i16 { - i16::MAX.wrapping_add(1) + i16::MAX.wrapping_add(i16::MAX) } #[endpoint] fn i32_overflow(&self) -> i32 { - i32::MAX.wrapping_add(1) + i32::MAX.wrapping_add(i32::MAX) } #[endpoint] fn i64_overflow(&self) -> i64 { - i64::MAX.wrapping_add(1) + i64::MAX.wrapping_add(i64::MAX) } } From 5464e24eb7ee9b452935a7e3684b75399b640653 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Wed, 15 Nov 2023 16:05:48 +0200 Subject: [PATCH 5/8] remove missing test files --- .../basic-features/tests/basic_features_scenario_go_test.rs | 5 ----- .../basic-features/tests/basic_features_scenario_rs_test.rs | 5 ----- 2 files changed, 10 deletions(-) diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs index 3f8a7e5964..8cc67d2be5 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs @@ -39,11 +39,6 @@ fn big_uint_pow_go() { world().run("scenarios/big_uint_pow.scen.json"); } -#[test] -fn big_uint_overflow_go() { - world().run("scenarios/big_uint_overflow.scen.json"); -} - #[test] fn big_uint_to_u_64_go() { world().run("scenarios/big_uint_to_u64.scen.json"); diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs index 8604bd2261..3f39fd3b04 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs @@ -56,11 +56,6 @@ fn big_uint_pow_rs() { world().run("scenarios/big_uint_sqrt.scen.json"); } -#[test] -fn big_uint_overflow_rs() { - world().run("scenarios/big_uint_overflow.scen.json"); -} - #[test] fn big_uint_to_u_64_rs() { world().run("scenarios/big_uint_to_u64.scen.json"); From a52748fe5ce6238f4d141fa57171f1f3747d97d1 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Wed, 15 Nov 2023 16:13:15 +0200 Subject: [PATCH 6/8] fix wasm + scenario names --- .../basic-features/tests/basic_features_scenario_rs_test.rs | 4 ++-- contracts/feature-tests/basic-features/wasm/src/lib.rs | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs index 3f39fd3b04..3479b19680 100644 --- a/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs +++ b/contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs @@ -48,12 +48,12 @@ fn big_uint_from_u_64_rs() { #[test] fn big_uint_sqrt_rs() { - world().run("scenarios/big_uint_pow.scen.json"); + world().run("scenarios/big_uint_sqrt.scen.json"); } #[test] fn big_uint_pow_rs() { - world().run("scenarios/big_uint_sqrt.scen.json"); + world().run("scenarios/big_uint_pow.scen.json"); } #[test] diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index c0223d5dcf..977a9832e0 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -5,10 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 360 +// Endpoints: 368 // Async Callback: 1 -// Total number of exported functions: 362 - +// Total number of exported functions: 370 #![no_std] From 7a77f3dbd1a0b9171a64dff53547ace6d8963874 Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Wed, 15 Nov 2023 18:35:12 +0200 Subject: [PATCH 7/8] fix after review --- .../scenarios/small_num_overflow.scen.json | 80 +++++++++---------- .../src/small_num_overflow_test_ops.rs | 38 ++++----- .../basic-features/wasm/src/lib.rs | 38 ++++----- 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json b/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json index 3ec613769c..992cc9f370 100644 --- a/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json +++ b/contracts/feature-tests/basic-features/scenarios/small_num_overflow.scen.json @@ -21,12 +21,12 @@ }, { "step": "scCall", - "id": "u8", + "id": "no_overflow_u8", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u8", + "function": "no_overflow_u8", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -41,12 +41,12 @@ }, { "step": "scCall", - "id": "u8_overflow", + "id": "overflow_u8", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u8_overflow", + "function": "overflow_u8", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -63,12 +63,12 @@ }, { "step": "scCall", - "id": "i8", + "id": "no_overflow_i8", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i8", + "function": "no_overflow_i8", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -83,12 +83,12 @@ }, { "step": "scCall", - "id": "i8_overflow", + "id": "overflow_i8", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i8_overflow", + "function": "overflow_i8", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -105,12 +105,12 @@ }, { "step": "scCall", - "id": "u16", + "id": "no_overflow_u16", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u16", + "function": "no_overflow_u16", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -125,12 +125,12 @@ }, { "step": "scCall", - "id": "u16_overflow", + "id": "overflow_u16", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u16_overflow", + "function": "overflow_u16", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -147,12 +147,12 @@ }, { "step": "scCall", - "id": "i16", + "id": "no_overflow_i16", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i16", + "function": "no_overflow_i16", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -167,12 +167,12 @@ }, { "step": "scCall", - "id": "i16_overflow", + "id": "overflow_i16", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i16_overflow", + "function": "overflow_i16", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -189,12 +189,12 @@ }, { "step": "scCall", - "id": "u32", + "id": "no_overflow_u32", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u32", + "function": "no_overflow_u32", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -209,12 +209,12 @@ }, { "step": "scCall", - "id": "u32_overflow", + "id": "overflow_u32", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u32_overflow", + "function": "overflow_u32", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -231,12 +231,12 @@ }, { "step": "scCall", - "id": "i32", + "id": "no_overflow_i32", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i32", + "function": "no_overflow_i32", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -251,12 +251,12 @@ }, { "step": "scCall", - "id": "i32_overflow", + "id": "overflow_i32", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i32_overflow", + "function": "overflow_i32", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -273,12 +273,12 @@ }, { "step": "scCall", - "id": "u64", + "id": "no_overflow_u64", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u64", + "function": "no_overflow_u64", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -293,12 +293,12 @@ }, { "step": "scCall", - "id": "u64_overflow", + "id": "overflow_u64", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "u64_overflow", + "function": "overflow_u64", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -315,12 +315,12 @@ }, { "step": "scCall", - "id": "i64", + "id": "no_overflow_i64", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i64", + "function": "no_overflow_i64", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -335,12 +335,12 @@ }, { "step": "scCall", - "id": "i64_overflow", + "id": "overflow_i64", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "i64_overflow", + "function": "overflow_i64", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -357,12 +357,12 @@ }, { "step": "scCall", - "id": "usize", + "id": "no_overflow_usize", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "usize", + "function": "no_overflow_usize", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -377,12 +377,12 @@ }, { "step": "scCall", - "id": "usize_overflow", + "id": "overflow_usize", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "usize_overflow", + "function": "overflow_usize", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -399,12 +399,12 @@ }, { "step": "scCall", - "id": "isize", + "id": "no_overflow_isize", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "isize", + "function": "no_overflow_isize", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" @@ -419,12 +419,12 @@ }, { "step": "scCall", - "id": "isize_overflow", + "id": "overflow_isize", "tx": { "from": "address:an_account", "to": "sc:basic-features", "value": "0", - "function": "isize_overflow", + "function": "overflow_isize", "arguments": [], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs index 58423fd404..574777beda 100644 --- a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs +++ b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs @@ -6,25 +6,25 @@ multiversx_sc::imports!(); pub trait SmallIntOverflow { #[endpoint] #[allow(arithmetic_overflow)] - fn usize(&self) -> usize { + fn no_overflow_usize(&self) -> usize { usize::MAX + 1 } #[endpoint] #[allow(arithmetic_overflow)] - fn u8(&self) -> u8 { + fn no_overflow_u8(&self) -> u8 { u8::MAX + 1 } #[endpoint] #[allow(arithmetic_overflow)] - fn u16(&self) -> u16 { + fn no_overflow_u16(&self) -> u16 { u16::MAX + 1 } #[endpoint] #[allow(arithmetic_overflow)] - fn u32(&self) -> u32 { + fn no_overflow_u32(&self) -> u32 { u32::MAX + 1 } @@ -34,82 +34,82 @@ pub trait SmallIntOverflow { u64::MAX + 1 } #[endpoint] - fn usize_overflow(&self) -> usize { + fn overflow_usize(&self) -> usize { usize::MAX.wrapping_add(1) } #[endpoint] - fn u8_overflow(&self) -> u8 { + fn overflow_u8(&self) -> u8 { u8::MAX.wrapping_add(1) } #[endpoint] - fn u16_overflow(&self) -> u16 { + fn overflow_u16(&self) -> u16 { u16::MAX.wrapping_add(1) } #[endpoint] - fn u32_overflow(&self) -> u32 { + fn overflow_u32(&self) -> u32 { u32::MAX.wrapping_add(1) } #[endpoint] - fn u64_overflow(&self) -> u64 { + fn overflow_u64(&self) -> u64 { u64::MAX.wrapping_add(1) } #[endpoint] #[allow(arithmetic_overflow)] - fn isize(&self) -> isize { + fn no_overflow_isize(&self) -> isize { isize::MAX + isize::MAX } #[endpoint] #[allow(arithmetic_overflow)] - fn i8(&self) -> i8 { + fn no_overflow_i8(&self) -> i8 { i8::MAX + i8::MAX } #[endpoint] #[allow(arithmetic_overflow)] - fn i16(&self) -> i16 { + fn no_overflow_i16(&self) -> i16 { i16::MAX + i16::MAX } #[endpoint] #[allow(arithmetic_overflow)] - fn i32(&self) -> i32 { + fn no_overflow_i32(&self) -> i32 { i32::MAX + i32::MAX } #[endpoint] #[allow(arithmetic_overflow)] - fn i64(&self) -> i64 { + fn no_overflow_i64(&self) -> i64 { i64::MAX + i64::MAX } #[endpoint] - fn isize_overflow(&self) -> isize { + fn overflow_isize(&self) -> isize { isize::MAX.wrapping_add(isize::MAX) } #[endpoint] - fn i8_overflow(&self) -> i8 { + fn overflow_i8(&self) -> i8 { i8::MAX.wrapping_add(i8::MAX) } #[endpoint] - fn i16_overflow(&self) -> i16 { + fn overflow_i16(&self) -> i16 { i16::MAX.wrapping_add(i16::MAX) } #[endpoint] - fn i32_overflow(&self) -> i32 { + fn overflow_i32(&self) -> i32 { i32::MAX.wrapping_add(i32::MAX) } #[endpoint] - fn i64_overflow(&self) -> i64 { + fn overflow_i64(&self) -> i64 { i64::MAX.wrapping_add(i64::MAX) } } diff --git a/contracts/feature-tests/basic-features/wasm/src/lib.rs b/contracts/feature-tests/basic-features/wasm/src/lib.rs index 977a9832e0..f30e5c5447 100644 --- a/contracts/feature-tests/basic-features/wasm/src/lib.rs +++ b/contracts/feature-tests/basic-features/wasm/src/lib.rs @@ -365,26 +365,26 @@ multiversx_sc_wasm_adapter::endpoints! { unique_id_mapper_set => unique_id_mapper_set unique_id_mapper => unique_id_mapper managed_struct_eq => managed_struct_eq - usize => usize - u8 => u8 - u16 => u16 - u32 => u32 + no_overflow_usize => no_overflow_usize + no_overflow_u8 => no_overflow_u8 + no_overflow_u16 => no_overflow_u16 + no_overflow_u32 => no_overflow_u32 u64 => u64 - usize_overflow => usize_overflow - u8_overflow => u8_overflow - u16_overflow => u16_overflow - u32_overflow => u32_overflow - u64_overflow => u64_overflow - isize => isize - i8 => i8 - i16 => i16 - i32 => i32 - i64 => i64 - isize_overflow => isize_overflow - i8_overflow => i8_overflow - i16_overflow => i16_overflow - i32_overflow => i32_overflow - i64_overflow => i64_overflow + overflow_usize => overflow_usize + overflow_u8 => overflow_u8 + overflow_u16 => overflow_u16 + overflow_u32 => overflow_u32 + overflow_u64 => overflow_u64 + no_overflow_isize => no_overflow_isize + no_overflow_i8 => no_overflow_i8 + no_overflow_i16 => no_overflow_i16 + no_overflow_i32 => no_overflow_i32 + no_overflow_i64 => no_overflow_i64 + overflow_isize => overflow_isize + overflow_i8 => overflow_i8 + overflow_i16 => overflow_i16 + overflow_i32 => overflow_i32 + overflow_i64 => overflow_i64 token_identifier_egld => token_identifier_egld token_identifier_is_valid_1 => token_identifier_is_valid_1 token_identifier_is_valid_2 => token_identifier_is_valid_2 From 65de16118abcade55d1403f08eb5bd95ac73bd9c Mon Sep 17 00:00:00 2001 From: Alin Cruceat Date: Wed, 15 Nov 2023 18:40:43 +0200 Subject: [PATCH 8/8] typo rename --- .../basic-features/src/small_num_overflow_test_ops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs index 574777beda..6104f00dbe 100644 --- a/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs +++ b/contracts/feature-tests/basic-features/src/small_num_overflow_test_ops.rs @@ -30,7 +30,7 @@ pub trait SmallIntOverflow { #[endpoint] #[allow(arithmetic_overflow)] - fn u64(&self) -> u64 { + fn no_overflow_u64(&self) -> u64 { u64::MAX + 1 } #[endpoint]