diff --git a/packages/fuels-code-gen/src/program_bindings/resolved_type.rs b/packages/fuels-code-gen/src/program_bindings/resolved_type.rs index 8bee4508d..ab6d809bc 100644 --- a/packages/fuels-code-gen/src/program_bindings/resolved_type.rs +++ b/packages/fuels-code-gen/src/program_bindings/resolved_type.rs @@ -112,6 +112,8 @@ impl TypeResolver { } pub(crate) fn resolve(&self, type_application: &FullTypeApplication) -> Result { + Self::is_deprecated(type_application.type_decl.type_field.as_str())?; + let resolvers = [ Self::try_as_primitive_type, Self::try_as_bits256, @@ -144,6 +146,15 @@ impl TypeResolver { .collect() } + fn is_deprecated(type_field: &str) -> Result<()> { + match type_field { + "struct std::u256::U256" | "struct U256" => { + Err(error!("{} is deprecated. Use `u256` instead.", type_field)) + } + _ => Ok(()), + } + } + fn try_as_generic( &self, type_application: &FullTypeApplication, @@ -228,16 +239,20 @@ impl TypeResolver { let maybe_resolved = match type_field.as_str() { "()" => Some(ResolvedType::Unit), - "struct std::u128::U128" | "struct U128" => { - let u128_path = TypePath::new("::core::primitive::u128").expect("to be correct"); - Some(ResolvedType::Primitive(u128_path)) - } - "u8" | "u16" | "u32" | "u64" | "bool" => { + "bool" | "u8" | "u16" | "u32" | "u64" => { let path = format!("::core::primitive::{type_field}"); let type_path = TypePath::new(path).expect("to be a valid path"); Some(ResolvedType::Primitive(type_path)) } + "struct std::u128::U128" | "struct U128" => { + let u128_path = TypePath::new("::core::primitive::u128").expect("is correct"); + Some(ResolvedType::Primitive(u128_path)) + } + "u256" => { + let u256_path = TypePath::new("::fuels::types::U256").expect("is correct"); + Some(ResolvedType::Primitive(u256_path)) + } _ => None, }; diff --git a/packages/fuels-code-gen/src/program_bindings/utils.rs b/packages/fuels-code-gen/src/program_bindings/utils.rs index bd2cc0483..56671a371 100644 --- a/packages/fuels-code-gen/src/program_bindings/utils.rs +++ b/packages/fuels-code-gen/src/program_bindings/utils.rs @@ -149,7 +149,6 @@ pub(crate) fn sdk_provided_custom_types_lookup() -> HashMap ("std::option::Option", "::core::option::Option"), ("std::result::Result", "::core::result::Result"), ("std::string::String", "::std::string::String"), - ("std::u256::U256", "::fuels::types::U256"), ("std::vec::Vec", "::std::vec::Vec"), ( "std::vm::evm::evm_address::EvmAddress", diff --git a/packages/fuels-core/src/codec/function_selector.rs b/packages/fuels-core/src/codec/function_selector.rs index 2e04683ee..b77748da6 100644 --- a/packages/fuels-core/src/codec/function_selector.rs +++ b/packages/fuels-core/src/codec/function_selector.rs @@ -27,7 +27,7 @@ fn resolve_arg(arg: &ParamType) -> String { ParamType::U32 => "u32".to_owned(), ParamType::U64 => "u64".to_owned(), ParamType::U128 => "s(u64,u64)".to_owned(), - ParamType::U256 => "s(u64,u64,u64,u64)".to_owned(), + ParamType::U256 => "u256".to_owned(), ParamType::Bool => "bool".to_owned(), ParamType::B256 => "b256".to_owned(), ParamType::Unit => "()".to_owned(), diff --git a/packages/fuels/tests/types/contracts/u256/src/main.sw b/packages/fuels/tests/types/contracts/u256/src/main.sw index f930777e6..5a1bd9955 100644 --- a/packages/fuels/tests/types/contracts/u256/src/main.sw +++ b/packages/fuels/tests/types/contracts/u256/src/main.sw @@ -1,7 +1,5 @@ contract; -use std::u256::U256; - #[allow(dead_code)] enum SomeEnum { A: bool, @@ -9,32 +7,30 @@ enum SomeEnum { } abi MyContract { - fn u256_sum_and_ret(some_u256: U256) -> U256; - fn u256_in_enum_input(some_enum: SomeEnum); - fn u256_in_enum_output() -> SomeEnum; + fn u256_sum_and_ret(some_u256: u256) -> u256; + fn u256_in_enum_output() -> SomeEnum; + fn u256_in_enum_input(some_enum: SomeEnum); } impl MyContract for Contract { - #[allow(deprecated)] - fn u256_sum_and_ret(arg: U256) -> U256 { - arg + U256::from((3, 4, 5, 6)) + fn u256_sum_and_ret(arg: u256) -> u256 { + arg + 0x0000000000000003000000000000000400000000000000050000000000000006u256 + } + + fn u256_in_enum_output() -> SomeEnum { + SomeEnum::B( + 0x0000000000000001000000000000000200000000000000030000000000000004u256, + ) } - #[allow(deprecated)] - fn u256_in_enum_input(some_enum: SomeEnum) { + fn u256_in_enum_input(some_enum: SomeEnum) { if let SomeEnum::B(some_u256) = some_enum { - let expected_u256 = U256::from((2, 3, 4, 5)); require( - some_u256 == expected_u256, + some_u256 == 0x0000000000000002000000000000000300000000000000040000000000000005u256, "given u256 didn't match the expected u256", ); } else { require(false, "enum was not of variant B: u256"); } } - - #[allow(deprecated)] - fn u256_in_enum_output() -> SomeEnum { - SomeEnum::B(U256::from((1, 2, 3, 4))) - } } diff --git a/packages/fuels/tests/types/predicates/predicate_u256/src/main.sw b/packages/fuels/tests/types/predicates/predicate_u256/src/main.sw index 59bb293a0..6d53cf3b3 100644 --- a/packages/fuels/tests/types/predicates/predicate_u256/src/main.sw +++ b/packages/fuels/tests/types/predicates/predicate_u256/src/main.sw @@ -1,8 +1,5 @@ predicate; -use std::u256::U256; - -#[allow(deprecated)] -fn main(arg: U256) -> bool { - arg == U256::from((10, 11, 12, 13)) +fn main(arg: u256) -> bool { + arg == 0x000000000000000a000000000000000b000000000000000c000000000000000du256 } diff --git a/packages/fuels/tests/types/scripts/script_u256/src/main.sw b/packages/fuels/tests/types/scripts/script_u256/src/main.sw index 8a827b42f..d92297493 100644 --- a/packages/fuels/tests/types/scripts/script_u256/src/main.sw +++ b/packages/fuels/tests/types/scripts/script_u256/src/main.sw @@ -1,8 +1,5 @@ script; -use std::u256::U256; - -#[allow(deprecated)] -fn main(arg: U256) -> U256 { - arg + U256::from((6, 7, 8, 9)) +fn main(arg: u256) -> u256 { + arg + 0x0000000000000006000000000000000700000000000000080000000000000009u256 } diff --git a/packages/fuels/tests/types_contracts.rs b/packages/fuels/tests/types_contracts.rs index e65c43a1e..1043d9d59 100644 --- a/packages/fuels/tests/types_contracts.rs +++ b/packages/fuels/tests/types_contracts.rs @@ -930,12 +930,12 @@ async fn strings_must_have_correct_length_custom_types() { "type": "enum MyEnum", "components": [ { - "name": "foo", + "name": "Foo", "type": 1, "typeArguments": null }, { - "name": "bar", + "name": "Bar", "type": 3, "typeArguments": null } @@ -980,7 +980,7 @@ async fn strings_must_have_correct_length_custom_types() { let contract_instance = SimpleContract::new(null_contract_id(), wallet); let _ = contract_instance .methods() - .takes_enum(MyEnum::bar("fuell".try_into().unwrap())); + .takes_enum(MyEnum::Bar("fuell".try_into().unwrap())); } #[tokio::test] @@ -1747,17 +1747,15 @@ async fn test_u256() -> Result<()> { let contract_methods = contract_instance.methods(); { let arg = u256_from((1, 2, 3, 4)); - let actual = contract_methods.u256_sum_and_ret(arg).call().await?.value; - let expected = arg + u256_from((3, 4, 5, 6)); assert_eq!(expected, actual); } { let actual = contract_methods.u256_in_enum_output().call().await?.value; - let expected = SomeEnum::B(u256_from((1, 2, 3, 4))); + assert_eq!(expected, actual); } {