Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test coverage on std-lib #6087

Merged
merged 35 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
afa1321
Add address inline tests
bitzoic Jun 4, 2024
893b4d0
Add asset_id inline and contract tests
bitzoic Jun 4, 2024
85cf083
Add alloc inline tests
bitzoic Jun 4, 2024
f811d10
Add array_conversions inline tests
bitzoic Jun 4, 2024
550d462
Add assert inline tests
bitzoic Jun 4, 2024
ffe36e1
Add B512 inline tests
bitzoic Jun 4, 2024
7d69c75
Add block inline tests
bitzoic Jun 4, 2024
08770a4
Add bytes inlines tests
bitzoic Jun 4, 2024
1375e2b
Add bytes conversion inline tests
bitzoic Jun 4, 2024
c7064e8
Add contract_id inline and contract tests
bitzoic Jun 4, 2024
a413de3
Add ecr inline tests
bitzoic Jun 4, 2024
34efb53
Add flags inline tests
bitzoic Jun 4, 2024
0717a1b
Add hash inline tests
bitzoic Jun 4, 2024
b0c076f
Add identity inline tests
bitzoic Jun 4, 2024
45154c7
Add math inline tests
bitzoic Jun 4, 2024
5d40fba
Add option inline tests
bitzoic Jun 4, 2024
b9e5c94
Add primitive conversions inline tests
bitzoic Jun 4, 2024
9a7cbae
Add result inline tests
bitzoic Jun 4, 2024
55d5b6d
Add revert inline tests
bitzoic Jun 4, 2024
1a60461
Add string inline tests
bitzoic Jun 4, 2024
0272ee3
Add U128 inline tests
bitzoic Jun 4, 2024
c65718b
Add vec inline tests
bitzoic Jun 4, 2024
b274ae6
Add vm inline tests
bitzoic Jun 4, 2024
415cead
Add Forc.toml workspace
bitzoic Jun 4, 2024
518dda2
Remove inline tests from std-lib and minor updates
bitzoic Jun 4, 2024
16f9708
Merge branch 'master' into bitzoic-6038
bitzoic Jun 4, 2024
4e6ef76
Add in_language_tests to CI
bitzoic Jun 4, 2024
3c3707c
Fix typos
bitzoic Jun 4, 2024
b87e43b
Resolve e2e CI errors
bitzoic Jun 6, 2024
988004d
Merge branch 'master' into bitzoic-6038
bitzoic Jun 6, 2024
90a4625
Merge branch 'master' into bitzoic-6038
IGI-111 Jun 8, 2024
ed2bb0e
Add gitignore
bitzoic Jun 10, 2024
c8a75f4
Add comments on commented out code with TODO
bitzoic Jun 10, 2024
4b59567
Merge branch 'master' into bitzoic-6038
K1-R1 Jun 10, 2024
35cbdb8
Merge branch 'master' into bitzoic-6038
IGI-111 Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ jobs:
- name: Install Forc
run: cargo install --locked --debug --path ./forc
- name: Run Unit Tests
run: forc build --path sway-lib-core && forc test --path sway-lib-core && forc build --path sway-lib-std && forc test --path sway-lib-std
run: forc build --path sway-lib-core && forc test --path sway-lib-core && forc build --path sway-lib-std && forc test --path sway-lib-std && forc build --path test/src/in_language_tests & forc test --path test/src/in_language_tests

forc-pkg-fuels-deps-check:
runs-on: ubuntu-latest
Expand Down
32 changes: 0 additions & 32 deletions sway-lib-std/src/address.sw
Original file line number Diff line number Diff line change
Expand Up @@ -125,35 +125,3 @@ impl Hash for Address {
bits.hash(state);
}
}

#[test]
fn test_address_from_b256() {
use ::assert::assert;

let my_address = Address::from(0x0000000000000000000000000000000000000000000000000000000000000001);
assert(
my_address
.bits() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);
}

#[test]
fn test_address_into_b256() {
use ::assert::assert;
use ::convert::Into;

let address = Address::from(0x0000000000000000000000000000000000000000000000000000000000000001);
let b256_data: b256 = address.into();
assert(b256_data == 0x0000000000000000000000000000000000000000000000000000000000000001);
}

#[test]
fn test_address_zero() {
use ::assert::assert;

let address = Address::zero();
assert(address.is_zero());

let other_address = Address::from(0x0000000000000000000000000000000000000000000000000000000000000001);
assert(!other_address.is_zero());
}
52 changes: 0 additions & 52 deletions sway-lib-std/src/array_conversions/b256.sw
Original file line number Diff line number Diff line change
Expand Up @@ -173,55 +173,3 @@ impl b256 {
}
}
}

#[test]
fn test_b256_from_le_bytes() {
let bytes = [
32_u8, 31_u8, 30_u8, 29_u8, 28_u8, 27_u8, 26_u8, 25_u8, 24_u8, 23_u8, 22_u8,
21_u8, 20_u8, 19_u8, 18_u8, 17_u8, 16_u8, 15_u8, 14_u8, 13_u8, 12_u8, 11_u8,
10_u8, 9_u8, 8_u8, 7_u8, 6_u8, 5_u8, 4_u8, 3_u8, 2_u8, 1_u8,
];

let x = b256::from_le_bytes(bytes);

assert(x == 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20);
}

#[test]
fn test_b256_to_le_bytes() {
let x: b256 = 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20;

let bytes = x.to_le_bytes();

let mut i: u8 = 0;
while i < 32_u8 {
assert(bytes[i.as_u64()] == 32_u8 - i);
i += 1_u8;
}
}

#[test]
fn test_b256_from_be_bytes() {
let bytes = [
1_u8, 2_u8, 3_u8, 4_u8, 5_u8, 6_u8, 7_u8, 8_u8, 9_u8, 10_u8, 11_u8, 12_u8,
13_u8, 14_u8, 15_u8, 16_u8, 17_u8, 18_u8, 19_u8, 20_u8, 21_u8, 22_u8, 23_u8,
24_u8, 25_u8, 26_u8, 27_u8, 28_u8, 29_u8, 30_u8, 31_u8, 32_u8,
];

let x = b256::from_be_bytes(bytes);

assert(x == 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20);
}

#[test]
fn test_b256_to_be_bytes() {
let x: b256 = 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20;

let bytes = x.to_be_bytes();

let mut i: u8 = 0;
while i < 32_u8 {
assert(bytes[i.as_u64()] == i + 1_u8);
i += 1_u8;
}
}
34 changes: 0 additions & 34 deletions sway-lib-std/src/array_conversions/u16.sw
Original file line number Diff line number Diff line change
Expand Up @@ -122,37 +122,3 @@ impl u16 {
}
}
}

#[test]
fn test_u16_to_le_bytes() {
let x: u16 = 513;
let result = x.to_le_bytes();

assert(result[0] == 1_u8);
assert(result[1] == 2_u8);
}

#[test]
fn test_u16_from_le_bytes() {
let bytes = [1_u8, 2_u8];
let result = u16::from_le_bytes(bytes);

assert(result == 513_u16);
}

#[test]
fn test_u16_to_be_bytes() {
let x: u16 = 513;
let result = x.to_be_bytes();

assert(result[0] == 2_u8);
assert(result[1] == 1_u8);
}

#[test]
fn test_u16_from_be_bytes() {
let bytes = [2_u8, 1_u8];
let result = u16::from_be_bytes(bytes);

assert(result == 513_u16);
}
52 changes: 0 additions & 52 deletions sway-lib-std/src/array_conversions/u256.sw
Original file line number Diff line number Diff line change
Expand Up @@ -172,55 +172,3 @@ impl u256 {
}
}
}

#[test]
fn test_u256_from_le_bytes() {
let bytes = [
32_u8, 31_u8, 30_u8, 29_u8, 28_u8, 27_u8, 26_u8, 25_u8, 24_u8, 23_u8, 22_u8,
21_u8, 20_u8, 19_u8, 18_u8, 17_u8, 16_u8, 15_u8, 14_u8, 13_u8, 12_u8, 11_u8,
10_u8, 9_u8, 8_u8, 7_u8, 6_u8, 5_u8, 4_u8, 3_u8, 2_u8, 1_u8,
];

let x = u256::from_le_bytes(bytes);

assert(x == 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20u256);
}

#[test]
fn test_u256_to_le_bytes() {
let x: u256 = 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20u256;

let bytes = x.to_le_bytes();

let mut i: u8 = 0;
while i < 32_u8 {
assert(bytes[i.as_u64()] == 32_u8 - i);
i += 1_u8;
}
}

#[test]
fn test_u256_from_be_bytes() {
let bytes = [
1_u8, 2_u8, 3_u8, 4_u8, 5_u8, 6_u8, 7_u8, 8_u8, 9_u8, 10_u8, 11_u8, 12_u8,
13_u8, 14_u8, 15_u8, 16_u8, 17_u8, 18_u8, 19_u8, 20_u8, 21_u8, 22_u8, 23_u8,
24_u8, 25_u8, 26_u8, 27_u8, 28_u8, 29_u8, 30_u8, 31_u8, 32_u8,
];

let x = u256::from_be_bytes(bytes);

assert(x == 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20u256);
}

#[test]
fn test_u256_to_be_bytes() {
let x: u256 = 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20u256;

let bytes = x.to_be_bytes();

let mut i: u8 = 0;
while i < 32_u8 {
assert(bytes[i.as_u64()] == i + 1_u8);
i += 1_u8;
}
}
38 changes: 0 additions & 38 deletions sway-lib-std/src/array_conversions/u32.sw
Original file line number Diff line number Diff line change
Expand Up @@ -189,41 +189,3 @@ impl u32 {
}
}
}

#[test]
fn test_u32_to_le_bytes() {
let x: u32 = 67305985;
let result = x.to_le_bytes();

assert(result[0] == 1_u8);
assert(result[1] == 2_u8);
assert(result[2] == 3_u8);
assert(result[3] == 4_u8);
}

#[test]
fn test_u32_from_le_bytes() {
let bytes = [1_u8, 2_u8, 3_u8, 4_u8];
let result = u32::from_le_bytes(bytes);

assert(result == 67305985_u32);
}

#[test]
fn test_u32_to_be_bytes() {
let x: u32 = 67305985;
let result = x.to_be_bytes();

assert(result[0] == 4_u8);
assert(result[1] == 3_u8);
assert(result[2] == 2_u8);
assert(result[3] == 1_u8);
}

#[test]
fn test_u32_from_be_bytes() {
let bytes = [4_u8, 3_u8, 2_u8, 1_u8];
let result = u32::from_be_bytes(bytes);

assert(result == 67305985_u32);
}
46 changes: 0 additions & 46 deletions sway-lib-std/src/array_conversions/u64.sw
Original file line number Diff line number Diff line change
Expand Up @@ -257,49 +257,3 @@ impl u64 {
}
}
}

#[test]
fn test_u64_to_le_bytes() {
let x: u64 = 578437695752307201;
let result = x.to_le_bytes();

assert(result[0] == 1_u8);
assert(result[1] == 2_u8);
assert(result[2] == 3_u8);
assert(result[3] == 4_u8);
assert(result[4] == 5_u8);
assert(result[5] == 6_u8);
assert(result[6] == 7_u8);
assert(result[7] == 8_u8);
}

#[test]
fn test_u64_from_le_bytes() {
let bytes = [1_u8, 2_u8, 3_u8, 4_u8, 5_u8, 6_u8, 7_u8, 8_u8];
let result = u64::from_le_bytes(bytes);

assert(result == 578437695752307201);
}

#[test]
fn test_u64_to_be_bytes() {
let x: u64 = 578437695752307201;
let result = x.to_be_bytes();

assert(result[0] == 8_u8);
assert(result[1] == 7_u8);
assert(result[2] == 6_u8);
assert(result[3] == 5_u8);
assert(result[4] == 4_u8);
assert(result[5] == 3_u8);
assert(result[6] == 2_u8);
assert(result[7] == 1_u8);
}

#[test]
fn test_u64_from_be_bytes() {
let bytes = [8_u8, 7_u8, 6_u8, 5_u8, 4_u8, 3_u8, 2_u8, 1_u8];
let result = u64::from_be_bytes(bytes);

assert(result == 578437695752307201);
}
69 changes: 5 additions & 64 deletions sway-lib-std/src/asset_id.sw
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ impl AssetId {

/// Creates a new AssetId with the default SubId for the current contract.
///
/// # Additional Information
///
/// **WARNING** If called in an external context, this will **not** return a correct AssetId.
/// If called externally, will actually use the Transaction Id as a the ContractId.
///
/// # Returns
///
/// * [AssetId] - The AssetId of the asset. Computed by hashing the ContractId and the default SubId.
Expand Down Expand Up @@ -240,67 +245,3 @@ impl From<AssetId> for b256 {
id.bits()
}
}

#[test()]
fn test_hasher_sha256_asset_id() {
use ::assert::assert;
let mut hasher = Hasher::new();
AssetId::from(0x0000000000000000000000000000000000000000000000000000000000000000)
.hash(hasher);
let s256 = hasher.sha256();
assert(s256 == 0x66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925);

let mut hasher = Hasher::new();
AssetId::from(0x0000000000000000000000000000000000000000000000000000000000000001)
.hash(hasher);
let s256 = hasher.sha256();
assert(s256 == 0xec4916dd28fc4c10d78e287ca5d9cc51ee1ae73cbfde08c6b37324cbfaac8bc5);
}

#[test()]
fn test_hasher_sha256_contract_id() {
use ::assert::assert;
let mut hasher = Hasher::new();
ContractId::from(0x0000000000000000000000000000000000000000000000000000000000000000)
.hash(hasher);
let s256 = hasher.sha256();
assert(s256 == 0x66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925);

let mut hasher = Hasher::new();
ContractId::from(0x0000000000000000000000000000000000000000000000000000000000000001)
.hash(hasher);
let s256 = hasher.sha256();
assert(s256 == 0xec4916dd28fc4c10d78e287ca5d9cc51ee1ae73cbfde08c6b37324cbfaac8bc5);
}

#[test]
fn test_asset_id_from_b256() {
use ::assert::assert;

let my_asset = AssetId::from(0x0000000000000000000000000000000000000000000000000000000000000001);
assert(
my_asset
.bits() == 0x0000000000000000000000000000000000000000000000000000000000000001,
);
}

#[test]
fn test_asset_id_into_b256() {
use ::assert::assert;
use ::convert::Into;

let asset = AssetId::from(0x0000000000000000000000000000000000000000000000000000000000000001);
let b256_data: b256 = asset.into();
assert(b256_data == 0x0000000000000000000000000000000000000000000000000000000000000001);
}

#[test]
fn test_asset_id_zero() {
use ::assert::assert;

let asset = AssetId::zero();
assert(asset.is_zero());

let other_assert = AssetId::from(0x0000000000000000000000000000000000000000000000000000000000000001);
assert(!other_assert.is_zero());
}
Loading
Loading