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

chore: add blob script deploy stress test #3270

Merged
merged 6 commits into from
Oct 7, 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
4 changes: 4 additions & 0 deletions .changeset/itchy-schools-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: add blob script deploy stress test
71 changes: 71 additions & 0 deletions packages/fuel-gauge/src/blob-deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ScriptMainArgBool,
PredicateTrue,
PredicateWithMoreConfigurables,
ScriptWithMoreConfigurable,
} from '../test/typegen';

/**
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
license = "Apache-2.0"
name = "script-with-more-configurable"

[dependencies]
Original file line number Diff line number Diff line change
@@ -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
}