-
Notifications
You must be signed in to change notification settings - Fork 323
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
Update structs-exercise.md Data type warning #177
Conversation
I've run into an error in the automated tests, specifically regarding the Car struct. The tests seem to expect a `uint256` for the `numberOfDoors` declaration, causing a somewhat cryptic "wrong signature" error. Given the exercises leading up to this point, it's intuitive to lean towards the smallest uint, like `uint8` given that several fellow learners at #basecamp-chat on discord and myself have faced this, and I propose the warning in my Pr to address this.
Thanks for taking the time to open this PR! Will leave this open until our team has an opportunity to review. |
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.
Hi @RenierC, thanks for taking the time to write this!
The exercise is actually structured this way on purpose, so that the learner is tested to see if they understand when using a uint8 will have a gas advantage in packing, and when (such as in this case) a uint8 is the incorrect choice, since there is no packing and the VM has to cast it to 32 bytes every time it operates on it.
But given the recent conversations, I do agree that some tuning is necessary. Do you mind trying to think of a subtler hint to put in the Car Struct section?
Review Error for briandoyle81CB @ 2023-12-07 16:58:22 UTC |
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.
Didn't do mfa, please see comment above
@briandoyle81CB You're welcome! and thx for clarifying this, I remember that when you hinted this at me on the discord I read 2 docs that pushed me in the right direction, I set up a spoiler at the bottom with those resources and made it more subtle in the new commits and removed the previous warning I made. Closed spoilerOpen spoilerThe urls take you here https://docs.soliditylang.org/en/v0.8.17/internals/layout_in_storage.html#layout-of-state-variables-in-storage and here https://docs.base.org/base-camp/docs/structs/structs-sbs/#setting-up-the-struct Let me know what you think and if I need to improve on this 😉. |
Perfect, thank you! |
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.
Thanks!
* Update structs-exercise.md Data type warning I've run into an error in the automated tests, specifically regarding the Car struct. The tests seem to expect a `uint256` for the `numberOfDoors` declaration, causing a somewhat cryptic "wrong signature" error. Given the exercises leading up to this point, it's intuitive to lean towards the smallest uint, like `uint8` given that several fellow learners at #basecamp-chat on discord and myself have faced this, and I propose the warning in my Pr to address this. * adds spoiler for struct exercise
What changed? Why?
Adding a new message at the end of the exercise to avoid future errors. (just a proposal we can change the copy if needed be).
Notes to reviewers
I've run into an error in the automated tests, specifically regarding the Car struct. The tests seem to expect a
uint256
for thenumberOfDoors
declaration, causing a somewhat cryptic "wrong signature" error.Given the exercises leading up to this point, it's intuitive to lean towards the smallest uint, like
uint8
given that several fellow learners at #basecamp-chat on discord and myself have faced this, and I propose the warning in my Pr to address this.How has it been tested?
Tried to submit a contract with
uint8
in thestruct
, it gave a cryptic error and then I just changed it touint256
and it passed.