diff --git a/.changeset/itchy-schools-bathe.md b/.changeset/itchy-schools-bathe.md new file mode 100644 index 00000000000..bd2c800a6fa --- /dev/null +++ b/.changeset/itchy-schools-bathe.md @@ -0,0 +1,4 @@ +--- +--- + +chore: add blob script deploy stress test diff --git a/packages/fuel-gauge/src/blob-deploy.test.ts b/packages/fuel-gauge/src/blob-deploy.test.ts index df8a682e81c..d9160eb5312 100644 --- a/packages/fuel-gauge/src/blob-deploy.test.ts +++ b/packages/fuel-gauge/src/blob-deploy.test.ts @@ -8,6 +8,7 @@ import { ScriptMainArgBool, PredicateTrue, PredicateWithMoreConfigurables, + ScriptWithMoreConfigurable, } from '../test/typegen'; /** @@ -170,6 +171,76 @@ describe('first try', () => { expect(value).toBe(false); }); + it('should set configurables in complicated script', async () => { + using launch = await launchTestNode(); + + const { + wallets: [wallet], + } = launch; + + const factory = new ContractFactory( + ScriptWithMoreConfigurable.bytecode, + ScriptWithMoreConfigurable.abi, + wallet + ); + const { waitForResult } = await factory.deployAsBlobTxForScript(); + const { loaderBytecode, configurableOffsetDiff } = await waitForResult(); + + const configurable = { + U8: 16, + U16: 201, + U32: 1001, + U64: 99999999, + BOOL: false, + B256: '0x314fa58689bbe1da2430517de2d772b384a1c1d2e9cb87e73c6afcf246045b10', + ENUM: 'blue', + ARRAY: [ + [101, 99], + [123, 456], + ], + STR_4: 'leuf', + TUPLE: [67, true, 'hu'], + STRUCT_1: { + tag: '909', + age: 15, + scores: [9, 2, 1], + }, + }; + + const normalScript = new Script( + ScriptWithMoreConfigurable.bytecode, + ScriptWithMoreConfigurable.abi, + wallet + ); + + normalScript.setConfigurableConstants(configurable); + + const script = new Script( + loaderBytecode, + mapToLoaderAbi(ScriptWithMoreConfigurable.abi, configurableOffsetDiff), + wallet + ); + + script.setConfigurableConstants(configurable); + + const { waitForResult: waitForResult2 } = await script.functions.main().call(); + const { value, logs } = await waitForResult2(); + + expect(value).toBeTruthy(); + + expect(logs[0]).equal(configurable.U8); + expect(logs[1]).equal(configurable.U16); + expect(logs[2]).equal(configurable.U32); + expect(logs[3].toNumber()).equal(configurable.U64); + expect(logs[4]).equal(configurable.BOOL); + expect(logs[5]).equal(configurable.B256); + expect(logs[6]).equal(configurable.ENUM); + expect(logs[7]).toStrictEqual(configurable.ARRAY); + expect(logs[8]).equal(configurable.STR_4); + expect(logs[9]).toStrictEqual(configurable.TUPLE); + expect(logs[10]).toStrictEqual(configurable.STRUCT_1); + }); + it('Should work with predicates', async () => { using launch = await launchTestNode(); const { diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml index e1837da3cbc..bb2f195d352 100644 --- a/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml +++ b/packages/fuel-gauge/test/fixtures/forc-projects/Forc.toml @@ -61,6 +61,7 @@ members = [ "script-str-slice", "script-with-array", "script-with-configurable", + "script-with-more-configurable", "script-with-vector", "script-with-options", "script-with-vector-advanced", diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/script-with-more-configurable/Forc.toml b/packages/fuel-gauge/test/fixtures/forc-projects/script-with-more-configurable/Forc.toml new file mode 100644 index 00000000000..c290e1b982d --- /dev/null +++ b/packages/fuel-gauge/test/fixtures/forc-projects/script-with-more-configurable/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "script-with-more-configurable" + +[dependencies] diff --git a/packages/fuel-gauge/test/fixtures/forc-projects/script-with-more-configurable/src/main.sw b/packages/fuel-gauge/test/fixtures/forc-projects/script-with-more-configurable/src/main.sw new file mode 100644 index 00000000000..0ca4258e98c --- /dev/null +++ b/packages/fuel-gauge/test/fixtures/forc-projects/script-with-more-configurable/src/main.sw @@ -0,0 +1,123 @@ +script; + +use std::{string::String,}; + +struct Struct1 { + tag: str[3], + age: u8, + scores: [u8; 3], +} + +enum Colors { + red: (), + blue: (), +} + +impl Eq for [u32; 2] { + fn eq(self, other: Self) -> bool { + self[0] == other[0] && self[1] == other[1] + } +} + +impl Eq for [u8; 3] { + fn eq(self, other: Self) -> bool { + self[0] == other[0] && self[1] == other[1] && self[2] == other[2] + } +} + +impl Eq for [[u32; 2]; 2] { + fn eq(self, other: Self) -> bool { + self[0] == other[0] && self[1] == other[1] + } +} + +impl Eq for str[2] { + fn eq(self, other: Self) -> bool { + from_str_array(self) == from_str_array(other) + } +} + +impl Eq for str[3] { + fn eq(self, other: Self) -> bool { + from_str_array(self) == from_str_array(other) + } +} + +impl Eq for str[4] { + fn eq(self, other: Self) -> bool { + from_str_array(self) == from_str_array(other) + } +} + +impl Eq for (u8, bool, str[2]) { + fn eq(self, other: Self) -> bool { + self.0 == other.0 && self.1 == other.1 && self.2 == other.2 + } +} + +impl Eq for Struct1 { + fn eq(self, other: Self) -> bool { + self.tag == other.tag && self.age == other.age && self.scores == other.scores + } +} + +impl Eq for Colors { + fn eq(self, other: Self) -> bool { + match (self, other) { + (Colors::red, Colors::red) => true, + (Colors::blue, Colors::blue) => true, + _ => false, + } + } +} + +configurable { + U8: u8 = 10, + U16: u16 = 301u16, + U32: u32 = 799u32, + U64: u64 = 100000, + BOOL: bool = true, + B256: b256 = 0x1d6ebd57dd6a8d7e90889c8c7388f22c30d5c3556080a2b6dc4c521092a0b942, + ENUM: Colors = Colors::red, + ARRAY: [[u32; 2]; 2] = [[253u32, 254u32], [255u32, 256u32]], + STR_4: str[4] = __to_str_array("fuel"), + TUPLE: (u8, bool, str[2]) = (12, false, __to_str_array("hi")), + STRUCT_1: Struct1 = Struct1 { + tag: __to_str_array("000"), + age: 21, + scores: [1, 3, 4], + }, +} + +fn main() -> bool { + assert(U8 == 16); + log(U8); + assert(U16 == 201u16); + log(U16); + assert(U32 == 1001u32); + log(U32); + assert(U64 == 99999999); + log(U64); + assert(BOOL == false); + log(BOOL); + assert(B256 == 0x314fa58689bbe1da2430517de2d772b384a1c1d2e9cb87e73c6afcf246045b10); + log(B256); + assert(ENUM == Colors::blue); + log(ENUM); + assert(ARRAY == [[101u32, 99u32], [123u32, 456u32]]); + log(ARRAY); + assert(from_str_array((STR_4)) == "leuf"); + log(STR_4); + assert(TUPLE == (67, true, __to_str_array("hu"))); + log(TUPLE); + assert( + STRUCT_1 == Struct1 { + tag: __to_str_array("909"), + age: 15, + scores: [9, 2, 1], + }, + ); + log(STRUCT_1); + + true +}