| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964 |
- // SPDX-License-Identifier: Apache-2.0
- use crate::build_solidity;
- #[test]
- fn u256_basic_ops() {
- let runtime = build_solidity(
- r#"contract math {
- function add(uint256 a, uint256 b) public returns (uint256) {
- return a + b;
- }
- function sub(uint256 a, uint256 b) public returns (uint256) {
- return a - b;
- }
- function mul(uint256 a, uint256 b) public returns (uint256) {
- return a * b;
- }
- function div(uint256 b) public returns (uint256) {
- uint256 a = 100;
- return a / b;
- }
- function mod(uint256 b) public returns (uint256) {
- uint256 a = 100;
- return a % b;
- }
- // Test function that uses constants to avoid passing 256-bit values
- function test_constants() public returns (uint256) {
- uint256 a = 5;
- uint256 b = 4;
- return a + b;
- }
- // Test edge case: maximum uint256 value
- function test_max_value() public returns (uint256) {
- uint256 max = 2**256 - 1;
- return max;
- }
- // Test edge case: zero values
- function test_zero_ops() public returns (uint256) {
- uint256 a = 0;
- uint256 b = 0;
- return a + b;
- }
- // Test edge case: large numbers
- function test_large_numbers() public returns (uint256) {
- uint256 a = 2**128;
- uint256 b = 2**128;
- return a + b;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test the constants function first
- let res = runtime.invoke_contract(addr, "test_constants", vec![]);
- assert!(!res.is_void());
- // Test max value function
- let res = runtime.invoke_contract(addr, "test_max_value", vec![]);
- assert!(!res.is_void());
- // Test zero operations
- let res = runtime.invoke_contract(addr, "test_zero_ops", vec![]);
- assert!(!res.is_void());
- // Test large numbers
- let res = runtime.invoke_contract(addr, "test_large_numbers", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn u256_edge_cases() {
- let runtime = build_solidity(
- r#"contract math {
- // Test boundary values (simplified)
- function test_boundary_values() public returns (uint256) {
- uint256 a = 1;
- uint256 b = 2**64;
- return a + b;
- }
- // Test power of 2 values
- function test_power_of_2() public returns (uint256) {
- uint256 a = 2**64;
- uint256 b = 2**64;
- return a + b;
- }
- // Test minimum values
- function test_min_values() public returns (uint256) {
- uint256 a = 0;
- uint256 b = 1;
- return a + b;
- }
- // Test near-maximum values (simplified to avoid compilation issues)
- function test_near_max_values() public returns (uint256) {
- uint256 a = 2**128;
- uint256 b = 2**128;
- return a + b;
- }
- // Test single bit values
- function test_single_bit_values() public returns (uint256) {
- uint256 a = 2**128;
- uint256 b = 2**128;
- return a + b;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test boundary values
- let res = runtime.invoke_contract(addr, "test_boundary_values", vec![]);
- assert!(!res.is_void());
- // Test power of 2 values
- let res = runtime.invoke_contract(addr, "test_power_of_2", vec![]);
- assert!(!res.is_void());
- // Test min values
- let res = runtime.invoke_contract(addr, "test_min_values", vec![]);
- assert!(!res.is_void());
- // Test near max values
- let res = runtime.invoke_contract(addr, "test_near_max_values", vec![]);
- assert!(!res.is_void());
- // Test single bit values
- let res = runtime.invoke_contract(addr, "test_single_bit_values", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn u256_overflow_scenarios() {
- let runtime = build_solidity(
- r#"contract math {
- // Test overflow scenarios (should wrap around) - simplified
- function test_overflow_wrap() public returns (uint256) {
- uint256 a = 2**64;
- uint256 b = 2**64;
- return a + b; // Should wrap around
- }
- // Test large multiplication - simplified
- function test_large_multiplication() public returns (uint256) {
- uint256 a = 2**64;
- uint256 b = 2**64;
- return a * b; // Should be 2**128
- }
- // Test bit shifting beyond bounds
- function test_shift_beyond_bounds() public returns (uint256) {
- uint256 a = 1;
- return a << 64; // Should be 2**64
- }
- // Test division edge (simplified)
- function test_division_edge() public returns (uint256) {
- uint256 a = 2**64;
- uint256 b = 1;
- return a / b; // Should be 2**64
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test overflow wrap
- let res = runtime.invoke_contract(addr, "test_overflow_wrap", vec![]);
- assert!(!res.is_void());
- // Test large multiplication
- let res = runtime.invoke_contract(addr, "test_large_multiplication", vec![]);
- assert!(!res.is_void());
- // Test shift beyond bounds
- let res = runtime.invoke_contract(addr, "test_shift_beyond_bounds", vec![]);
- assert!(!res.is_void());
- // Test division edge
- let res = runtime.invoke_contract(addr, "test_division_edge", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_no_power_test() {
- let runtime = build_solidity(
- r#"contract math {
- // Test int256 without power operators
- function test_simple() public returns (int256) {
- int256 a = 256; // Simple constant
- return a;
- }
-
- function test_large_constant() public returns (int256) {
- int256 a = 9223372036854775807; // Large constant (2^63 - 1)
- return a;
- }
-
- function test_negative() public returns (int256) {
- int256 a = -9223372036854775808; // Large negative constant
- return a;
- }
-
- function test_arithmetic() public returns (int256) {
- int256 a = 1000000;
- int256 b = 2000000;
- return a + b;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test simple constant
- let res = runtime.invoke_contract(addr, "test_simple", vec![]);
- assert!(!res.is_void());
- // Test large constant
- let res = runtime.invoke_contract(addr, "test_large_constant", vec![]);
- assert!(!res.is_void());
- // Test negative constant
- let res = runtime.invoke_contract(addr, "test_negative", vec![]);
- assert!(!res.is_void());
- // Test arithmetic
- let res = runtime.invoke_contract(addr, "test_arithmetic", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_power_operator_test() {
- let runtime = build_solidity(
- r#"contract math {
- // Use shift-based expressions with uint256 and cast to int256
- function test_power_small() public returns (int256) {
- int256 a = int256(uint256(1) << 8);
- return a;
- }
-
- function test_power_medium() public returns (int256) {
- int256 a = int256(uint256(1) << 64);
- return a;
- }
-
- function test_power_large() public returns (int256) {
- int256 a = int256(uint256(1) << 127);
- return a;
- }
-
- function test_power_max() public returns (int256) {
- int256 a = int256((uint256(1) << 255) - 1);
- return a;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test small power
- let res = runtime.invoke_contract(addr, "test_power_small", vec![]);
- assert!(!res.is_void());
- // Test medium power
- let res = runtime.invoke_contract(addr, "test_power_medium", vec![]);
- assert!(!res.is_void());
- // Test large power
- let res = runtime.invoke_contract(addr, "test_power_large", vec![]);
- assert!(!res.is_void());
- // Test max power
- let res = runtime.invoke_contract(addr, "test_power_max", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_basic_ops() {
- let runtime = build_solidity(
- r#"contract math {
- function add(int256 a, int256 b) public returns (int256) {
- return a + b;
- }
- function sub(int256 a, int256 b) public returns (int256) {
- return a - b;
- }
- function mul(int256 a, int256 b) public returns (int256) {
- return a * b;
- }
- function div(int256 b) public returns (int256) {
- int256 a = 100;
- return a / b;
- }
- function mod(int256 b) public returns (int256) {
- int256 a = 100;
- return a % b;
- }
- // Test function that uses constants to avoid passing 256-bit values
- function test_constants() public returns (int256) {
- int256 a = 5;
- int256 b = 4;
- return a + b;
- }
- // Test edge case: maximum int256 value using shift-based expression
- function test_max_value() public returns (int256) {
- int256 max = int256((uint256(1) << 255) - 1);
- return max;
- }
- // Test edge case: zero values
- function test_zero_ops() public returns (int256) {
- int256 a = 0;
- int256 b = 0;
- return a + b;
- }
- // Test edge case: large positive numbers using shift-based expressions
- function test_large_positive() public returns (int256) {
- int256 a = int256(uint256(1) << 127);
- int256 b = int256(uint256(1) << 127);
- return a + b;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test the constants function first
- let res = runtime.invoke_contract(addr, "test_constants", vec![]);
- assert!(!res.is_void());
- // Test max value function
- let res = runtime.invoke_contract(addr, "test_max_value", vec![]);
- assert!(!res.is_void());
- // Test zero operations
- let res = runtime.invoke_contract(addr, "test_zero_ops", vec![]);
- assert!(!res.is_void());
- // Test large positive numbers
- let res = runtime.invoke_contract(addr, "test_large_positive", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_edge_cases() {
- let runtime = build_solidity(
- r#"contract math {
- // Test minimum int256 value
- function test_min_value() public returns (int256) {
- int256 min = int256(uint256(1) << 255);
- return min;
- }
- // Test negative edge cases
- function test_negative_edge() public returns (int256) {
- int256 a = int256(uint256(1) << 255); // Min value
- int256 b = 1;
- return a + b; // Should be min + 1
- }
- // Test boundary between positive and negative
- function test_boundary_crossing() public returns (int256) {
- int256 a = -1;
- int256 b = 1;
- return a + b; // Should be 0
- }
- // Test large negative numbers
- function test_large_negative() public returns (int256) {
- int256 a = int256(uint256(1) << 255); // Min value
- int256 b = int256(uint256(1) << 254); // Half of min
- return a + b; // Should be a very large negative number
- }
- // Test sign change operations
- function test_sign_change() public returns (int256) {
- int256 a = 100;
- return -a; // Should be -100
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test min value
- let res = runtime.invoke_contract(addr, "test_min_value", vec![]);
- assert!(!res.is_void());
- // Test negative edge
- let res = runtime.invoke_contract(addr, "test_negative_edge", vec![]);
- assert!(!res.is_void());
- // Test boundary crossing
- let res = runtime.invoke_contract(addr, "test_boundary_crossing", vec![]);
- assert!(!res.is_void());
- // Test large negative
- let res = runtime.invoke_contract(addr, "test_large_negative", vec![]);
- assert!(!res.is_void());
- // Test sign change
- let res = runtime.invoke_contract(addr, "test_sign_change", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_overflow_scenarios() {
- let runtime = build_solidity(
- r#"contract math {
- // Test positive overflow (should wrap around) - simplified
- function test_positive_overflow() public returns (int256) {
- int256 a = int256((uint256(1) << 63) - 1); // Max positive for 64-bit
- int256 b = 1;
- return a + b; // Should wrap to min value
- }
- // Test negative overflow (should wrap around) - simplified
- function test_negative_overflow() public returns (int256) {
- int256 a = int256(uint256(1) << 63); // Min value for 64-bit
- int256 b = -1;
- return a + b; // Should wrap to max positive
- }
- // Test multiplication overflow - simplified
- function test_multiplication_overflow() public returns (int256) {
- int256 a = int256(uint256(1) << 31); // Large positive
- int256 b = 2;
- return a * b; // Should overflow
- }
- // Test division edge cases - simplified
- function test_division_edge() public returns (int256) {
- int256 a = int256(uint256(1) << 63); // Min value
- int256 b = -1;
- return a / b; // Should be max positive
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test positive overflow
- let res = runtime.invoke_contract(addr, "test_positive_overflow", vec![]);
- assert!(!res.is_void());
- // Test negative overflow
- let res = runtime.invoke_contract(addr, "test_negative_overflow", vec![]);
- assert!(!res.is_void());
- // Test multiplication overflow
- let res = runtime.invoke_contract(addr, "test_multiplication_overflow", vec![]);
- assert!(!res.is_void());
- // Test division edge
- let res = runtime.invoke_contract(addr, "test_division_edge", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_minimal_test() {
- let runtime = build_solidity(
- r#"contract math {
- // Minimal test: just declare an int256 variable and return it
- function test_minimal() public returns (int256) {
- int256 a = 5;
- return a;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test the minimal function
- let res = runtime.invoke_contract(addr, "test_minimal", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_simple_arithmetic() {
- let runtime = build_solidity(
- r#"contract math {
- // Simple arithmetic test
- function test_add() public returns (int256) {
- int256 a = 5;
- int256 b = 3;
- return a + b;
- }
-
- function test_sub() public returns (int256) {
- int256 a = 10;
- int256 b = 4;
- return a - b;
- }
-
- function test_mul() public returns (int256) {
- int256 a = 6;
- int256 b = 7;
- return a * b;
- }
-
- function test_div() public returns (int256) {
- int256 a = 20;
- int256 b = 4;
- return a / b;
- }
-
- function test_mod() public returns (int256) {
- int256 a = 23;
- int256 b = 5;
- return a % b;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test addition
- let res = runtime.invoke_contract(addr, "test_add", vec![]);
- assert!(!res.is_void());
- // Test subtraction
- let res = runtime.invoke_contract(addr, "test_sub", vec![]);
- assert!(!res.is_void());
- // Test multiplication
- let res = runtime.invoke_contract(addr, "test_mul", vec![]);
- assert!(!res.is_void());
- // Test division
- let res = runtime.invoke_contract(addr, "test_div", vec![]);
- assert!(!res.is_void());
- // Test modulo
- let res = runtime.invoke_contract(addr, "test_mod", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn u256_simple_values() {
- let runtime = build_solidity(
- r#"contract math {
- function add(uint256 a, uint256 b) public returns (uint256) {
- return a + b;
- }
- // Test function that uses constants to avoid passing 256-bit values
- function test_constants() public returns (uint256) {
- uint256 a = 100;
- uint256 b = 1;
- return a + b;
- }
- // Test edge case: boundary values
- function test_boundary_values() public returns (uint256) {
- uint256 a = 1;
- uint256 b = 2**256 - 2;
- return a + b;
- }
- // Test edge case: power of 2 values
- function test_power_of_2() public returns (uint256) {
- uint256 a = 2**64;
- uint256 b = 2**64;
- return a + b;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test the constants function first
- let res = runtime.invoke_contract(addr, "test_constants", vec![]);
- assert!(!res.is_void());
- // Test boundary values
- let res = runtime.invoke_contract(addr, "test_boundary_values", vec![]);
- assert!(!res.is_void());
- // Test power of 2 values
- let res = runtime.invoke_contract(addr, "test_power_of_2", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_simple_values() {
- let runtime = build_solidity(
- r#"contract math {
- function add(int256 a, int256 b) public returns (int256) {
- return a + b;
- }
- // Test function that uses constants to avoid passing 256-bit values
- function test_constants() public returns (int256) {
- int256 a = 100;
- int256 b = 1;
- return a + b;
- }
- // Test edge case: boundary values using shift-based expression
- function test_boundary_values() public returns (int256) {
- int256 a = 1;
- int256 b = int256((uint256(1) << 255) - 2);
- return a + b;
- }
- // Test edge case: power of 2 values using shift-based expressions
- function test_power_of_2() public returns (int256) {
- int256 a = int256(uint256(1) << 63);
- int256 b = int256(uint256(1) << 63);
- return a + b;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test the constants function first
- let res = runtime.invoke_contract(addr, "test_constants", vec![]);
- assert!(!res.is_void());
- // Test boundary values
- let res = runtime.invoke_contract(addr, "test_boundary_values", vec![]);
- assert!(!res.is_void());
- // Test power of 2 values
- let res = runtime.invoke_contract(addr, "test_power_of_2", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn u256_complex_operations() {
- let runtime = build_solidity(
- r#"contract math {
- // Test complex operations with 256-bit integers
- function test_complex_math() public returns (uint256) {
- uint256 a = 2**128;
- uint256 b = 2**64;
- uint256 c = 2**32;
-
- // Complex expression: (a + b) * c / (b + c)
- uint256 result = (a + b) * c / (b + c);
- return result;
- }
- // Test bitwise operations
- function test_bitwise_ops() public returns (uint256) {
- uint256 a = 2**128 - 1;
- uint256 b = 2**64 - 1;
-
- // Bitwise AND, OR, XOR
- uint256 and_result = a & b;
- uint256 or_result = a | b;
- uint256 xor_result = a ^ b;
-
- // Return combination of results
- return and_result + or_result + xor_result;
- }
- // Test shift operations
- function test_shift_ops() public returns (uint256) {
- uint256 a = 2**128;
-
- // Left shift by 64
- uint256 left_shift = a << 64;
- // Right shift by 32
- uint256 right_shift = a >> 32;
-
- return left_shift + right_shift;
- }
- // Test comparison operations
- function test_comparisons() public returns (uint256) {
- uint256 a = 2**128;
- uint256 b = 2**64;
-
- // Return 1 if a > b, 0 otherwise
- return a > b ? 1 : 0;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test complex math
- let res = runtime.invoke_contract(addr, "test_complex_math", vec![]);
- assert!(!res.is_void());
- // Test bitwise operations
- let res = runtime.invoke_contract(addr, "test_bitwise_ops", vec![]);
- assert!(!res.is_void());
- // Test shift operations
- let res = runtime.invoke_contract(addr, "test_shift_ops", vec![]);
- assert!(!res.is_void());
- // Test comparisons
- let res = runtime.invoke_contract(addr, "test_comparisons", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_complex_operations() {
- let runtime = build_solidity(
- r#"contract math {
- // Test complex operations with signed 256-bit integers
- function test_complex_math() public returns (int256) {
- int256 a = int256(uint256(1) << 127); // 2^127
- int256 b = int256(uint256(1) << 63); // 2^63
- int256 c = int256(uint256(1) << 31); // 2^31
-
- // Complex expression: (a + b) * c / (b + c)
- int256 result = (a + b) * c / (b + c);
- return result;
- }
- // Test bitwise operations with signed integers
- function test_bitwise_ops() public returns (int256) {
- int256 a = int256((uint256(1) << 127) - 1); // 2^127 - 1
- int256 b = int256((uint256(1) << 63) - 1); // 2^63 - 1
-
- // Bitwise AND, OR, XOR
- int256 and_result = a & b;
- int256 or_result = a | b;
- int256 xor_result = a ^ b;
-
- // Return combination of results
- return and_result + or_result + xor_result;
- }
- // Test shift operations with signed integers
- function test_shift_ops() public returns (int256) {
- int256 a = int256(uint256(1) << 127); // 2^127
-
- // Left shift by 32
- int256 left_shift = a << 32;
- // Right shift by 16 (arithmetic shift for signed)
- int256 right_shift = a >> 16;
-
- return left_shift + right_shift;
- }
- // Test comparison operations with signed integers
- function test_comparisons() public returns (int256) {
- int256 a = int256(uint256(1) << 127); // Large positive
- int256 b = int256(uint256(1) << 63); // Smaller positive
- int256 c = -1; // Negative
-
- // Return 1 if a > b, 0 otherwise
- return a > b ? 1 : 0;
- }
- // Test negative number operations
- function test_negative_ops() public returns (int256) {
- int256 a = -1000;
- int256 b = 500;
-
- // Test operations with negative numbers
- int256 sum = a + b;
- int256 diff = a - b;
- int256 prod = a * b;
- int256 quot = a / b;
-
- return sum + diff + prod + quot;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test complex math
- let res = runtime.invoke_contract(addr, "test_complex_math", vec![]);
- assert!(!res.is_void());
- // Test bitwise operations
- let res = runtime.invoke_contract(addr, "test_bitwise_ops", vec![]);
- assert!(!res.is_void());
- // Test shift operations
- let res = runtime.invoke_contract(addr, "test_shift_ops", vec![]);
- assert!(!res.is_void());
- // Test comparisons
- let res = runtime.invoke_contract(addr, "test_comparisons", vec![]);
- assert!(!res.is_void());
- // Test negative operations
- let res = runtime.invoke_contract(addr, "test_negative_ops", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn u256_stress_test() {
- let runtime = build_solidity(
- r#"contract math {
- // Test stress operations with multiple operations
- function test_stress_operations() public returns (uint256) {
- uint256 result = 0;
-
- // Multiple arithmetic operations (simplified)
- for (uint256 i = 0; i < 10; i++) {
- result += i;
- result *= 2;
- result = result % (2**64); // Keep within bounds
- }
-
- return result;
- }
- // Test with very large numbers (simplified)
- function test_very_large_numbers() public returns (uint256) {
- uint256 a = 2**64;
- uint256 b = 2**63;
- uint256 c = 2**62;
-
- // Complex calculation (simplified)
- uint256 result = (a + b) * c / (a + c);
- return result;
- }
- // Test boundary conditions (simplified)
- function test_boundary_conditions() public returns (uint256) {
- uint256 max = 2**64;
- uint256 min = 0;
- uint256 one = 1;
-
- // Test edge cases
- uint256 result = max - one;
- result = result + one;
- result = result * one;
- result = result / one;
-
- return result;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test stress operations
- let res = runtime.invoke_contract(addr, "test_stress_operations", vec![]);
- assert!(!res.is_void());
- // Test very large numbers
- let res = runtime.invoke_contract(addr, "test_very_large_numbers", vec![]);
- assert!(!res.is_void());
- // Test boundary conditions
- let res = runtime.invoke_contract(addr, "test_boundary_conditions", vec![]);
- assert!(!res.is_void());
- }
- #[test]
- fn i256_stress_test() {
- let runtime = build_solidity(
- r#"contract math {
- // Test stress operations with multiple operations for signed integers
- function test_stress_operations() public returns (int256) {
- int256 result = 0;
-
- // Multiple arithmetic operations (simplified)
- for (int256 i = 0; i < 10; i++) {
- result += i;
- result *= 2;
- result = result % int256(uint256(1) << 63); // Keep within bounds
- }
-
- return result;
- }
- // Test with very large signed numbers (simplified)
- function test_very_large_numbers() public returns (int256) {
- int256 a = int256(uint256(1) << 63); // Large positive
- int256 b = int256(uint256(1) << 62); // Smaller positive
- int256 c = int256(uint256(1) << 61); // Even smaller
-
- // Complex calculation (simplified)
- int256 result = (a + b) * c / (a + c);
- return result;
- }
- // Test boundary conditions for signed integers (simplified)
- function test_boundary_conditions() public returns (int256) {
- int256 max_pos = int256((uint256(1) << 63) - 1); // Max positive
- int256 min_neg = int256(uint256(1) << 63); // Min negative
- int256 one = 1;
- int256 neg_one = -1;
-
- // Test edge cases (simplified)
- int256 result = max_pos - one;
- result = result + one;
- result = result * one;
- result = result / one;
-
- return result;
- }
- // Test negative number stress (simplified)
- function test_negative_stress() public returns (int256) {
- int256 result = 0;
-
- // Work with negative numbers (simplified)
- for (int256 i = -5; i < 5; i++) {
- result += i;
- result = result * (i < 0 ? -1 : 1);
- result = result % int256(uint256(1) << 63);
- }
-
- return result;
- }
- }"#,
- |_| {},
- );
- let addr = runtime.contracts.last().unwrap();
- // Test stress operations
- let res = runtime.invoke_contract(addr, "test_stress_operations", vec![]);
- assert!(!res.is_void());
- // Test very large numbers
- let res = runtime.invoke_contract(addr, "test_very_large_numbers", vec![]);
- assert!(!res.is_void());
- // Test boundary conditions
- let res = runtime.invoke_contract(addr, "test_boundary_conditions", vec![]);
- assert!(!res.is_void());
- // Test negative stress
- let res = runtime.invoke_contract(addr, "test_negative_stress", vec![]);
- assert!(!res.is_void());
- }
|