mirror of
https://github.com/FuelLabs/sway.git
synced 2025-08-18 17:41:07 +00:00

## Description ## Checklist - [ ] I have linked to any relevant issues. - [ ] 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. - [ ] 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.
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
use fuels::prelude::*;
|
|
|
|
// Load abi from json
|
|
abigen!(Script(
|
|
name = "MyScript",
|
|
abi = "out/debug/{{project-name}}-abi.json"
|
|
));
|
|
|
|
async fn get_script_instance() -> MyScript<WalletUnlocked> {
|
|
// Launch a local network
|
|
let wallets = launch_custom_provider_and_get_wallets(
|
|
WalletsConfig::new(
|
|
Some(1), /* Single wallet */
|
|
Some(1), /* Single coin (UTXO) */
|
|
Some(1_000_000_000), /* Amount per coin */
|
|
),
|
|
None,
|
|
None,
|
|
)
|
|
.await;
|
|
let wallet = wallets.unwrap().pop().unwrap();
|
|
|
|
let bin_path = "./out/debug/{{project-name}}.bin";
|
|
|
|
let instance = MyScript::new(wallet.clone(), bin_path);
|
|
|
|
instance
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn can_get_script_instance() {
|
|
const LUCKY_NUMBER: u64 = 777;
|
|
let configurables = MyScriptConfigurables::default().with_SECRET_NUMBER(LUCKY_NUMBER.clone()).unwrap();
|
|
|
|
let instance = get_script_instance().await;
|
|
|
|
// Now you have an instance of your script
|
|
let response = instance.with_configurables(configurables).main().call().await.unwrap();
|
|
|
|
assert_eq!(response.value, LUCKY_NUMBER);
|
|
|
|
// You can print logs from scripts to debug
|
|
let logs = response.decode_logs();
|
|
println!("{:?}", logs);
|
|
}
|