Skip to content

Commit

Permalink
feature!: make experimental encoding deafault (#1334)
Browse files Browse the repository at this point in the history
This PR makes the experimental encoding default and adds the
`legacy_encoding` flag to use the old one.
  • Loading branch information
hal3e authored Apr 16, 2024
1 parent 3b25158 commit 81fd7f2
Show file tree
Hide file tree
Showing 34 changed files with 974 additions and 974 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
working-directory: packages/fuels

- name: Build Sway test projects
run: forc build --terse --error-on-warnings
run: forc build --terse --error-on-warnings --experimental-new-encoding
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
Expand All @@ -82,7 +82,7 @@ jobs:
# TODO: To be removed once https://github.com/FuelLabs/fuels-rs/issues/881 is unblocked.
- name: Build Sway test projects w type paths
run: forc build --terse --error-on-warnings --json-abi-with-callpaths
run: forc build --terse --error-on-warnings --json-abi-with-callpaths --experimental-new-encoding
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
Expand All @@ -99,15 +99,15 @@ jobs:
!packages/fuels/tests/**/Forc.lock
!packages/fuels/tests/.gitignore
# TODO: To be removed once experimental encoding is the default
- name: Build Sway test projects w experimental encoding
run: forc build --terse --error-on-warnings --json-abi-with-callpaths --experimental-new-encoding
# TODO: To be removed once legacy encoding is removed
- name: Build Sway test projects w legacy encoding
run: forc build --terse --error-on-warnings --json-abi-with-callpaths
working-directory: packages/fuels

- uses: actions/upload-artifact@v2
with:
retention-days: 2
name: sway-examples-w-experimental-encoding
name: sway-examples-w-legacy-encoding
# cache only the sway build artifacts, skip all src files
path: |
packages/fuels/tests
Expand Down Expand Up @@ -205,10 +205,10 @@ jobs:
args:
- command: check_typos
args:
# TODO: To be removed once experimental encoding is the default
# TODO: To be removed once legacy encoding is removed
- cargo_command: nextest
args: run --all-targets --features "experimental" --workspace --cargo-quiet
download_sway_artifacts: sway-examples-w-experimental-encoding
args: run --all-targets --features "legacy_encoding" --workspace --cargo-quiet
download_sway_artifacts: sway-examples-w-legacy-encoding
install_fuel_core: true
steps:
- name: Checkout repository
Expand Down Expand Up @@ -275,7 +275,7 @@ jobs:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
cd packages/wasm-tests
wasm-pack test --node
wasm-pack test --node --features experimental
wasm-pack test --node --features legacy_encoding
- name: Check for invalid documentation anchors
if: ${{ matrix.command == 'check_doc_anchors_valid' }}
Expand Down
2 changes: 1 addition & 1 deletion examples/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ tokio = { workspace = true, features = ["full"] }
[features]
fuel-core-lib = ["fuels/fuel-core-lib"]
rocksdb = ["fuels/rocksdb"]
experimental = ["fuels/experimental"]
legacy_encoding = ["fuels/legacy_encoding"]
12 changes: 6 additions & 6 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

let expected_gas = if cfg!(feature = "experimental") {
2065
} else {
let expected_gas = if cfg!(feature = "legacy_encoding") {
796
} else {
2065
};

assert_eq!(transaction_cost.gas_used, expected_gas);
Expand Down Expand Up @@ -614,9 +614,9 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let expected_gas = 1172;
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let expected_gas = 3532;

assert_eq!(transaction_cost.gas_used, expected_gas);
Expand Down Expand Up @@ -698,7 +698,7 @@ mod tests {
}

#[tokio::test]
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
async fn low_level_call_example() -> Result<()> {
use fuels::{
core::codec::{calldata, fn_selector},
Expand Down
2 changes: 1 addition & 1 deletion examples/debugging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ serde_json = { workspace = true }
tokio = { workspace = true, features = ["full"] }

[features]
experimental = ["fuels/experimental"]
legacy_encoding = ["fuels/legacy_encoding"]
12 changes: 6 additions & 6 deletions examples/debugging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ mod tests {
use std::collections::HashMap;

use fuel_abi_types::abi::program::ProgramABI;
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
use fuels::core::codec::{calldata, fn_selector};
use fuels::{
core::codec::ABIDecoder,
macros::abigen,
types::{errors::Result, param_types::ParamType, SizedAsciiString},
};

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn get_a_fn_selector() {
use fuels::core::{codec::resolve_fn_selector, traits::Parameterize};
Expand All @@ -27,7 +27,7 @@ mod tests {
// ANCHOR_END: example_fn_selector
}

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn a_fn_selector_from_json_abi() -> Result<()> {
use fuels::core::codec::resolve_fn_selector;
Expand Down Expand Up @@ -65,7 +65,7 @@ mod tests {
Ok(())
}

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn test_macros() -> Result<()> {
let function_selector = fn_selector!(initialize_counter(u64));
Expand Down Expand Up @@ -167,9 +167,9 @@ mod tests {

let expected_u8 = 1;

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [0, 0, 0, 0, 0, 0, 0, 1];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [1];

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ tokio = { workspace = true, features = ["test-util", "macros"] }
[features]
default = ["std"]
std = ["dep:fuel-core-client"]
experimental = []
legacy_encoding = []
4 changes: 2 additions & 2 deletions packages/fuels-core/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ mod tests {

#[test]
fn can_convert_bytes_into_tuple() -> Result<()> {
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let tuple_in_bytes: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let tuple_in_bytes: Vec<u8> = vec![0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2];

let the_tuple: (u64, u32) = try_from_bytes(&tuple_in_bytes, DecoderConfig::default())?;
Expand Down
66 changes: 33 additions & 33 deletions packages/fuels-core/src/codec/abi_decoder.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#[cfg(not(feature = "experimental"))]
#[cfg(not(feature = "legacy_encoding"))]
mod bounded_decoder;
mod decode_as_debug_str;
#[cfg(feature = "experimental")]
mod experimental_bounded_decoder;
#[cfg(feature = "legacy_encoding")]
mod legacy_bounded_decoder;

#[cfg(not(feature = "experimental"))]
#[cfg(not(feature = "legacy_encoding"))]
use crate::codec::abi_decoder::bounded_decoder::BoundedDecoder;
#[cfg(feature = "experimental")]
use crate::codec::abi_decoder::experimental_bounded_decoder::BoundedDecoder;
#[cfg(feature = "legacy_encoding")]
use crate::codec::abi_decoder::legacy_bounded_decoder::BoundedDecoder;
use crate::{
codec::abi_decoder::decode_as_debug_str::decode_as_debug_str,
types::{errors::Result, param_types::ParamType, Token},
Expand Down Expand Up @@ -138,7 +138,7 @@ mod tests {
ParamType::U256,
];

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [
255, // u8
0, 0, 0, 0, 0, 0, 255, 255, // u16
Expand All @@ -149,7 +149,7 @@ mod tests {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // u256
];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [
255, // u8
255, 255, // u16
Expand Down Expand Up @@ -207,13 +207,13 @@ mod tests {
#[test]
fn decode_string_array() -> Result<()> {
let types = vec![ParamType::StringArray(23), ParamType::StringArray(5)];
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [
84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 117, 108, 108, 32, 115, 101, 110,
116, 101, 110, 99, 101, 0, //This is a full sentence
72, 101, 108, 108, 111, 0, 0, 0, // Hello
];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [
84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 117, 108, 108, 32, 115, 101, 110,
116, 101, 110, 99, 101, //This is a full sentence
Expand All @@ -237,12 +237,12 @@ mod tests {

#[test]
fn decode_string_slice() -> Result<()> {
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [
84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 117, 108, 108, 32, 115, 101, 110,
116, 101, 110, 99, 101, //This is a full sentence
];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [
0, 0, 0, 0, 0, 0, 0, 23, // [length]
84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 117, 108, 108, 32, 115, 101, 110,
Expand All @@ -263,12 +263,12 @@ mod tests {

#[test]
fn decode_string() -> Result<()> {
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [
84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 117, 108, 108, 32, 115, 101, 110,
116, 101, 110, 99, 101, //This is a full sentence
];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [
0, 0, 0, 0, 0, 0, 0, 23, // [length]
84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 102, 117, 108, 108, 32, 115, 101, 110,
Expand All @@ -287,12 +287,12 @@ mod tests {
#[test]
fn decode_tuple() -> Result<()> {
let param_type = ParamType::Tuple(vec![ParamType::U32, ParamType::Bool]);
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [
0, 0, 0, 0, 0, 0, 0, 255, //u32
1, 0, 0, 0, 0, 0, 0, 0, //bool
];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [
0, 0, 0, 255, //u32
1, //bool
Expand Down Expand Up @@ -327,9 +327,9 @@ mod tests {
// bar: bool,
// }

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [1, 1];

let param_type = ParamType::Struct {
Expand All @@ -349,9 +349,9 @@ mod tests {

#[test]
fn decode_bytes() -> Result<()> {
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [255, 0, 1, 2, 3, 4, 5];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [0, 0, 0, 0, 0, 0, 0, 7, 255, 0, 1, 2, 3, 4, 5];

let decoded = ABIDecoder::default().decode(&ParamType::Bytes, &data)?;
Expand All @@ -365,9 +365,9 @@ mod tests {

#[test]
fn decode_raw_slice() -> Result<()> {
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [255, 0, 1, 2, 3, 4, 5];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [0, 0, 0, 0, 0, 0, 0, 7, 255, 0, 1, 2, 3, 4, 5];

let decoded = ABIDecoder::default().decode(&ParamType::RawSlice, &data)?;
Expand Down Expand Up @@ -395,9 +395,9 @@ mod tests {
}];

// "0" discriminant and 42 enum value
#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42];

let decoded = ABIDecoder::default().decode_multiple(&types, &data)?;
Expand All @@ -408,7 +408,7 @@ mod tests {
Ok(())
}

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn decoder_will_skip_enum_padding_and_decode_next_arg() -> Result<()> {
// struct MyStruct {
Expand Down Expand Up @@ -493,11 +493,11 @@ mod tests {
generics: vec![],
};

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let data = [
0, 0, 0, 0, 0, 0, 0, 10, 1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0,
];
#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let data = [0, 10, 1, 1, 2];

let decoded = ABIDecoder::default().decode(&nested_struct, &data)?;
Expand Down Expand Up @@ -552,7 +552,7 @@ mod tests {

let types = [nested_struct, u8_arr, b256];

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
let bytes = [
0, 0, 0, 0, 0, 0, 0, 10, // u16
1, 0, 0, 0, 0, 0, 0, 0, // bool
Expand All @@ -562,7 +562,7 @@ mod tests {
152, 244, 172, 69, 123, 168, 248, 39, 67, 243, 30, 147, 11, // b256
];

#[cfg(feature = "experimental")]
#[cfg(not(feature = "legacy_encoding"))]
let bytes = [
0, 10, // u16
1, // bool
Expand Down Expand Up @@ -597,7 +597,7 @@ mod tests {
Ok(())
}

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn units_in_structs_are_decoded_as_one_word() -> Result<()> {
let data = [
Expand Down Expand Up @@ -734,7 +734,7 @@ mod tests {
assert!(matches!(result, Err(Error::Codec(_))));
}

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn decoding_enum_with_more_than_one_heap_type_variant_fails() -> Result<()> {
let mut param_types = vec![
Expand Down Expand Up @@ -774,7 +774,7 @@ mod tests {
Ok(())
}

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn enums_w_too_deeply_nested_heap_types_not_allowed() {
let variants = to_named(&[
Expand Down Expand Up @@ -892,7 +892,7 @@ mod tests {
}
}

#[cfg(not(feature = "experimental"))]
#[cfg(feature = "legacy_encoding")]
#[test]
fn vectors_of_zst_are_not_supported() {
let param_type = ParamType::Vector(Box::new(ParamType::StringArray(0)));
Expand Down
Loading

0 comments on commit 81fd7f2

Please sign in to comment.