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

feat: add assert_ne and revert_with_log revert signals #1548

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env:
FUEL_CORE_PATCH_BRANCH: ""
FUEL_CORE_PATCH_REVISION: ""
RUST_VERSION: 1.79.0
FORC_VERSION: 0.66.4
FORC_VERSION: 0.66.5
FORC_PATCH_BRANCH: ""
FORC_PATCH_REVISION: ""
NEXTEST_HIDE_PROGRESS_BAR: "true"
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ fuels-macros = { version = "0.66.10", path = "./packages/fuels-macros", default-
fuels-programs = { version = "0.66.10", path = "./packages/fuels-programs", default-features = false }
fuels-test-helpers = { version = "0.66.10", path = "./packages/fuels-test-helpers", default-features = false }
versions-replacer = { version = "0.66.10", path = "./scripts/versions-replacer", default-features = false }

[patch.crates-io]
fuel-abi-types = { git = "https://github.com/FuelLabs/fuel-abi-types", branch = "hal3e/add-require-with-log-signal", package = "fuel-abi-types"}
4 changes: 2 additions & 2 deletions e2e/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ members = [
'sway/contracts/needs_custom_decoder',
'sway/contracts/payable_annotation',
'sway/contracts/proxy',
'sway/contracts/require',
'sway/contracts/revert_logs',
'sway/contracts/revert_transaction_error',
'sway/contracts/storage',
'sway/contracts/token_ops',
Expand Down Expand Up @@ -55,7 +55,7 @@ members = [
'sway/scripts/script_enum',
'sway/scripts/script_needs_custom_decoder',
'sway/scripts/script_proxy',
'sway/scripts/script_require',
'sway/scripts/script_revert_logs',
'sway/scripts/script_struct',
'sway/scripts/transfer_script',
'sway/types/contracts/b256',
Expand Down
17 changes: 15 additions & 2 deletions e2e/sway/contracts/asserts/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ impl Eq for TestEnum {

abi TestContract {
fn assert_primitive(a: u64, b: u64);

fn assert_eq_primitive(a: u64, b: u64);
fn assert_eq_struct(test_struct: TestStruct, test_struct2: TestStruct);
fn assert_eq_enum(test_enum: TestEnum, test_enum2: TestEnum);

fn assert_ne_primitive(a: u64, b: u64);
fn assert_ne_struct(test_struct: TestStruct, test_struct2: TestStruct);
fn assert_ne_enum(test_enum: TestEnum, test_enum2: TestEnum);
}

impl TestContract for Contract {
Expand All @@ -42,12 +47,20 @@ impl TestContract for Contract {
fn assert_eq_primitive(a: u64, b: u64) {
assert_eq(a, b);
}

fn assert_eq_struct(test_struct: TestStruct, test_struct2: TestStruct) {
assert_eq(test_struct, test_struct2);
}

fn assert_eq_enum(test_enum: TestEnum, test_enum2: TestEnum) {
assert_eq(test_enum, test_enum2);
}

fn assert_ne_primitive(a: u64, b: u64) {
assert_ne(a, b);
}
fn assert_ne_struct(test_struct: TestStruct, test_struct2: TestStruct) {
assert_ne(test_struct, test_struct2);
}
fn assert_ne_enum(test_enum: TestEnum, test_enum2: TestEnum) {
assert_ne(test_enum, test_enum2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "require"
name = "revert_logs"
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ abi TestContract {
fn require_string();
fn require_custom_generic();
fn require_with_additional_logs();

fn rev_w_log_primitive();
fn rev_w_log_string();
fn rev_w_log_custom_generic();
}

impl TestContract for Contract {
Expand Down Expand Up @@ -57,4 +61,28 @@ impl TestContract for Contract {
log(__to_str_array("fuel"));
require(false, 64);
}

fn rev_w_log_primitive() {
revert_with_log(42);
}

fn rev_w_log_string() {
revert_with_log(__to_str_array("fuel"));
}

fn rev_w_log_custom_generic() {
let l: [u8; 3] = [1u8, 2u8, 3u8];

let test_enum = EnumWithGeneric::VariantOne(l);
let test_struct_nested = StructWithNestedGeneric {
field_1: test_enum,
field_2: 64,
};
let test_deeply_nested_generic = StructDeeplyNestedGeneric {
field_1: test_struct_nested,
field_2: 64,
};

revert_with_log(test_deeply_nested_generic);
}
}
11 changes: 11 additions & 0 deletions e2e/sway/scripts/script_asserts/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ enum MatchEnum {
AssertEqPrimitive: (u64, u64),
AssertEqStruct: (TestStruct, TestStruct),
AssertEqEnum: (TestEnum, TestEnum),
AssertNePrimitive: (u64, u64),
AssertNeStruct: (TestStruct, TestStruct),
AssertNeEnum: (TestEnum, TestEnum),
}

fn main(match_enum: MatchEnum) {
Expand All @@ -46,5 +49,13 @@ fn main(match_enum: MatchEnum) {
} else if let MatchEnum::AssertEqEnum((test_enum, test_enum2)) = match_enum
{
assert_eq(test_enum, test_enum2);
} else if let MatchEnum::AssertNePrimitive((a, b)) = match_enum {
assert_ne(a, b);
} else if let MatchEnum::AssertNeStruct((test_struct, test_struct2)) = match_enum
{
assert_ne(test_struct, test_struct2);
} else if let MatchEnum::AssertNeEnum((test_enum, test_enum2)) = match_enum
{
assert_ne(test_enum, test_enum2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
name = "script_require"
name = "script_revert_logs"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ enum MatchEnum {
RequireString: (),
RequireCustomGeneric: (),
RequireWithAdditionalLogs: (),
RevWLogPrimitive: (),
RevWLogString: (),
RevWLogCustomGeneric: (),
}

fn main(match_enum: MatchEnum) {
Expand All @@ -51,5 +54,23 @@ fn main(match_enum: MatchEnum) {
log(42);
log(__to_str_array("fuel"));
require(false, 64);
} else if let MatchEnum::RevWLogPrimitive = match_enum {
revert_with_log(42);
} else if let MatchEnum::RevWLogString = match_enum {
revert_with_log(__to_str_array("fuel"));
} else if let MatchEnum::RevWLogCustomGeneric = match_enum {
let l: [u8; 3] = [1u8, 2u8, 3u8];

let test_enum = EnumWithGeneric::VariantOne(l);
let test_struct_nested = StructWithNestedGeneric {
field_1: test_enum,
field_2: 64,
};
let test_deeply_nested_generic = StructDeeplyNestedGeneric {
field_1: test_struct_nested,
field_2: 64,
};

revert_with_log(test_deeply_nested_generic);
}
}
2 changes: 1 addition & 1 deletion e2e/sway/types/contracts/vectors/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract;

mod data_structures;
pub mod data_structures;
mod eq_impls;
mod utils;

Expand Down
2 changes: 1 addition & 1 deletion e2e/sway/types/scripts/script_vectors/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
script;

mod data_structures;
pub mod data_structures;
mod eq_impls;
mod utils;

Expand Down
Loading
Loading