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

fix: return an error on invalid voter address #733

Merged
merged 1 commit into from
Oct 28, 2023

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Oct 27, 2023

Fail early and return meaningful when voter address is invalid on vp query

Before, when passing 0x0000000000000000000000000000000000000000 or `` as voter, it calls score-api then returns:

{
  "errors": [
    {
      "message": "Unexpected error value: { code: 400, message: \"unauthorized\", data: \"invalid address\" }",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "vp"
      ]
    }
  ],
  "data": {
    "vp": null
  }
}

Now, it should return the error without calling score-api

{
  "errors": [
    {
      "message": "invalid address",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "vp"
      ]
    }
  ],
  "data": {
    "vp": null
  }
}

Test with following query

query Vp{
		vp(
			space: "rocketpool-dao.eth",
			voter: "0x0000000000000000000000000000000000000000",
		) {
			vp
		}
	}
	

@wa0x6e wa0x6e requested a review from ChaituVR October 27, 2023 15:28
Comment on lines +7 to +9
if (voter === '0x0000000000000000000000000000000000000000' || voter === '') {
return Promise.reject(new Error('invalid address'));
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also better to check getAddress to check checksum

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but this will require adding a address dependency

Copy link
Member

@ChaituVR ChaituVR left a comment

Choose a reason for hiding this comment

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

utAck

@wa0x6e wa0x6e merged commit efe8f61 into master Oct 28, 2023
2 checks passed
@wa0x6e wa0x6e deleted the filter-out-invalid-address-in-vp branch October 28, 2023 05:21
@sentry-io
Copy link

sentry-io bot commented Oct 28, 2023

Sentry issue: SNAPSHOT-HUB-1K

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.

2 participants