-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Description The reproduction presented in #6324 was missing loading the storage configuration properly. To do that we have to use the following in `test/src/sdk-harness/test_projects/run_external_proxy_with_storage/mod.rs`: ```rust StorageConfiguration::default().add_slot_overrides_from_file("test_projects/run_external_target_with_storage/out/release/run_external_target_with_storage-storage_slots.json").unwrap(); ``` This commit changes the presented reproduction to load the storage slots and the test runs without reverting. Closes #6324 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. Co-authored-by: João Matos <[email protected]>
- Loading branch information
Showing
10 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_projects/run_external_proxy_with_storage/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-37E4B1588712FA61' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-37E4B1588712FA61' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'run_external_proxy' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_projects/run_external_proxy_with_storage/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "run_external_proxy_with_storage" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../sway-lib-std" } |
106 changes: 106 additions & 0 deletions
106
test/src/sdk-harness/test_projects/run_external_proxy_with_storage/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
use fuels::{prelude::*, types::Bits256}; | ||
|
||
abigen!(Contract( | ||
name = "RunExternalProxyContract", | ||
abi = "test_projects/run_external_proxy_with_storage/out/release/run_external_proxy_with_storage-abi.json", | ||
)); | ||
|
||
#[tokio::test] | ||
async fn run_external_can_proxy_call() { | ||
let wallet = launch_provider_and_get_wallet().await.unwrap(); | ||
|
||
let storage_configuration = | ||
StorageConfiguration::default().add_slot_overrides_from_file("test_projects/run_external_target_with_storage/out/release/run_external_target_with_storage-storage_slots.json").unwrap(); | ||
|
||
let target_id = Contract::load_from( | ||
"test_projects/run_external_target_with_storage/out/release/run_external_target_with_storage.bin", | ||
LoadConfiguration::default() | ||
.with_storage_configuration(storage_configuration.clone()), | ||
) | ||
.unwrap() | ||
.deploy(&wallet, TxPolicies::default()) | ||
.await | ||
.unwrap(); | ||
|
||
let configurables = RunExternalProxyContractConfigurables::default() | ||
.with_TARGET(target_id.clone().into()) | ||
.unwrap(); | ||
let id = Contract::load_from( | ||
"test_projects/run_external_proxy_with_storage/out/release/run_external_proxy_with_storage.bin", | ||
LoadConfiguration::default().with_configurables(configurables).with_storage_configuration(storage_configuration), | ||
) | ||
.unwrap() | ||
.deploy(&wallet, TxPolicies::default()) | ||
.await | ||
.unwrap(); | ||
let instance = RunExternalProxyContract::new(id.clone(), wallet); | ||
// Call "large_value" | ||
// Will call run_external_proxy::large_value | ||
// that will call run_external_target::large_value | ||
// and return the value doubled. | ||
let result = instance | ||
.methods() | ||
.large_value() | ||
.with_contract_ids(&[target_id.clone().into()]) | ||
.call() | ||
.await | ||
.unwrap(); | ||
for r in result.receipts.iter() { | ||
match r { | ||
Receipt::LogData { data, .. } => { | ||
if let Some(data) = data { | ||
if data.len() > 8 { | ||
if let Ok(s) = std::str::from_utf8(&data[8..]) { | ||
print!("{:?} ", s); | ||
} | ||
} | ||
println!("{:?}", data); | ||
} | ||
} | ||
_ => {} | ||
} | ||
} | ||
let expected_large = | ||
Bits256::from_hex_str("0x00000000000000000000000059F2f1fCfE2474fD5F0b9BA1E73ca90b143Eb8d0") | ||
.unwrap(); | ||
assert_eq!(result.value, expected_large); | ||
// Call "double_value" | ||
// Will call run_external_proxy::double_value | ||
// that will call run_external_target::double_value | ||
// and return the value doubled. | ||
let result = instance | ||
.methods() | ||
.double_value(42) | ||
.with_contract_ids(&[target_id.clone().into()]) | ||
.call() | ||
.await | ||
.unwrap(); | ||
for r in result.receipts.iter() { | ||
match r { | ||
Receipt::LogData { data, .. } => { | ||
if let Some(data) = data { | ||
if data.len() > 8 { | ||
if let Ok(s) = std::str::from_utf8(&data[8..]) { | ||
print!("{:?} ", s); | ||
} | ||
} | ||
println!("{:?}", data); | ||
} | ||
} | ||
_ => {} | ||
} | ||
} | ||
assert_eq!(result.value, 84); | ||
// Call "does_not_exist_in_the_target" | ||
// Will call run_external_proxy::does_not_exist_in_the_target | ||
// it will proxy the call to run_external_target, | ||
// and endup in the fallback, fn that will triple the input value | ||
let result = instance | ||
.methods() | ||
.does_not_exist_in_the_target(42) | ||
.with_contract_ids(&[target_id.into()]) | ||
.call() | ||
.await | ||
.unwrap(); | ||
assert_eq!(result.value, 126); | ||
} |
29 changes: 29 additions & 0 deletions
29
test/src/sdk-harness/test_projects/run_external_proxy_with_storage/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
contract; | ||
|
||
use std::execution::run_external; | ||
|
||
configurable { | ||
TARGET: ContractId = ContractId::zero(), | ||
} | ||
|
||
abi RunExternalTest { | ||
fn double_value(foo: u64) -> u64; | ||
fn large_value() -> b256; | ||
fn does_not_exist_in_the_target(foo: u64) -> u64; | ||
} | ||
impl RunExternalTest for Contract { | ||
fn double_value(_foo: u64) -> u64 { | ||
__log(1); | ||
run_external(TARGET) | ||
} | ||
|
||
fn large_value() -> b256 { | ||
run_external(TARGET) | ||
} | ||
|
||
// ANCHOR: does_not_exist_in_the_target | ||
fn does_not_exist_in_the_target(_foo: u64) -> u64 { | ||
run_external(TARGET) | ||
} | ||
// ANCHOR_END: does_not_exist_in_the_target | ||
} |
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_projects/run_external_target_with_storage/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-37E4B1588712FA61' | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-37E4B1588712FA61' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'run_external_target' | ||
source = 'member' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_projects/run_external_target_with_storage/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "run_external_target_with_storage" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../sway-lib-std" } |
38 changes: 38 additions & 0 deletions
38
test/src/sdk-harness/test_projects/run_external_target_with_storage/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
contract; | ||
|
||
use std::constants::ZERO_B256; | ||
|
||
storage { | ||
owner: Identity = Identity::Address(Address::from(ZERO_B256)), | ||
simple_value: u64 = 0, | ||
} | ||
|
||
abi RunExternalTest { | ||
fn double_value(foo: u64) -> u64; | ||
fn large_value() -> b256; | ||
} | ||
|
||
impl RunExternalTest for Contract { | ||
fn double_value(foo: u64) -> u64 { | ||
__log(2); | ||
foo * 2 | ||
} | ||
fn large_value() -> b256 { | ||
0x00000000000000000000000059F2f1fCfE2474fD5F0b9BA1E73ca90b143Eb8d0 | ||
} | ||
} | ||
|
||
// ANCHOR: fallback | ||
#[fallback, storage(read, write)] | ||
fn fallback() -> u64 { | ||
let iden = storage.owner.read(); | ||
|
||
use std::call_frames::*; | ||
__log(3); | ||
__log(called_method()); | ||
__log("double_value"); | ||
__log(called_method() == "double_value"); | ||
let foo = called_args::<u64>(); | ||
foo * 3 | ||
} | ||
// ANCHOR_END: fallback |