-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
276 additions
and
88 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "fuels-example-scripts" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
publish = false | ||
repository = { workspace = true } | ||
description = "Fuel Rust SDK scripts examples." | ||
|
||
[dev-dependencies] | ||
fuels = { workspace = true, features = ["default"] } | ||
tokio = { workspace = true, features = ["full"] } |
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,74 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use fuels::prelude::Result; | ||
|
||
#[tokio::test] | ||
async fn script_configurables() -> Result<()> { | ||
use fuels::{ | ||
core::codec::EncoderConfig, | ||
prelude::*, | ||
types::{Bits256, SizedAsciiString, U256}, | ||
}; | ||
|
||
// ANCHOR: script_configurables | ||
abigen!(Script( | ||
name = "MyScript", | ||
abi = "e2e/sway/scripts/script_configurables/out/release/script_configurables-abi.json" | ||
)); | ||
|
||
let wallet = launch_provider_and_get_wallet().await?; | ||
let bin_path = | ||
"../../e2e/sway/scripts/script_configurables/out/release/script_configurables.bin"; | ||
let script_instance = MyScript::new(wallet, bin_path); | ||
|
||
let str_4: SizedAsciiString<4> = "FUEL".try_into()?; | ||
let new_struct = StructWithGeneric { | ||
field_1: 16u8, | ||
field_2: 32, | ||
}; | ||
let new_enum = EnumWithGeneric::VariantTwo; | ||
|
||
let configurables = MyScriptConfigurables::new(EncoderConfig { | ||
max_tokens: 5, | ||
..Default::default() | ||
}) | ||
.with_BOOL(false)? | ||
.with_U8(7)? | ||
.with_U16(15)? | ||
.with_U32(31)? | ||
.with_U64(63)? | ||
.with_U256(U256::from(8))? | ||
.with_B256(Bits256([2; 32]))? | ||
.with_STR_4(str_4.clone())? | ||
.with_TUPLE((7, false))? | ||
.with_ARRAY([252, 253, 254])? | ||
.with_STRUCT(new_struct.clone())? | ||
.with_ENUM(new_enum.clone())?; | ||
|
||
let response = script_instance | ||
.with_configurables(configurables) | ||
.main() | ||
.call() | ||
.await?; | ||
// ANCHOR_END: script_configurables | ||
|
||
let expected_value = ( | ||
false, | ||
7, | ||
15, | ||
31, | ||
63, | ||
U256::from(8), | ||
Bits256([2; 32]), | ||
str_4, | ||
(7, false), | ||
[252, 253, 254], | ||
new_struct, | ||
new_enum, | ||
); | ||
|
||
assert_eq!(response.value, expected_value); | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.