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

test: refactor StringCoder tests #972

Conversation

danielbate
Copy link
Member

Related to #753

This PR will:

  • Introduce a seperate test file for the service under test
  • Seperate test cases for encode and decode
  • Remove snapshot tests to bring expectations into the same test file
  • Remove redundant tests to more clearly report on code coverage

A previous PR #942 introduced this functionality but was closed erroneously due to the removal of a fork repository.

Comment on lines 73 to 91
// TODO: StringCoder should throw for these conditions?

// it('should throw when encoding a string that is too big', () => {
// const coder = new StringCoder(0);
// const invalidInput = STRING_MAX_DECODED;

// expect(() => {
// coder.encode(invalidInput);
// }).toThrow();
// });

// it('should throw when encoding a string that is too small', () => {
// const coder = new StringCoder(1);
// const invalidInput = STRING_MIN_DECODED;

// expect(() => {
// coder.encode(invalidInput);
// }).toThrow();
// });
Copy link
Member Author

Choose a reason for hiding this comment

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

Moving conversation from #942 due to changed head repository.

@danielbate:

@FuelLabs/sdk-ts should we be throwing for these conditions? Other coders throw for this behaviour, wheras StringCoder will instead just slice the input by the length that is past to the construtor.

@arboleya:

My instinct says yes — we should throw.

Not sure how the Rust SDK handles this.

cc @digorithm.

Copy link
Member Author

@danielbate danielbate May 7, 2023

Choose a reason for hiding this comment

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

@arboleya @digorithm looking at the Rust SDK, I believe we should be throwing for this condition:

https://github.com/FuelLabs/fuels-rs/blob/c20630cc92b4bcffce0a516dc360bfb8fbe9bfbf/packages/fuels-types/src/core.rs#L44-L50

Other encoders within the TS SDK throw for similar behaviour, so I believe that to be the expected behaviour. I'll raise an issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

#985 has been raised to deal with the missing throw conditions, so I'll remove the commented out tests and will address there

@danielbate danielbate changed the title Db/test/refactor string coder tests test: refactor StringCoder tests May 3, 2023
@danielbate danielbate self-assigned this May 3, 2023
@danielbate danielbate marked this pull request as ready for review May 3, 2023 13:58
@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2023

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
95.11% (-0.07% 🔻)
4703/4945
🟢 Branches
83.97% (+0.02% 🔼)
833/992
🟢 Functions
92.43% (-0.23% 🔻)
903/977
🟢 Lines
95.13% (-0.05% 🔻)
4496/4726
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / operations.ts
86.44% (-1.69% 🔻)
100%
72.88% (-3.39% 🔻)
91.21% (-1.1% 🔻)
🟡
... / provider.ts
78.85% (-0.66% 🔻)
72.5%
79.07% (-1.37% 🔻)
77.85% (-0.58% 🔻)
🟢
... / vec.ts
83.33% (-3.62% 🔻)
25% 83.33%
82.61% (-3.75% 🔻)

Test suite run success

826 tests passing in 127 suites.

Report generated by 🧪jest coverage report action from 57dc375

@danielbate danielbate merged commit 03e4988 into db/test/refactor-abi-coder-coders-tests May 7, 2023
@danielbate danielbate deleted the db/test/refactor-string-coder-tests branch May 7, 2023 18:24
danielbate added a commit that referenced this pull request May 17, 2023
* test: add individual unit test files for coders

* test: implemented abi coder test utils

* Revert "test: add individual unit test files for coders"

This reverts commit 9d77f9d.

* test: refactor `NumberCoder` tests (#949)

* test: refactor and increase verbosity of number coder tests

* chore: changeset

* chore: force rebuild

---------

Co-authored-by: danielbate <--global>

* test: refactor `B256Coder` tests (#946)

* test: refactor and increase verbosity of b256 coder tests

* chore: changeset

* test: add test for missing throw condition

---------

Co-authored-by: danielbate <--global>

* test: refactor `B512Coder` tests (#945)

* test: refactor and increase verbosity of b512 coder tests

* chore: changeset

* chore: linting

* test: add test case for missing throw condition in b512 coder

* test: correct imported class name in b512 coder test

Co-authored-by: Sérgio Torres <[email protected]>

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Sérgio Torres <[email protected]>

* test: refactor `BooleanCoder` tests (#944)

* test: refactor and increase verbosity of boolean coder tests

* chore: changeset

* test: add missing test coverage to boolean coder throw conditions

---------

Co-authored-by: danielbate <--global>

* test: refactor `ByteCoder` tests (#943)

* test: refactored byte coder tests

* chore: changeset

---------

Co-authored-by: danielbate <--global>

* test: refactor `TupleCoder` tests (#939)

* test: refactor and increase verbosity of tuple coder tests

* chore: changeset

---------

Co-authored-by: danielbate <--global>

* test: refactor `StructCoder` tests (#940)

* test: refactor and increase verbosity of struct test

* test: fix test number inputs in struct coder test

* chore: changeset

* test: use template literals for struct name in struct coder test

Co-authored-by: Anderson Arboleya <[email protected]>

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Anderson Arboleya <[email protected]>

* test: refactor `ArrayCoder` tests (#937)

* test: refactor and increase verbosity of array coder tests

* chore: changeset

* test: remove redundant describe block from array coder test

* test: add missing throw condition testcase to array coder

---------

Co-authored-by: danielbate <--global>

* test: refactor `U64Coder` tests (#941)

* test: refactor and increase verbosity of u64 coder tests

* test: remove redundant imports and comments

* chore: changeset

* chore: force rebuild

---------

Co-authored-by: danielbate <--global>

* test: refactor `VecCoder` tests (#936)

* test: refactor and increase verbosity of vec test

* chore: changeset

* test: add missing test cases for encoding non array inputs in vec coder

---------

Co-authored-by: danielbate <--global>

* test: refactor `StringCoder` tests (#972)

* test: refactor and increase verbosity of string coder tests

* test: remove redundant import

* chore: changeset

* chore: force rebuild

* test: remove commented out tests from string coder

---------

Co-authored-by: danielbate <--global>

* test: refactor `EnumCoder` tests (#938)

* test: refactor and increase verbosity of enum coder tests

* chore: changeset

* test: introduce test cases for native enums

* test: add feature test in abi coder for native enum

* test: remove abi coder test case for native enum as redundant

---------

Co-authored-by: danielbate <--global>

* test: abstract coder tests

* refactor: remove coders mass and snapshot tests

* chore: remove redundant import in ABI coder

* chore: linting

* chore: linting

* test: remove redundant enum coder tests

* test: refactor `OptionCoder` tests (#1006)

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Sérgio Torres <[email protected]>
Co-authored-by: Anderson Arboleya <[email protected]>
danielbate added a commit that referenced this pull request May 18, 2023
* test: add individual unit test files for coders

* test: implemented abi coder test utils

* Revert "test: add individual unit test files for coders"

This reverts commit 9d77f9d.

* test: refactor `NumberCoder` tests (#949)

* test: refactor and increase verbosity of number coder tests

* chore: changeset

* chore: force rebuild

---------

Co-authored-by: danielbate <--global>

* test: refactor `B256Coder` tests (#946)

* test: refactor and increase verbosity of b256 coder tests

* chore: changeset

* test: add test for missing throw condition

---------

Co-authored-by: danielbate <--global>

* test: refactor `B512Coder` tests (#945)

* test: refactor and increase verbosity of b512 coder tests

* chore: changeset

* chore: linting

* test: add test case for missing throw condition in b512 coder

* test: correct imported class name in b512 coder test

Co-authored-by: Sérgio Torres <[email protected]>

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Sérgio Torres <[email protected]>

* test: refactor `BooleanCoder` tests (#944)

* test: refactor and increase verbosity of boolean coder tests

* chore: changeset

* test: add missing test coverage to boolean coder throw conditions

---------

Co-authored-by: danielbate <--global>

* test: refactor `ByteCoder` tests (#943)

* test: refactored byte coder tests

* chore: changeset

---------

Co-authored-by: danielbate <--global>

* test: refactor `TupleCoder` tests (#939)

* test: refactor and increase verbosity of tuple coder tests

* chore: changeset

---------

Co-authored-by: danielbate <--global>

* test: refactor `StructCoder` tests (#940)

* test: refactor and increase verbosity of struct test

* test: fix test number inputs in struct coder test

* chore: changeset

* test: use template literals for struct name in struct coder test

Co-authored-by: Anderson Arboleya <[email protected]>

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Anderson Arboleya <[email protected]>

* test: refactor `ArrayCoder` tests (#937)

* test: refactor and increase verbosity of array coder tests

* chore: changeset

* test: remove redundant describe block from array coder test

* test: add missing throw condition testcase to array coder

---------

Co-authored-by: danielbate <--global>

* test: refactor `U64Coder` tests (#941)

* test: refactor and increase verbosity of u64 coder tests

* test: remove redundant imports and comments

* chore: changeset

* chore: force rebuild

---------

Co-authored-by: danielbate <--global>

* test: refactor `VecCoder` tests (#936)

* test: refactor and increase verbosity of vec test

* chore: changeset

* test: add missing test cases for encoding non array inputs in vec coder

---------

Co-authored-by: danielbate <--global>

* test: refactor `StringCoder` tests (#972)

* test: refactor and increase verbosity of string coder tests

* test: remove redundant import

* chore: changeset

* chore: force rebuild

* test: remove commented out tests from string coder

---------

Co-authored-by: danielbate <--global>

* feat: add throw to string coder when encoding value with length mismatch

* test: add unit test for string cdoer encoder throw conditon

* chore: changeset

* chore: force rebuild

---------

Co-authored-by: danielbate <--global>
Co-authored-by: Sérgio Torres <[email protected]>
Co-authored-by: Anderson Arboleya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants