forked from FuelLabs/fuels-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…uelLabs#1275) * prep new bytes * add setup * fix test * refactor * adjust * tests * improve tests * aDJUST * refactor * add tests * refactor * adjust * adjust * fix length * correct reference * refactor * twenty eagles lick? * adjust * fix post rename * catch magic revert number * fix mapper * add sway projects * add predicate bytes test * add predicate raw slice tests * add bytes and raw slice sway projects * add bytes test for script * add test for raw slice in script input * fix: linting warning * adjust * convert errors * cs * cs * pretty * fix prettier and lint post merge * fix assertions * revise * add additional coverage on input validation --------- Co-authored-by: Nedim Salkić <[email protected]>
- Loading branch information
Showing
10 changed files
with
188 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
--- | ||
|
||
Add tests for Bytes and RawSlice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/fuel-gauge/fixtures/forc-projects/script-bytes/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[project] | ||
authors = ["FuelLabs"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "script-bytes" | ||
|
||
[dependencies] |
37 changes: 37 additions & 0 deletions
37
packages/fuel-gauge/fixtures/forc-projects/script-bytes/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
script; | ||
|
||
use std::bytes::Bytes; | ||
|
||
#[allow(dead_code)] | ||
enum SomeEnum<T> { | ||
First: bool, | ||
Second: T, | ||
} | ||
|
||
struct Wrapper<T> { | ||
inner: T, | ||
inner_enum: SomeEnum<Bytes>, | ||
} | ||
|
||
fn expected_bytes() -> Bytes { | ||
let mut bytes = Bytes::new(); | ||
|
||
bytes.push(40u8); | ||
bytes.push(41u8); | ||
bytes.push(42u8); | ||
|
||
bytes | ||
} | ||
|
||
fn main(_arg: u64, wrapper: Wrapper<Vec<Bytes>>) { | ||
if let SomeEnum::Second(enum_bytes) = wrapper.inner_enum { | ||
require(enum_bytes == expected_bytes(), "wrapper.inner_enum didn't carry the expected bytes") | ||
} else { | ||
require(false, "enum was not of variant Second"); | ||
} | ||
|
||
let inner_vec = wrapper.inner; | ||
require(inner_vec.len() == 2, "Expected wrapper.inner vector to have 2 elements"); | ||
require(inner_vec.get(0).unwrap() == expected_bytes(), "wrapper.inner[0] didn't match expectation"); | ||
require(inner_vec.get(1).unwrap() == expected_bytes(), "wrapper.inner[1] didn't match expectation"); | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/fuel-gauge/fixtures/forc-projects/script-raw-slice/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[project] | ||
authors = ["FuelLabs"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "script-raw-slice" | ||
|
||
[dependencies] |
44 changes: 44 additions & 0 deletions
44
packages/fuel-gauge/fixtures/forc-projects/script-raw-slice/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
script; | ||
|
||
#[allow(dead_code)] | ||
enum SomeEnum<T> { | ||
First: bool, | ||
Second: T, | ||
} | ||
|
||
struct Wrapper<T> { | ||
inner: T, | ||
inner_enum: SomeEnum<raw_slice>, | ||
} | ||
|
||
fn validate_raw_slice(input: raw_slice) { | ||
let vec: Vec<u64> = Vec::from(input); | ||
require(vec.len() == 3, "raw slice len is not 3"); | ||
require(vec.get(2).unwrap() == 42, "expected 3rd slice entry to be 42"); | ||
require(vec.get(1).unwrap() == 41, "expected 2nd slice entry to be 41"); | ||
require(vec.get(0).unwrap() == 40, "expected 1st slice entry to be 40"); | ||
} | ||
|
||
fn validate_vec(vec: Vec<raw_slice>) { | ||
require(vec.len() == 2, "vec should have two elements"); | ||
validate_raw_slice(vec.get(0).unwrap()); | ||
validate_raw_slice(vec.get(1).unwrap()); | ||
} | ||
|
||
fn main(_arg: u64, wrapper: Wrapper<Vec<raw_slice>>) -> raw_slice { | ||
if let SomeEnum::Second(enum_raw_slice) = wrapper.inner_enum | ||
{ | ||
validate_raw_slice(enum_raw_slice); | ||
} else { | ||
require(false, "enum was not of variant Second"); | ||
} | ||
|
||
validate_vec(wrapper.inner); | ||
|
||
let mut rtn: Vec<u64> = Vec::new(); | ||
rtn.push(1); | ||
rtn.push(2); | ||
rtn.push(3); | ||
|
||
rtn.as_raw_slice() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters