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

Error handling #133

Closed
wants to merge 0 commits into from
Closed

Error handling #133

wants to merge 0 commits into from

Conversation

faytey
Copy link

@faytey faytey commented Oct 8, 2023

A draft of the error-handling techniques used for testing purposes, kindly let me know if the method used so far is acceptable. Thanks

Copy link
Collaborator

@uri-99 uri-99 left a comment

Choose a reason for hiding this comment

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

some format errors. You should run make fmt before pushing

@@ -25,7 +25,8 @@ trait IYASPool<TContractState> {

#[starknet::contract]
mod YASPool {
use super::IYASPool;
use core::result::ResultTrait;
use super::IYASPool;
Copy link
Collaborator

Choose a reason for hiding this comment

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

format error. You should run make fmt before pushing

@@ -74,7 +73,8 @@ trait ITick<TContractState> {

#[starknet::contract]
mod Tick {
use super::{ITick, Info};
use core::result::ResultTrait;
use super::{ITick, Info};
Copy link
Collaborator

Choose a reason for hiding this comment

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

format error. You should run make fmt before pushing

@@ -10,7 +10,8 @@ trait ITickBitmap<TContractState> {

#[starknet::contract]
mod TickBitmap {
use super::ITickBitmap;
use core::result::ResultTrait;
use super::ITickBitmap;
Copy link
Collaborator

Choose a reason for hiding this comment

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

format error. You should run make fmt before pushing

@@ -1,81 +1,131 @@
mod BitMathTests {
mod MostSignificantBit {
use integer::BoundedInt;
use core::result::ResultTrait;
use integer::BoundedInt;
Copy link
Collaborator

Choose a reason for hiding this comment

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

format error. You should run make fmt before pushing

}
}

mod LeastSignificantBit {
use integer::BoundedInt;
use core::result::ResultTrait;
use integer::BoundedInt;
Copy link
Collaborator

Choose a reason for hiding this comment

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

format error. You should run make fmt before pushing

Copy link
Collaborator

@uri-99 uri-99 left a comment

Choose a reason for hiding this comment

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

some missing #[available_gas()] attributes in #[tests]. It is important to evaluate gas consumption, to ensure there are no deadlocks.

use yas::libraries::bit_math::BitMath::most_significant_bit;

#[test]
fn msb_happy_path() {
fn msb_happy_path() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Suggested change
fn msb_happy_path() -> Result<u8, felt252> {
#[available_gas(200000000)]
fn msb_happy_path() -> Result<u8, felt252> {

Comment on lines 17 to 18
#[test]
fn msb_larger_number() {
fn msb_larger_number() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 27 to 28
#[test]
fn msb_bigger_number() {
fn msb_bigger_number() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 38 to 39
#[test]
fn msb_maximum_256() {
assert(most_significant_bit(BoundedInt::max()) == 255, 'msb should be 255');
fn msb_maximum_256() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 48 to 49
#[test]
fn msb_random_number() {
fn msb_random_number() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 82 to 83
#[test]
fn lsb_larger_number() {
fn lsb_larger_number() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 93 to 94
#[test]
fn lsb_bigger_number() {
fn lsb_bigger_number() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 104 to 105
#[test]
fn lsb_maximum_256() {
fn lsb_maximum_256() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 115 to 116
#[test]
fn lsb_random_number() {
fn lsb_random_number() -> Result<u8, felt252> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Comment on lines 127 to 129
#[test]
#[should_panic]
// #[should_panic]
fn lsb_number_zero() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

#[test] should contain #[available_gas()] attribute

Copy link
Collaborator

@uri-99 uri-99 left a comment

Choose a reason for hiding this comment

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

Tests should assert() different values regarding the functionality being tested; to ensure the functionality fails when it should fail and also to ensure that it doesn't fail when it shouldn't

if !(most_significant_bit(1).expect('msb errored') == 0 ) {
return Result::Err('msb should be 0');
}
return most_significant_bit(1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(most_significant_bit(128).expect('msb errored') == 7 ) {
return Result::Err('msb should be 7');
}
return most_significant_bit(128);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(most_significant_bit(1000000).expect('msb errored') == 19) {
return Result::Err('msb should be 19');
}
return most_significant_bit(1000000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(most_significant_bit(BoundedInt::max()).expect('msb errored') == 255) {
return Result::Err('msb should be 255');
}
return most_significant_bit(BoundedInt::max());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(most_significant_bit(12345).expect('msb errored') == 13) {
return Result::Err('msb should be 13');
}
return most_significant_bit(12345);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(ret.expect('lsb errored') == 0) {
return Result::Err('lsb should be 0');
}
return ret;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(z == 15) {
return Result::Err('z == 15');
}
return Result::Ok(z);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(z == 2) {
return Result::Err('z == 2');
}
return Result::Ok(z);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(z == 2) {
return Result::Err('z == 2');
}
return Result::Ok(z);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

if !(z == 2) {
return Result::Err('z == 2');
}
return Result::Ok(z);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a Test return a value?

@faytey
Copy link
Author

faytey commented Oct 19, 2023

So maybe I got the task wrong, I was asked to handle errors and replace all asserts, also to use the Result method for error handling. Please can you help explain the task properly so I do the correct thing please thanks

@rcatalan98
Copy link
Collaborator

So maybe I got the task wrong, I was asked to handle errors and replace all asserts, also to use the Result method for error handling. Please can you help explain the task properly so I do the correct thing please thanks

Hi @faytey! No problem maybe we weren't clear enough with the issue. The task is to refactor the listed function to return Result instead of having the assert in this library functions. So for testing this functions you will receive whatever the function returns and use patter matching to check if there was an error or not. This same strategy should be used by any function that calls the underlying library functions.

Is that clear?

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