Skip to content

Commit

Permalink
chore: use #[allow(dead_code)] in forc projects (FuelLabs#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e committed Jun 9, 2023
1 parent f41dd3a commit 09ebbef
Show file tree
Hide file tree
Showing 51 changed files with 171 additions and 114 deletions.
4 changes: 2 additions & 2 deletions packages/fuels/tests/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 32,7 @@ async fn compile_bindings_from_contract_file() {

let call_handler = simple_contract_instance
.methods()
.takes_ints_returns_bool(42);
.takes_int_returns_bool(42);

let encoded_args = call_handler.contract_call.encoded_args.resolve(0);
let encoded = format!(
Expand All @@ -41,7 41,7 @@ async fn compile_bindings_from_contract_file() {
hex::encode(encoded_args)
);

assert_eq!("000000009593586c000000000000002a", encoded);
assert_eq!("000000005f68ee3d000000000000002a", encoded);
}

#[tokio::test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 9,7 @@ struct StructSameNameButDifferentInternals {
a: u32,
}

#[allow(dead_code)]
enum EnumSameNameButDifferentInternals {
a: u32,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 9,7 @@ struct StructSameNameButDifferentInternals {
a: [u64; 1],
}

#[allow(dead_code)]
enum EnumSameNameButDifferentInternals {
a: [u64; 1],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 9,7 @@ pub struct SharedStruct2<K> {
b: SharedStruct1<K>,
}

#[allow(dead_code)]
pub enum SharedEnum<L> {
a: u64,
b: SharedStruct2<L>,
Expand Down
6 changes: 3 additions & 3 deletions packages/fuels/tests/bindings/simple_contract/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,11 1,11 @@
contract;

abi MyContract {
fn takes_ints_returns_bool(only_argument: u32) -> bool;
fn takes_int_returns_bool(arg: u32) -> bool;
}

impl MyContract for Contract {
fn takes_ints_returns_bool(only_argument: u32) -> bool {
true
fn takes_int_returns_bool(arg: u32) -> bool {
arg == 32u32
}
}
2 changes: 1 addition & 1 deletion packages/fuels/tests/bindings/type_paths/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 11,7 @@ abi MyContract {
}

impl MyContract for Contract {
fn test_function(arg: AWrapper) -> VeryCommonNameStruct {
fn test_function(_arg: AWrapper) -> VeryCommonNameStruct {
VeryCommonNameStruct { field_a: 10u32 }
}
}
12 changes: 6 additions & 6 deletions packages/fuels/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 29,7 @@ async fn test_multiple_args() -> Result<()> {
let contract_methods = contract_instance.methods();
let response = contract_methods.get(5, 6).call().await?;

assert_eq!(response.value, 5);
assert_eq!(response.value, 11);

let t = MyType { x: 5, y: 6 };
let response = contract_methods.get_alt(t.clone()).call().await?;
Expand Down Expand Up @@ -162,11 162,11 @@ async fn test_multiple_read_calls() -> Result<()> {
// Use "simulate" because the methods don't actually run a transaction, but just a dry-run
// We can notice here that, thanks to this, we don't generate a TransactionId collision,
// even if the transactions are theoretically the same.
let stored = contract_methods.read(0).simulate().await?;
let stored = contract_methods.read().simulate().await?;

assert_eq!(stored.value, 42);

let stored = contract_methods.read(0).simulate().await?;
let stored = contract_methods.read().simulate().await?;

assert_eq!(stored.value, 42);
Ok(())
Expand Down Expand Up @@ -1001,7 1001,7 @@ async fn test_output_variable_contract_id_estimation_multicall() -> Result<()> {
.call::<(u64, u64, u64, u64)>()
.await?;

assert_eq!(call_response.value, (43, 43, 43, 5));
assert_eq!(call_response.value, (43, 43, 43, 11));

Ok(())
}
Expand Down Expand Up @@ -1043,7 1043,7 @@ async fn test_contract_call_with_non_default_max_input() -> Result<()> {

let response = contract_instance.methods().get(5, 6).call().await?;

assert_eq!(response.value, 5);
assert_eq!(response.value, 11);

Ok(())
}
Expand Down Expand Up @@ -1101,7 1101,7 @@ async fn test_add_custom_assets() -> Result<()> {
.call()
.await?;

assert_eq!(response.value, 5);
assert_eq!(response.value, 11);

let balance_asset_1 = wallet_1.get_asset_balance(&asset_id_1).await?;
let balance_asset_2 = wallet_1.get_asset_balance(&asset_id_2).await?;
Expand Down
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/asserts/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@ struct TestStruct {
field_2: u64,
}

#[allow(dead_code)]
enum TestEnum {
VariantOne: (),
VariantTwo: (),
Expand Down
1 change: 1 addition & 0 deletions packages/fuels/tests/contracts/configurables/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,5 1,6 @@
contract;

#[allow(dead_code)]
enum EnumWithGeneric<D> {
VariantOne: D,
VariantTwo: (),
Expand Down
4 changes: 3 additions & 1 deletion packages/fuels/tests/contracts/contract_test/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 8,12 @@ struct MyType {
y: u64,
}

#[allow(dead_code)]
struct Person {
name: str[4],
}

#[allow(dead_code)]
enum State {
A: (),
B: (),
Expand Down Expand Up @@ -107,7 109,7 @@ impl TestContract for Contract {
}

fn get(x: u64, y: u64) -> u64 {
x
x y
}

fn get_alt(t: MyType) -> MyType {
Expand Down
8 changes: 4 additions & 4 deletions packages/fuels/tests/contracts/large_return_data/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 35,18 @@ impl TestContract for Contract {
}

fn get_small_struct() -> SmallStruct {
SmallStruct { foo: 100 }
SmallStruct { foo: 100u32 }
}

fn get_large_struct() -> LargeStruct {
LargeStruct {
foo: 12,
bar: 42,
foo: 12u8,
bar: 42u8,
}
}

fn get_large_array() -> [u32; 2] {
let x: [u32; 2] = [1, 2];
let x: [u32; 2] = [1u32, 2u32];
x
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 25,12 @@ impl ContractCaller for Contract {
let contract_instance = abi(LibContract, contract_id.into());
let contract_instance2 = abi(LibContract, contract_id2.into());

contract_instance.increment(value) contract_instance.increment(value)
contract_instance.increment(value) contract_instance2.increment(value)
}

fn increment_from_contract_then_mint(contract_id: ContractId, amount: u64, address: Address) {
let contract_instance = abi(LibContract, contract_id.into());
let response = contract_instance.increment(42);
let _ = contract_instance.increment(42);

mint_to_address(amount, address);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@ abi MyContract {
#[storage(write)]
fn store(input: u64);
#[storage(read)]
fn read(input: u64) -> u64;
fn read() -> u64;
}

const COUNTER_KEY = 0x0000000000000000000000000000000000000000000000000000000000000000;
Expand All @@ -18,8 18,7 @@ impl MyContract for Contract {
}

#[storage(read)]
fn read(input: u64) -> u64 {
let v = read::<u64>(COUNTER_KEY, 0).unwrap_or(0);
v
fn read() -> u64 {
read::<u64>(COUNTER_KEY, 0).unwrap_or(0)
}
}
3 changes: 3 additions & 0 deletions packages/fuels/tests/contracts/require/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 2,19 @@ contract;

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,
Expand Down
6 changes: 3 additions & 3 deletions packages/fuels/tests/contracts/token_ops/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 50,9 @@ impl TestFuelCoin for Contract {

fn send_message(recipient: b256, coins: u64) {
let mut data = Bytes::new();
data.push(1);
data.push(2);
data.push(3);
data.push(1u8);
data.push(2u8);
data.push(3u8);

send_message(recipient, data, coins);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/fuels/tests/logs/contract_logs/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 3,38 @@ contract;
use std::logging::log;
use contract_logs::ContractLogs;

#[allow(dead_code)]
struct TestStruct {
field_1: bool,
field_2: b256,
field_3: u64,
}

#[allow(dead_code)]
enum TestEnum {
VariantOne: (),
VariantTwo: (),
}

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

#[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,
Expand Down
6 changes: 6 additions & 0 deletions packages/fuels/tests/logs/script_logs/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 2,38 @@ script;

use std::logging::log;

#[allow(dead_code)]
struct TestStruct {
field_1: bool,
field_2: b256,
field_3: u64,
}

#[allow(dead_code)]
enum TestEnum {
VariantOne: (),
VariantTwo: (),
}

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

#[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,
Expand Down
12 changes: 6 additions & 6 deletions packages/fuels/tests/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 240,7 @@ async fn pay_with_predicate_vector_data() -> Result<()> {
)
);

let predicate_data = MyPredicateEncoder::encode_data(2, 4, vec![2, 4, 42]);
let predicate_data = MyPredicateEncoder::encode_data(12, 30, vec![2, 4, 42]);

let mut predicate: Predicate = Predicate::load_from(
"tests/types/predicates/predicate_vector/out/debug/predicate_vector.bin",
Expand Down Expand Up @@ -289,7 289,7 @@ async fn predicate_contract_transfer() -> Result<()> {
"packages/fuels/tests/types/predicates/predicate_vector/out/debug/predicate_vector-abi.json"
));

let predicate_data = MyPredicateEncoder::encode_data(2, 4, vec![2, 4, 42]);
let predicate_data = MyPredicateEncoder::encode_data(2, 40, vec![2, 4, 42]);

let mut predicate: Predicate = Predicate::load_from(
"tests/types/predicates/predicate_vector/out/debug/predicate_vector.bin",
Expand Down Expand Up @@ -353,7 353,7 @@ async fn predicate_transfer_to_base_layer() -> Result<()> {
"packages/fuels/tests/types/predicates/predicate_vector/out/debug/predicate_vector-abi.json"
));

let predicate_data = MyPredicateEncoder::encode_data(2, 4, vec![2, 4, 42]);
let predicate_data = MyPredicateEncoder::encode_data(22, 20, vec![2, 4, 42]);

let mut predicate: Predicate = Predicate::load_from(
"tests/types/predicates/predicate_vector/out/debug/predicate_vector.bin",
Expand Down Expand Up @@ -400,7 400,7 @@ async fn predicate_transfer_with_signed_resources() -> Result<()> {
"packages/fuels/tests/types/predicates/predicate_vector/out/debug/predicate_vector-abi.json"
));

let predicate_data = MyPredicateEncoder::encode_data(2, 4, vec![2, 4, 42]);
let predicate_data = MyPredicateEncoder::encode_data(2, 40, vec![2, 4, 42]);

let mut predicate: Predicate = Predicate::load_from(
"tests/types/predicates/predicate_vector/out/debug/predicate_vector.bin",
Expand Down Expand Up @@ -486,7 486,7 @@ async fn contract_tx_and_call_params_with_predicate() -> Result<()> {
)
);

let predicate_data = MyPredicateEncoder::encode_data(2, 4, vec![2, 4, 42]);
let predicate_data = MyPredicateEncoder::encode_data(22, 20, vec![2, 4, 42]);

let mut predicate: Predicate = Predicate::load_from(
"tests/types/predicates/predicate_vector/out/debug/predicate_vector.bin",
Expand Down Expand Up @@ -563,7 563,7 @@ async fn diff_asset_predicate_payment() -> Result<()> {
)
);

let predicate_data = MyPredicateEncoder::encode_data(2, 4, vec![2, 4, 42]);
let predicate_data = MyPredicateEncoder::encode_data(28, 14, vec![2, 4, 42]);

let mut predicate: Predicate = Predicate::load_from(
"tests/types/predicates/predicate_vector/out/debug/predicate_vector.bin",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 1,5 @@
predicate;

fn main(a: u32, b: u64) -> bool {
a == b
b == a
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,7 @@ impl Eq for EnumWithGeneric<bool> {
}

// ANCHOR: predicate_configurables
#[allow(dead_code)]
enum EnumWithGeneric<D> {
VariantOne: D,
VariantTwo: (),
Expand Down
Loading

0 comments on commit 09ebbef

Please sign in to comment.