-
Notifications
You must be signed in to change notification settings - Fork 24
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
Error handling #133
Conversation
There was a problem hiding this 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
src/contracts/yas_pool.cairo
Outdated
@@ -25,7 +25,8 @@ trait IYASPool<TContractState> { | |||
|
|||
#[starknet::contract] | |||
mod YASPool { | |||
use super::IYASPool; | |||
use core::result::ResultTrait; | |||
use super::IYASPool; |
There was a problem hiding this comment.
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
src/libraries/tick.cairo
Outdated
@@ -74,7 +73,8 @@ trait ITick<TContractState> { | |||
|
|||
#[starknet::contract] | |||
mod Tick { | |||
use super::{ITick, Info}; | |||
use core::result::ResultTrait; | |||
use super::{ITick, Info}; |
There was a problem hiding this comment.
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
src/libraries/tick_bitmap.cairo
Outdated
@@ -10,7 +10,8 @@ trait ITickBitmap<TContractState> { | |||
|
|||
#[starknet::contract] | |||
mod TickBitmap { | |||
use super::ITickBitmap; | |||
use core::result::ResultTrait; | |||
use super::ITickBitmap; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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
fn msb_happy_path() -> Result<u8, felt252> { | |
#[available_gas(200000000)] | |
fn msb_happy_path() -> Result<u8, felt252> { |
#[test] | ||
fn msb_larger_number() { | ||
fn msb_larger_number() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
fn msb_bigger_number() { | ||
fn msb_bigger_number() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
fn msb_maximum_256() { | ||
assert(most_significant_bit(BoundedInt::max()) == 255, 'msb should be 255'); | ||
fn msb_maximum_256() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
fn msb_random_number() { | ||
fn msb_random_number() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
fn lsb_larger_number() { | ||
fn lsb_larger_number() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
fn lsb_bigger_number() { | ||
fn lsb_bigger_number() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
fn lsb_maximum_256() { | ||
fn lsb_maximum_256() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
fn lsb_random_number() { | ||
fn lsb_random_number() -> Result<u8, felt252> { |
There was a problem hiding this comment.
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
#[test] | ||
#[should_panic] | ||
// #[should_panic] | ||
fn lsb_number_zero() { |
There was a problem hiding this comment.
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
There was a problem hiding this 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
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 Is that clear? |
0421a94
to
88a08d1
Compare
A draft of the error-handling techniques used for testing purposes, kindly let me know if the method used so far is acceptable. Thanks