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

Validate allowance expiration #792

Closed
wants to merge 6 commits into from
Closed

Conversation

chipshort
Copy link
Contributor

Closes #628

Adds a check for valid expiration when increasing or decreasing allowance.
Also had to change some of the tests because they were creating expired allowances to test the expiration checks of the other message handlers.

@CLAassistant
Copy link

CLAassistant commented Sep 5, 2022

CLA assistant check
All committers have signed the CLA.

@ueco-jb ueco-jb requested a review from 0xFable September 5, 2022 13:19
Copy link
Contributor

@uint uint left a comment

Choose a reason for hiding this comment

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

Looks good in general, just one suggestion.

Nice tests!

let mut val = allow.unwrap_or_default();
if let Some(exp) = expires {
if exp.is_expired(&env.block) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You found this helper instead of writing the check yourself. Nice!

let mut val = allow.unwrap_or_default();
if let Some(exp) = expires {
if exp.is_expired(&env.block) {
return Err(ContractError::Expired {});
Copy link
Contributor

Choose a reason for hiding this comment

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

More a suggestion than a blocker. I think what we want is more a validation error, just to be clearer to the user/consumer. The problem isn't that an existing allowance is expired, the problem is the user is trying to create/modify an allowance so that it expires in the past.

I'd add a new error variant here:
https://github.com/CosmWasm/cw-plus/blob/main/contracts/cw20-base/src/error.rs

@uint
Copy link
Contributor

uint commented Sep 5, 2022

For some reason CircleCI is not picking up this branch. Let's figure that out...

@chipshort
Copy link
Contributor Author

Closing this, as it is a part of #793 and the ci picked that one up.

@chipshort chipshort closed this Sep 5, 2022
@chipshort chipshort deleted the validate-allowance-expiration branch September 5, 2022 15:07
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.

cw20 allowance expiration can be set to a block height or timestamp in the past
3 participants