-
Notifications
You must be signed in to change notification settings - Fork 353
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
Improve tests #864
Improve tests #864
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.
Great work, Eric! I left a few minor comments, suggestions, and questions
use core::fmt::{Debug, Formatter, Error}; | ||
use starknet::{ContractAddress, ClassHash}; | ||
|
||
impl DebugContractAddress of core::fmt::Debug<ContractAddress> { | ||
fn fmt(self: @ContractAddress, ref f: Formatter) -> Result<(), Error> { | ||
let address: felt252 = (*self).into(); | ||
write!(f, "{address:?}") | ||
} | ||
} | ||
|
||
impl DebugClassHash of core::fmt::Debug<ClassHash> { | ||
fn fmt(self: @ClassHash, ref f: Formatter) -> Result<(), Error> { | ||
let hash: felt252 = (*self).into(); | ||
write!(f, "{hash:?}") | ||
} | ||
} |
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.
👍
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.
Also, should we document this addition in the CHANGELOG?
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.
Not sure if we should add test stuff in the changelog. Actually, I think we shouldn't, even when I added a couple of entries already. I think changelog should be for API-related stuff of the library, not including testing, what do you think?
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.
If you agree I will remove the test-related entries already added.
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.
Yeah, I agree with not including testing
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.
cc @martriay
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.
agreed offline to focus on relevant API changes, albeit with some flexibility analyzing case by case
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
…tracts into feat/improve-tests
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.
I left a final suggestion and I agree with removing the test items in the changelog. I guess we should also remove the use ComponentState in tests
as well?
Co-authored-by: Andrew Fleming <fleming.andrew@protonmail.com>
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.
Great improvements! The library, and therefore the world, is now a bit better thanks to this PR :)
use core::fmt::{Debug, Formatter, Error}; | ||
use starknet::{ContractAddress, ClassHash}; | ||
|
||
impl DebugContractAddress of core::fmt::Debug<ContractAddress> { | ||
fn fmt(self: @ContractAddress, ref f: Formatter) -> Result<(), Error> { | ||
let address: felt252 = (*self).into(); | ||
write!(f, "{address:?}") | ||
} | ||
} | ||
|
||
impl DebugClassHash of core::fmt::Debug<ClassHash> { | ||
fn fmt(self: @ClassHash, ref f: Formatter) -> Result<(), Error> { | ||
let hash: felt252 = (*self).into(); | ||
write!(f, "{hash:?}") | ||
} | ||
} |
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.
agreed offline to focus on relevant API changes, albeit with some flexibility analyzing case by case
src/tests/presets/test_account.cairo
Outdated
assert!(supports_isrc5); | ||
assert!(supports_isrc6); |
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 not asserting right after each query? this is the least important optimization but we can save us a call in case isrc5 fails early -- that's actually a guideline we try to follow in our contracts: fail early and loud
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.
Good point, I will update it.
let supports_isrc5 = dispatcher.supports_interface(ISRC5_ID); | ||
let supports_isrc6 = dispatcher.supports_interface(ISRC6_ID); | ||
let doesnt_support_0x123 = !dispatcher.supports_interface(0x123); | ||
assert!(supports_isrc5); | ||
assert!(supports_isrc6); | ||
assert!(doesnt_support_0x123); |
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.
we should settle on a query/assert order pattern. in here it's all queries then asserts, in the previous test it's mixed, and there's also query/assert pairs
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.
Asserting right after each query as you suggested looks like the best approach to me.
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.
added a comment in the style guidelines issue
Fixes #670 #820
See this comment for assertion guidelines.
This PR also removes the
#[available_gas]
attributes.PR Checklist