Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof that #6324 is not a bug. #6573

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/src/sdk-harness/Forc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,21 @@ name = "run_external_proxy"
source = "member"
dependencies = ["std"]

[[package]]
name = "run_external_proxy_with_storage"
source = "member"
dependencies = ["std"]

[[package]]
name = "run_external_target"
source = "member"
dependencies = ["std"]

[[package]]
name = "run_external_target_with_storage"
source = "member"
dependencies = ["std"]

[[package]]
name = "script_bytecode"
source = "member"
Expand Down
2 changes: 2 additions & 0 deletions test/src/sdk-harness/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ members = [
"test_projects/result_option_expect",
"test_projects/run_external_proxy",
"test_projects/run_external_target",
"test_projects/run_external_proxy_with_storage",
"test_projects/run_external_target_with_storage",
"test_projects/script_bytecode",
"test_projects/script_data",
"test_projects/storage",
Expand Down
1 change: 1 addition & 0 deletions test/src/sdk-harness/test_projects/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod registers;
mod result_in_abi;
mod result_option_expect;
mod run_external_proxy;
mod run_external_proxy_with_storage;
mod script_data;
mod storage;
mod storage_access;
Expand Down
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']
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "run_external_proxy_with_storage"

[dependencies]
std = { path = "../../../../../sway-lib-std" }
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);
}
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
}
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']
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "run_external_target_with_storage"

[dependencies]
std = { path = "../../../../../sway-lib-std" }
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
Loading