Skip to content

Commit

Permalink
fix: forc-test log decoding in libraries (#6518)
Browse files Browse the repository at this point in the history
## Description

Closes #6468

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
  • Loading branch information
sdankel and JoshuaBatty committed Sep 11, 2024
1 parent 5699721 commit 7d574a9
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 15 deletions.
29 changes: 18 additions & 11 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,24 @@ pub fn generate_program_abi(
configurables: Some(configurables),
}
}
TyProgramKind::Library { .. } => program_abi::ProgramABI {
program_type: "library".to_string(),
spec_version,
encoding_version,
metadata_types: vec![],
concrete_types: vec![],
functions: vec![],
logged_types: None,
messages_types: None,
configurables: None,
},
TyProgramKind::Library { .. } => {
let logged_types =
generate_logged_types(handler, ctx, engines, metadata_types, concrete_types)?;
let messages_types =
generate_messages_types(handler, ctx, engines, metadata_types, concrete_types)?;

program_abi::ProgramABI {
program_type: "library".to_string(),
spec_version,
encoding_version,
metadata_types: metadata_types.to_vec(),
concrete_types: concrete_types.to_vec(),
functions: vec![],
logged_types: Some(logged_types),
messages_types: Some(messages_types),
configurables: None,
}
}
};

standardize_json_abi_types(&mut program_abi);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[[package]]
name = "core"
source = "path+from-root-A2C6CB9CD0980A06"
source = "path+from-root-A1A671B3B44F9A9A"

[[package]]
name = "log_decode"
name = "lib_log_decode"
source = "member"
dependencies = ["std"]

[[package]]
name = "std"
source = "path+from-root-A2C6CB9CD0980A06"
source = "path+from-root-A1A671B3B44F9A9A"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "lib.sw"
license = "Apache-2.0"
name = "lib_log_decode"

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
library;

use std::flags::disable_panic_on_overflow;

#[test]
fn test_fn() {
let a = 10;
log(a);
let b = 30;
log(b);
assert_eq(a, 10)
}

#[test]
fn math_u16_overflow_mul() {
disable_panic_on_overflow();

let a = (u16::max() / 2 ) + 1;
let b = a * 2;

log(b);
assert(b == 0_u16)
}

#[test]
fn math_u32_overflow_mul() {
disable_panic_on_overflow();

let a = (u32::max() / 2 ) + 1;
let b = a * 2;

log(b);
assert(b == 0_u32)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
category = "unit_tests_pass"
expected_decoded_test_logs = ["10", "30", "0", "0"]
experimental_new_encoding = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = "core"
source = "path+from-root-2988E4B52C5E1B31"

[[package]]
name = "script_log_decode"
source = "member"
dependencies = ["std"]

[[package]]
name = "std"
source = "path+from-root-2988E4B52C5E1B31"
dependencies = ["core"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "log_decode"
name = "script_log_decode"

[dependencies]
std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" }

0 comments on commit 7d574a9

Please sign in to comment.