From aff51f166441dfd978bc7f10dada337f917dbe0b Mon Sep 17 00:00:00 2001 From: MujkicA <32431923+MujkicA@users.noreply.github.com> Date: Sat, 4 May 2024 14:05:34 +0200 Subject: [PATCH] chore: add echo string test (#1341) Adds a test that echoes a string from a contract and confirms the gas usage is normal --- .../tests/types/contracts/std_lib_string/src/main.sw | 5 +++++ packages/fuels/tests/types_contracts.rs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/fuels/tests/types/contracts/std_lib_string/src/main.sw b/packages/fuels/tests/types/contracts/std_lib_string/src/main.sw index fc9cea9152..ff1694a781 100644 --- a/packages/fuels/tests/types/contracts/std_lib_string/src/main.sw +++ b/packages/fuels/tests/types/contracts/std_lib_string/src/main.sw @@ -7,6 +7,7 @@ use std::bytes::Bytes; abi MyContract { fn return_dynamic_string() -> String; fn accepts_dynamic_string(s: String); + fn echoes_dynamic_string(s: String) -> String; } impl MyContract for Contract { @@ -17,4 +18,8 @@ impl MyContract for Contract { fn accepts_dynamic_string(string: String) { assert_eq(string, String::from_ascii_str("Hello World")); } + + fn echoes_dynamic_string(string: String) -> String { + string + } } diff --git a/packages/fuels/tests/types_contracts.rs b/packages/fuels/tests/types_contracts.rs index 7634db8a2a..b975a8a403 100644 --- a/packages/fuels/tests/types_contracts.rs +++ b/packages/fuels/tests/types_contracts.rs @@ -2071,6 +2071,14 @@ async fn test_contract_std_lib_string() -> Result<()> { .call() .await?; } + { + // confirm encoding/decoding a string wasn't faulty and led to too high gas consumption + let _resp = contract_methods + .echoes_dynamic_string(String::from("Hello Fuel")) + .with_tx_policies(TxPolicies::default().with_script_gas_limit(2000)) + .call() + .await?; + } Ok(()) }