From a7a19424790e9e6c65a9e83834d0fbcf02027e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaya=20G=C3=B6kalp?= Date: Tue, 29 Nov 2022 03:07:07 -0500 Subject: [PATCH] fix: inject contract_dependency::CONTRACT_ID as b256 (#3412) closes #3410. --- forc-pkg/src/pkg.rs | 2 +- .../contract_dependencies/contract_a/Forc.lock | 10 ++++++++++ .../contract_dependencies/contract_a/Forc.toml | 3 +++ .../contract_a/src/main.sw | 17 +++++++++-------- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index d3be91b05f7..03700a51a5c 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -2123,7 +2123,7 @@ pub fn dependency_namespace( // Construct namespace with contract id let contract_dep_constant_name = "CONTRACT_ID"; - let contract_id_value = format!("\"{dep_contract_id}\""); + let contract_id_value = format!("0x{dep_contract_id}"); let contract_id_constant = ConfigTimeConstant { r#type: "b256".to_string(), value: contract_id_value, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.lock index c3f19ba9ab2..677522a68b6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.lock +++ b/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.lock @@ -1,6 +1,7 @@ [[package]] name = 'contract_a' source = 'member' +dependencies = ['std'] contract-dependencies = [ 'contract_b', 'contract_c', @@ -14,3 +15,12 @@ contract-dependencies = ['contract_c'] [[package]] name = 'contract_c' source = 'path+from-root-C28B6153CE3E3FEB' + +[[package]] +name = 'core' +source = 'path+from-root-C28B6153CE3E3FEB' + +[[package]] +name = 'std' +source = 'path+from-root-C28B6153CE3E3FEB' +dependencies = ['core'] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.toml index cdc45d364ff..e97b9e2f77b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/Forc.toml @@ -5,6 +5,9 @@ implicit-std = false license = "Apache-2.0" name = "contract_a" +[dependencies] +std = { path = "../../../../../../../../sway-lib-std/" } + [contract-dependencies] contract_b = { path = "../contract_b" } contract_c = { path = "../contract_c" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/src/main.sw index 3fc564d2ca9..73017d21fb7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/forc/contract_dependencies/contract_a/src/main.sw @@ -4,13 +4,14 @@ use contract_b::CONTRACT_ID as CONTRACT_B_ID; use contract_c::CONTRACT_ID as CONTRACT_C_ID; abi MyContract { - fn test_function(); + fn test_function(); } - - impl MyContract for Contract { - fn test_function() { - let CONTRACT_B_ID = CONTRACT_B_ID; - let CONTRACT_C_ID = CONTRACT_C_ID; - } - } +impl MyContract for Contract { + fn test_function() { + let CONTRACT_B = CONTRACT_B_ID; + let CONTRACT_C = CONTRACT_C_ID; + let contract_b_id = ContractId::from(CONTRACT_B); + let contract_c_id = ContractId::from(CONTRACT_C); + } +}