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

Increase test coverage on std-lib #6087

merged 35 commits into from
Jun 11, 2024

Conversation

bitzoic
Copy link
Member

@bitzoic bitzoic commented Jun 4, 2024

Description

Completes in-language tests for #6038.

Any tests in the std-lib have been moved into the test/src/in_language_tests folder. This has been done to ensure imports behave as expected and fields that should be public are.

While many of the functions that have new tests are used elsewhere in the tests, there were no tests to explicitly check that it is behaving as expected.

The following tests have been added:

Address:

  • bits()
  • Eq
  • Neq
  • b256.into()
  • b256::from()
  • Hash
  • is_zero()

Assert

  • Assert revert when not true
  • Assert_eq revert when not true
  • Assert_ne revert when not false

Asset Id

  • Eq
  • Neq
  • b256.into()
  • b256::from()
  • new()
  • default()
  • bits()
  • is_zero()

B512

  • Eq
  • Neq
  • Into
  • b256::from
  • b256.into()
  • new()
  • bits()
  • is_zero()

Bytes

  • with_capacity()
  • capacity()
  • is_empty()
  • ptr()
  • b256.into()
  • b256::from()
  • clone()

ContractId

  • bits()
  • Eq
  • Neq
  • b256.into()
  • b256::from()
  • is_zero()

Hash

  • write_str_array()
  • Hash for 2, 3, 4, 5 tuple
  • Hash 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 arrays
  • sha256()
  • sha256_str_array()
  • kekkack()

Identity

  • Eq
  • Neq
  • Hash

Option

  • Neq
  • ok_or()
  • expect()

Result

  • Neq
  • expect()

String

  • ptr()
  • Bytes::from()
  • Bytes.into()
  • as_raw_slice()

U128

  • into u8
  • into u16
  • into u32
  • into u64
  • From (u64, u64)
  • Into (u64, u64)
  • (u64, u64)::from
  • (u64, u64).into()
  • Eq
  • Neq
  • Ord
  • new()
  • min()
  • max()
  • bits()
  • upper()
  • lower()
  • log2
  • u8.into()
  • u8::from()
  • u16.into()
  • u16::from()
  • u32.into()
  • u32::from()
  • u64.into()
  • u64::from()
  • u256.into()
  • u256::from()

Primitive Conversions

b256

  • into u256

u16

  • into u8

u32

  • into u8
  • into u16

u64

  • into u8
  • into u16
  • into u32

u256

  • into u8
  • into u16
  • into u32
  • into u64
  • into b256
  • into u256
  • into tuple

EvmAddrsss

  • bits()
  • Eq
  • Neq
  • is_zero()
  • b256::from()
  • b256.into()

Additional Edge cases have been added:

Address

  • Min & max edge cases

Alloc

  • Check alloc() does not exceed bounds
  • Check realloc() same size
  • Check realloc() less size does nothing
  • Check realloc() excludes values if less than current
  • realloc() reverts on unallocated memory
  • alloc_bytes() does not exceed bounds
  • realloc_bytes() same size
  • realloc_bytes() less size does nothing
  • realloc_bytes() excludes values if less than current
  • realloc_bytes() reverts on unallocated memory

Assert

  • No tests for array

AssetId

  • Min & max edge cases

B512

  • Min & max edge cases

Bytes

  • Push increases capacity
  • Pop does not change capacity
  • Check get result when out of bounds
  • Set front
  • Set back
  • Set does not change capacity
  • Set twice
  • Set behavior when out of bounds
  • Insert front
  • Insert back
  • Insert changes capacity
  • Insert behavior when out of bounds
  • Remove front
  • Remove back
  • Remove does not change capacity
  • Remove all
  • Remove behavior when out of bounds
  • Swap front
  • Swap back
  • Swap does not change capacity
  • Swap behavior when out of bounds
  • len() updates
  • Split twice
  • Split capacity checks
  • Split behavior when out of bounds
  • Append changes capacity

ContractId

  • Min & max edge cases

Hash

  • Min & max edge cases

Identity

  • Min & max edge cases

Option

  • Coverage on all primitive types

Result

  • Coverage on all primitive types

Revert

  • Require reverts on false

U128

  • Revert on add when overflow
  • Revert on sub when negative
  • Revert on mul when overflow
  • Revert on divide by zero
  • Min & max edge cases

Primitive Conversions

b256

  • Min & max edge cases

u8

  • Min & max edge cases

u16

  • Min & max edge cases

u32

  • Min & max edge cases

u64

  • Min & max edge cases

u256

  • Min & max edge cases

EvmAddress

  • Min & max edge cases

evm ecr recover

  • Result error when failed to recover

The following issue have been discovered by writing these tests:

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@bitzoic bitzoic added enhancement New feature or request lib: std Standard library big this task is hard and will take a while labels Jun 4, 2024
@bitzoic bitzoic added the testing General testing label Jun 4, 2024
@bitzoic bitzoic self-assigned this Jun 4, 2024
@bitzoic bitzoic requested review from a team as code owners June 4, 2024 10:09
@bitzoic bitzoic linked an issue Jun 4, 2024 that may be closed by this pull request
73 tasks
IGI-111
IGI-111 previously approved these changes Jun 8, 2024
Copy link
Contributor

@IGI-111 IGI-111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was skeptical of moving everything to separate libraries, but your reasoning for it is sound and it's actually easier to consume this way.

@K1-R1 K1-R1 self-requested a review June 10, 2024 16:29
Copy link
Member

@K1-R1 K1-R1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, LGTM

IGI-111 pushed a commit that referenced this pull request Jun 11, 2024
## Description

As part of #6087, it was revealed
that the current `use std::primitive_conversions::*;` line in the
prelude does not import anything which a developer can use. To use any
of the submodules in the primitive conversions library, users would need
to import the individual submodule regardless of the prelude.

This PR adds the submodules as an import to the prelude to stay
consistent with the original intent. Both the core's and std-lib's
primitive conversions modules are imported. Conversions between
primitive types should not require additional imports.

Example before:
```sway
use std::primitive_conversions::u32::*;

fn foo() {
    let my_u8 = 1_u8;
    let my_u16 = 1_u16;
    let my_u64 = 1_u64;

    let u32_1 = u32::from(my_u8);
    let u32_2 = u32::from(my_u16);
    let u32_3 = u32::try_from(my_u64);
}
```

Example after:
```sway
fn foo() {
    let my_u8 = 1_u8;
    let my_u16 = 1_u16;
    let my_u64 = 1_u64;

    let u32_1 = u32::from(my_u8);
    let u32_2 = u32::from(my_u16);
    let u32_3 = u32::try_from(my_u64);
}
```

Closes #6088

Dependent on #6087

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
@IGI-111 IGI-111 merged commit 5e24673 into master Jun 11, 2024
37 checks passed
@IGI-111 IGI-111 deleted the bitzoic-6038 branch June 11, 2024 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
big this task is hard and will take a while enhancement New feature or request lib: std Standard library testing General testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Increase std-lib test coverage
4 participants