Skip to content

Commit

Permalink
Add comments on commented out code with TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Jun 10, 2024
1 parent ed2bb0e commit c8a75f4
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ fn alloc_alloc() {
iter += 1;
}

// Can alloc enum
// let identity_ptr = alloc::<Identity>(1);
// assert(identity_ptr.read::<Identity>() == Identity::Address(Address::zero()));
// identity_ptr.write(Identity::Address(Address::from(b256::max())));
// assert(
// identity_ptr
// .read::<Identity>() == Identity::Address(Address::from(b256::max())),
// );

// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// Can alloc array
// let array_ptr = alloc::<[u64; 1]>(2);
// assert(array_ptr.read::<u64>() == 0u64);
Expand Down Expand Up @@ -103,20 +95,7 @@ fn alloc_realloc() {
assert(realloc_address_ptr.read::<Address>() == Address::from(b256::max()));
assert(realloc_address_ptr.add::<Address>(1).read::<Address>() == Address::zero());

// Can alloc enum
// let identity_ptr = alloc::<Identity>(1);
// identity_ptr.write(Identity::Address(Address::from(b256::max())));
// let realloc_identity_ptr = realloc::<Identity>(identity_ptr, 1, 2);
// assert(
// realloc_identity_ptr
// .read::<Identity>() == Identity::Address(Address::from(b256::max())),
// );
// assert(
// realloc_identity_ptr
// .add::<Identity>(1)
// .read::<Identity>() == Identity::Address(Address::from(b256::zero())),
// );

// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// Can realloc array
// let array_ptr = alloc::<[u64; 1]>(2);
// array_ptr.write(u64::max());
Expand Down Expand Up @@ -214,15 +193,7 @@ fn alloc_alloc_bytes() {
address_ptr.write(Address::from(b256::max()));
assert(address_ptr.read::<Address>() == Address::from(b256::max()));

// Can alloc enum
// let identity_ptr = alloc_bytes(__size_of_val::<Identity>(Identity::Address(Address::zero())));
// assert(identity_ptr.read::<Identity>() == Identity::Address(Address::zero()));
// identity_ptr.write(Identity::Address(Address::from(b256::max())));
// assert(
// identity_ptr
// .read::<Identity>() == Identity::Address(Address::from(b256::max())),
// );

// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// Can alloc array
// let array_ptr = alloc_bytes(__size_of::<[u64; 1]>() * 2);
// assert(array_ptr.read::<u64>() == 0u64);
Expand Down Expand Up @@ -289,24 +260,7 @@ fn alloc_realloc_bytes() {
assert(realloc_address_ptr.read::<Address>() == Address::from(b256::max()));
assert(realloc_address_ptr.add::<Address>(1).read::<Address>() == Address::zero());

// Can alloc enum
// let identity_ptr = alloc_bytes(__size_of_val::<Identity>(Identity::Address(Address::zero())));
// identity_ptr.write(Identity::Address(Address::from(b256::max())));
// let realloc_identity_ptr = realloc_bytes(
// identity_ptr,
// __size_of_val::<Identity>(Identity::Address(Address::zero())),
// __size_of_val::<Identity>(Identity::Address(Address::zero())) * 2,
// );
// assert(
// realloc_identity_ptr
// .read::<Identity>() == Identity::Address(Address::from(b256::max())),
// );
// assert(
// realloc_identity_ptr
// .add::<Identity>(1)
// .read::<Identity>() == Identity::Address(Address::from(b256::zero())),
// );

// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// Can realloc array
// let array_ptr = alloc_bytes(__size_of::<[u64; 1]>() * 2);
// array_ptr.write(u64::max());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fn assert_assert_eq() {
p.push(69u8);
assert_eq(o, p);

// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved.
// assert_eq array
// let value = 0xBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEFBEEF;
// let mut q: [u64; 3] = [0, 0, 0];
Expand Down Expand Up @@ -146,6 +147,7 @@ fn assert_assert_ne() {
p.push(70u8);
assert_ne(o, p);

// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved.
// assert_ne array
// let mut q: [u64; 3] = [1, 2, 3];
// let mut r: [u64; 3] = [0, 0, 0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn ecr_ec_recover_r1() {
let msg_hash_2 = 0x1e45523606c96c98ba970ff7cf9511fab8b25e1bcd52ced30b81df1e4a9c4323;
let signature_2: B512 = B512::from((hi_2, lo_2));
let result_2 = ec_recover_r1(signature_2, msg_hash_2);

assert(result_2.is_err());
}

Expand All @@ -81,7 +81,7 @@ fn ecr_ec_recover_address() {
let msg_hash_2 = 0xee45573606c96c98ba970ff7cf9511f1b8b25e6bcd52ced30b89df1e4a9c4323;
let signature_2: B512 = B512::from((hi_2, lo_2));
let result_2 = ec_recover_address(signature_2, msg_hash_2);

assert(result_2.is_err());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ library;

use std::{bytes::Bytes, hash::{Hash, Hasher, keccak256, sha256, sha256_str_array},};

// NOTE: There are no tests for the Hasher struct as there is nothing that can be asserted

#[test()]
fn hash_hasher_write_str() {
let mut hasher = Hasher::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library;

use std::hash::{Hash, sha256};

#[test]
fn identity_eq() {
let address1 = Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000000));
Expand Down Expand Up @@ -217,20 +215,33 @@ fn identity_bits() {
);
}

// #[test]
// fn identity_hash() {
// let address1 = Identity::Address(Address::zero());
// let address2 = Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
// let address3 = Identity::Address(Address::from(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
// let contract_id1 = Identity::ContractId(ContractId::zero());
// let contract_id2 = Identity::ContractId(ContractId::from(0x0000000000000000000000000000000000000000000000000000000000000001));
// let contract_id3 = Identity::ContractId(ContractId::from(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF));


// assert(sha256(address1) == 0x0000000000000000000000000000000000000000000000000000000000000001);
// assert(sha256(contract_id1) == b256::zero());
// assert(sha256(address2) == 0x0000000000000000000000000000000000000000000000000000000000000001);
// assert(sha256(contract_id2) == 0x0000000000000000000000000000000000000000000000000000000000000001);
// assert(sha256(address3) == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
// assert(sha256(contract_id3) == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
// }
#[test]
fn identity_hash() {
use std::hash::{Hash, sha256};

let address1 = Identity::Address(Address::zero());
let address2 = Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let address3 = Identity::Address(Address::from(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF));
let contract_id1 = Identity::ContractId(ContractId::zero());
let contract_id2 = Identity::ContractId(ContractId::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let contract_id3 = Identity::ContractId(ContractId::from(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF));

assert(
sha256(address1) == 0x7f9c9e31ac8256ca2f258583df262dbc7d6f68f2a03043d5c99a4ae5a7396ce9,
);
assert(
sha256(contract_id1) == 0x1a7dfdeaffeedac489287e85be5e9c049a2ff6470f55cf30260f55395ac1b159,
);
assert(
sha256(address2) == 0x1fd4247443c9440cb3c48c28851937196bc156032d70a96c98e127ecb347e45f,
);
assert(
sha256(contract_id2) == 0x2e255099d6d6bee307c8e7075acc78f949897c5f67b53adf60724c814d7b90cb,
);
assert(
sha256(address3) == 0x5e16d316ecd5773e50c3b02737d424192b02f25b4245822079181c557aafda7d,
);
assert(
sha256(contract_id3) == 0x29fb7cd3be48a8d76bb031f0abce26caa9e092c000cd16bb101d30f63c4c1bc1,
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library;

// NO IMPLEMENTATION FOR "Exponent" TRAIT

#[test]
fn math_root_u256() {
let max_u256 = u256::max();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ fn option_eq() {
let struct_2 = Some(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
let enum_2 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
// let array_1 = Some([0u64, 0u64]);
// let array_2 = Some([0u64, 0u64]);
let _array_1 = Some([0u64, 0u64]);
let _array_2 = Some([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let mut bytes_2 = Bytes::new();
Expand All @@ -39,6 +39,7 @@ fn option_eq() {
assert(b256_1 == b256_2);
assert(struct_1 == struct_2);
assert(enum_1 == enum_2);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1 == array_2);
assert(heap_1 == heap_2);
assert(none_1 == none_2);
Expand All @@ -64,8 +65,8 @@ fn option_ne() {
let struct_2 = Some(Address::from(0x0000000000000000000000000000000000000000000000000000000000000002));
let enum_1 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
let enum_2 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000002)));
// let array_1 = Some([0u64, 0u64]);
// let array_2 = Some([0u64, 1u64]);
let _array_1 = Some([0u64, 0u64]);
let _array_2 = Some([0u64, 1u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let mut bytes_2 = Bytes::new();
Expand All @@ -82,6 +83,7 @@ fn option_ne() {
assert(b256_1 != b256_2);
assert(struct_1 != struct_2);
assert(enum_1 != enum_2);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1 != array_2);
assert(heap_1 != heap_2);
assert(none_1 != u64_1);
Expand Down Expand Up @@ -161,7 +163,7 @@ fn option_unwrap() {
let b256_1 = Some(0x0000000000000000000000000000000000000000000000000000000000000001);
let struct_1 = Some(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
// let array_1 = Some([0u64, 0u64]);
let _array_1 = Some([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let heap_1 = Some(bytes_1);
Expand All @@ -183,6 +185,7 @@ fn option_unwrap() {
enum_1
.unwrap() == Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)),
);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1.unwrap() == [0u64, 0u64]);
assert(heap_1.unwrap() == bytes_1);
}
Expand All @@ -205,7 +208,7 @@ fn option_unwrap_or() {
let b256_1 = Some(0x0000000000000000000000000000000000000000000000000000000000000001);
let struct_1 = Some(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
// let array_1 = Some([0u64, 0u64]);
let _array_1 = Some([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let heap_1 = Some(bytes_1);
Expand All @@ -228,6 +231,7 @@ fn option_unwrap_or() {
enum_1
.unwrap_or(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000002))) == Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)),
);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1.unwrap_or([1u64, 1u64]) == [0u64, 0u64]);
assert(heap_1.unwrap_or(Bytes::new()) == bytes_1);
assert(none_1.unwrap_or(10u64) == 10u64);
Expand All @@ -245,7 +249,7 @@ fn option_ok_or() {
let b256_1 = Some(0x0000000000000000000000000000000000000000000000000000000000000001);
let struct_1 = Some(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
//let array_1 = Some([0u64, 0u64]);
let _array_1 = Some([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let heap_1 = Some(bytes_1);
Expand Down Expand Up @@ -289,6 +293,7 @@ fn option_ok_or() {
),
Result::Err => revert(0),
};
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// match array_1.ok_or([1u64, 1u64]) {
// Result::Ok(underlying) => assert(underlying == [0u64, 0u64]),
// Result::Err => revert(0),
Expand All @@ -315,7 +320,7 @@ fn option_expect() {
let b256_1 = Some(0x0000000000000000000000000000000000000000000000000000000000000001);
let struct_1 = Some(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1 = Some(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
// let array_1 = Some([0u64, 0u64]);
let _array_1 = Some([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let heap_1 = Some(bytes_1);
Expand All @@ -337,6 +342,7 @@ fn option_expect() {
enum_1
.expect("Failed Test") == Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)),
);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1.expect("Failed Test") == [0u64, 0u64]);
assert(heap_1.expect("Failed Test") == bytes_1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn result_unwrap() {
let b256_1: Result<b256, str> = Ok(0x0000000000000000000000000000000000000000000000000000000000000001);
let struct_1: Result<Address, str> = Ok(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1: Result<Identity, str> = Ok(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
// let array_1: Result<[u64; 2], str> = Ok([0u64, 0u64]);
let _array_1: Result<[u64; 2], str> = Ok([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let heap_1: Result<Bytes, str> = Ok(bytes_1);
Expand All @@ -96,6 +96,7 @@ fn result_unwrap() {
enum_1
.unwrap() == Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)),
);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1.unwrap() == [0u64, 0u64]);
assert(heap_1.unwrap() == bytes_1);
}
Expand All @@ -118,7 +119,7 @@ fn result_unwrap_or() {
let b256_1: Result<b256, str> = Ok(0x0000000000000000000000000000000000000000000000000000000000000001);
let struct_1: Result<Address, str> = Ok(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1: Result<Identity, str> = Ok(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
// let array_1: Result<[u64; 2], str> = Ok([0u64, 0u64]);
let _array_1: Result<[u64; 2], str> = Ok([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let heap_1: Result<Bytes, str> = Ok(bytes_1);
Expand All @@ -141,6 +142,7 @@ fn result_unwrap_or() {
enum_1
.unwrap_or(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000002))) == Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)),
);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1.unwrap_or([1u64, 1u64]) == [0u64, 0u64]);
assert(heap_1.unwrap_or(Bytes::new()) == bytes_1);
assert(err_1.unwrap_or(10u64) == 10u64);
Expand All @@ -158,7 +160,7 @@ fn result_expect() {
let b256_1: Result<b256, str> = Ok(0x0000000000000000000000000000000000000000000000000000000000000001);
let struct_1: Result<Address, str> = Ok(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001));
let enum_1: Result<Identity, str> = Ok(Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)));
// let array_1: Result<[u64; 2], str> = Ok([0u64, 0u64]);
let _array_1: Result<[u64; 2], str> = Ok([0u64, 0u64]);
let mut bytes_1 = Bytes::new();
bytes_1.push(1u8);
let heap_1: Result<Bytes, str> = Ok(bytes_1);
Expand All @@ -180,6 +182,7 @@ fn result_expect() {
enum_1
.expect("Failed Test") == Identity::Address(Address::from(0x0000000000000000000000000000000000000000000000000000000000000001)),
);
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6086 is resolved
// assert(array_1.expect("Failed Test") == [0u64, 0u64]);
assert(heap_1.expect("Failed Test") == bytes_1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ fn vec_from_raw_slice() {
assert(vec.len() == slice.len::<u64>());
}

// Uncomment when https://github.com/FuelLabs/sway/issues/6085 is resolved
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6085 is resolved
// #[test()]
// fn vec_into_raw_slice() {
// // Glob operator needed for From<Vec> for raw_slice
Expand All @@ -659,7 +659,7 @@ fn vec_from_raw_slice() {
// assert(vec.len() == slice.len::<u64>());
// }

// Uncomment when https://github.com/FuelLabs/sway/issues/6085 is resolved
// TODO: Uncomment when https://github.com/FuelLabs/sway/issues/6085 is resolved
// #[test()]
// fn vec_raw_slice_from() {
// // Glob operator needed for From<Vec> for raw_slice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
library;

use std::{
b512::B512,
vm::evm::{
evm_address::EvmAddress,
ecr::ec_recover_evm_address,
}
};
use std::{b512::B512, vm::evm::{ecr::ec_recover_evm_address, evm_address::EvmAddress,}};

#[test]
fn ecr_ec_recover() {
Expand All @@ -27,7 +21,6 @@ fn ecr_ec_recover() {
let signature_2: B512 = B512::from((hi_2, lo_2));

let result_2 = ec_recover_evm_address(signature_2, msg_hash_2);

assert(result_2.is_err());
}

0 comments on commit c8a75f4

Please sign in to comment.