Skip to content

feat!: add support for abi errors #1651

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

Merged
merged 17 commits into from
May 13, 2025
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
FUEL_CORE_PATCH_REVISION: ""
RUST_VERSION: 1.85.0
FORC_VERSION: 0.68.0
FORC_PATCH_BRANCH: ""
FORC_PATCH_BRANCH: "ironcev/error-codes-in-abi-json"
FORC_PATCH_REVISION: ""
NEXTEST_HIDE_PROGRESS_BAR: "true"
NEXTEST_STATUS_LEVEL: "fail"
Expand Down Expand Up @@ -60,10 +60,10 @@ jobs:
fi

- name: Check format of Sway test projects
run: forc fmt --check --path e2e
run: forc fmt --check --path e2e --experimental error_type

- name: Build Sway test projects
run: forc build --release --terse --error-on-warnings --path e2e
run: forc build --release --terse --error-on-warnings --path e2e --experimental error_type

- uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cynic = { version = "3.1.0", default-features = false }
test-case = { version = "3.3", default-features = false }
eth-keystore = "0.5.0"
flate2 = { version = "1.0", default-features = false }
fuel-abi-types = "0.8.0"
fuel-abi-types = "0.12.0"
futures = "0.3.29"
hex = { version = "0.4.3", default-features = false }
itertools = "0.12.0"
Expand Down
7 changes: 5 additions & 2 deletions e2e/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ members = [
'sway/contracts/needs_custom_decoder',
'sway/contracts/payable_annotation',
'sway/contracts/proxy',
'sway/contracts/revert_logs',
'sway/contracts/revert_transaction_error',
'sway/contracts/storage',
'sway/contracts/token_ops',
Expand All @@ -33,9 +32,11 @@ members = [
'sway/contracts/var_outputs',
'sway/logs/contract_logs',
'sway/logs/contract_logs_abi',
'sway/logs/contract_revert_logs',
'sway/logs/contract_with_contract_logs',
'sway/logs/script_heap_logs',
'sway/logs/script_logs',
'sway/logs/script_revert_logs',
'sway/logs/script_with_contract_logs',
'sway/predicates/basic_predicate',
'sway/predicates/predicate_blobs',
Expand All @@ -56,7 +57,6 @@ members = [
'sway/scripts/script_enum',
'sway/scripts/script_needs_custom_decoder',
'sway/scripts/script_proxy',
'sway/scripts/script_revert_logs',
'sway/scripts/script_struct',
'sway/scripts/script_tx_input_output',
'sway/scripts/transfer_script',
Expand Down Expand Up @@ -118,3 +118,6 @@ members = [
'sway/types/scripts/script_u256',
'sway/types/scripts/script_vectors',
]

[patch.'https://github.com/fuellabs/sway']
std = { git = "https://github.com/fuellabs/sway", branch = "ironcev/error-codes-in-abi-json" }
24 changes: 24 additions & 0 deletions e2e/sway/logs/contract_logs/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ contract;
use std::{logging::log, string::String};
use contract_logs_abi::ContractLogs;

struct B {
id: u64,
val: u64,
}

#[error_type]
enum MyError {
#[error(m = "some error A")]
A: (),
#[error(m = "some complex error B")]
B: B,
}

#[allow(dead_code)]
struct TestStruct {
field_1: bool,
Expand Down Expand Up @@ -178,4 +191,15 @@ impl ContractLogs for Contract {

log(v3);
}

fn produce_panic() {
panic "some panic message";
}

fn produce_panic_with_error() {
panic MyError::B(B {
id: 42,
val: 36,
});
}
}
3 changes: 3 additions & 0 deletions e2e/sway/logs/contract_logs_abi/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ abi ContractLogs {
fn produce_bytes_log();
fn produce_raw_slice_log();
fn produce_vec_log();

fn produce_panic();
fn produce_panic_with_error();
}
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 = "revert_logs"
name = "contract_revert_logs"
14 changes: 14 additions & 0 deletions e2e/sway/logs/contract_with_contract_logs/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use library::ContractLogs;

abi ContractCaller {
fn logs_from_external_contract(contract_id: ContractId) -> ();
fn panic_from_external_contract(contract_id: ContractId) -> ();
fn panic_error_from_external_contract(contract_id: ContractId) -> ();
}

impl ContractCaller for Contract {
Expand All @@ -13,4 +15,16 @@ impl ContractCaller for Contract {
let contract_instance = abi(ContractLogs, contract_id.into());
contract_instance.produce_logs_values();
}

fn panic_from_external_contract(contract_id: ContractId) {
// Call contract with `contract_id` and make some logs
let contract_instance = abi(ContractLogs, contract_id.into());
contract_instance.produce_panic();
}

fn panic_error_from_external_contract(contract_id: ContractId) {
// Call contract with `contract_id` and make some logs
let contract_instance = abi(ContractLogs, contract_id.into());
contract_instance.produce_panic_with_error();
}
}
96 changes: 96 additions & 0 deletions e2e/sway/logs/script_revert_logs/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
script;

use std::logging::log;

#[allow(dead_code)]
enum EnumWithGeneric<D> {
VariantOne: D,
VariantTwo: (),
}

#[allow(dead_code)]
struct StructWithNestedGeneric<D> {
field_1: D,
field_2: u64,
}

#[allow(dead_code)]
struct StructDeeplyNestedGeneric<D> {
field_1: D,
field_2: u64,
}

struct B {
id: u64,
val: u64,
}

#[error_type]
enum MyError {
#[error(m = "some error A")]
A: (),
#[error(m = "some complex error B")]
B: B,
}

#[allow(dead_code)]
enum MatchEnum {
RequirePrimitive: (),
RequireString: (),
RequireCustomGeneric: (),
RequireWithAdditionalLogs: (),
RevWLogPrimitive: (),
RevWLogString: (),
RevWLogCustomGeneric: (),
Panic: (),
PanicError: (),
}

fn main(match_enum: MatchEnum) {
match match_enum {
MatchEnum::RequirePrimitive => require(false, 42),
MatchEnum::RequireString => require(false, __to_str_array("fuel")),
MatchEnum::RequireCustomGeneric => {
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,
};

require(false, test_deeply_nested_generic);
}
MatchEnum::RequireWithAdditionalLogs => {
log(42);
log(__to_str_array("fuel"));
require(false, 64);
}
MatchEnum::RevWLogPrimitive => revert_with_log(42),
MatchEnum::RevWLogString => revert_with_log(__to_str_array("fuel")),
MatchEnum::RevWLogCustomGeneric => {
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);
}
MatchEnum::Panic => panic "some panic message",
MatchEnum::PanicError => panic MyError::B(B {
id: 42,
val: 36,
}),
}
}
38 changes: 27 additions & 11 deletions e2e/sway/logs/script_with_contract_logs/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@ script;
use std::logging::log;
use library::ContractLogs;

fn main(contract_id: ContractId) {
// Call contract with `contract_id` and make some logs
#[allow(dead_code)]
enum MatchEnum {
Logs: (),
Panic: (),
PanicError: (),
}

fn main(contract_id: ContractId, match_enum: MatchEnum) {
let contract_instance = abi(ContractLogs, contract_id.into());
contract_instance.produce_logs_values();
match match_enum {
MatchEnum::Logs => {
contract_instance.produce_logs_values();

let f: bool = true;
let u: u64 = 42;
let e: str[4] = __to_str_array("Fuel");
let l: [u8; 3] = [1u8, 2u8, 3u8];
log(f);
log(u);
log(e);
log(l);
let f: bool = true;
let u: u64 = 42;
let e: str[4] = __to_str_array("Fuel");
let l: [u8; 3] = [1u8, 2u8, 3u8];
log(f);
log(u);
log(e);
log(l);
}
MatchEnum::Panic => {
contract_instance.produce_panic();
}
MatchEnum::PanicError => {
contract_instance.produce_panic_with_error();
}
}
}
76 changes: 0 additions & 76 deletions e2e/sway/scripts/script_revert_logs/src/main.sw

This file was deleted.

Loading
Loading