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

feat: add simple address validity check #1303

Merged
merged 9 commits into from
Oct 28, 2023

Conversation

leohhhn
Copy link
Contributor

@leohhhn leohhhn commented Oct 26, 2023

Description

This PR adds a simple Valid() check to the Address type. It is there to prevent most human errors, and doesn't actually validate the math behind bech32 (for now) - it relies only on the length of the address.

Running gno test . will run the unit test for the Valid() function.
Closes: #1298

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@leohhhn leohhhn requested review from jaekwon, moul and a team as code owners October 26, 2023 16:14
@github-actions github-actions bot added 🧾 package/realm Tag used for new Realms or Packages. 📦 🤖 gnovm Issues or PRs gnovm related labels Oct 26, 2023
@github-actions github-actions bot removed the 🧾 package/realm Tag used for new Realms or Packages. label Oct 26, 2023
@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7105d00) 47.93% compared to head (1fb7ab6) 47.89%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1303      +/-   ##
==========================================
- Coverage   47.93%   47.89%   -0.05%     
==========================================
  Files         372      372              
  Lines       62990    62990              
==========================================
- Hits        30192    30166      -26     
- Misses      30341    30360      +19     
- Partials     2457     2464       +7     

see 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@harry-hov harry-hov left a comment

Choose a reason for hiding this comment

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

LGTM 💯

I just wonder if we can get rid of these in the same PR:

func checkIsValidAddress(addr std.Address) error {
if addr.String() == "" {
return ErrInvalidAddress
}
return nil
}

func isValidAddress(addr std.Address) error {
if addr.String() == "" {
return ErrInvalidAddress
}
return nil
}

func isValidAddress(addr std.Address) bool {
if addr.String() == "" {
return false
}
return true
}

Copy link
Member

@zivkovicmilos zivkovicmilos 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 💯

gnovm/stdlibs/std/crypto.gno Outdated Show resolved Hide resolved
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Oct 26, 2023
go.mod Outdated
Comment on lines 6 to 8
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c
github.com/btcsuite/btcd v0.22.3
github.com/btcsuite/btcd/btcutil v1.0.0
github.com/btcsuite/btcutil v1.0.2
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
Copy link
Member

Choose a reason for hiding this comment

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

Ehh, I'd say upgrading btcd/btcutil is something that should be done in another PR, especially considering #1064

I'd suggest reverting changes here + go.sum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was accidental, sorry. Will revert them :)

Copy link
Member

@moul moul Oct 27, 2023

Choose a reason for hiding this comment

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

Oops, my mistake. I attempted to fix the previous commit but didn't thoroughly check it.

Edit: nope, was introduced before my commit; I'll fix now.

Signed-off-by: moul <94029+moul@users.noreply.github.com>
@moul moul merged commit 199cd29 into gnolang:master Oct 28, 2023
190 checks passed
gfanton pushed a commit to gfanton/gno that referenced this pull request Nov 9, 2023
## Description

This PR adds a simple `Valid()` check to the Address type. It is there
to prevent most human errors, and doesn't actually validate the math
behind bech32 (for now) - it relies only on the length of the address.

Running `gno test .` will run the unit test for the `Valid()` function.
Closes: gnolang#1298 

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: moul <94029+moul@users.noreply.github.com>
moul added a commit to moul/gno that referenced this pull request Nov 14, 2023
## Description

This PR adds a simple `Valid()` check to the Address type. It is there
to prevent most human errors, and doesn't actually validate the math
behind bech32 (for now) - it relies only on the length of the address.

Running `gno test .` will run the unit test for the `Valid()` function.
Closes: gnolang#1298 

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Signed-off-by: moul <94029+moul@users.noreply.github.com>
Co-authored-by: moul <94029+moul@users.noreply.github.com>
@leohhhn leohhhn deleted the feat/add-valid-address branch March 20, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: 🌟 Wanted for Launch
Archived in project
Development

Successfully merging this pull request may close these issues.

Add better UX for checking if a Gno address is mathematically valid
5 participants