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

Improved schema validation for eth_getBalance #598

Merged
merged 7 commits into from
Oct 29, 2024

Conversation

cygnusv
Copy link
Member

@cygnusv cygnusv commented Oct 18, 2024

Type of PR:

  • Bugfix
  • Feature
  • Documentation
  • Other

Required reviews:

  • 1
  • 2
  • 3

What this does:

High-level idea of the changes introduced in this PR. List relevant API
changes (if any), as well as related PRs and issues.

Issues fixed/closed:

  • Fixes #...

Why it's needed:

Explain how this PR fits in the greater context of the NuCypher Network. E.g.,
if this PR address a nucypher/productdev issue, let reviewers know!

Notes for reviewers:

What should reviewers focus on? Is there a particular commit/function/section
of your PR that requires more attention from reviewers?

* Allow any type of context variable for the eth address parameter
* The non-empty array is not an acceptable schema for parameters. What we want is a one-element tuple
@cygnusv cygnusv changed the base branch from main to epic-v0.6.x October 18, 2024 15:33
Copy link

netlify bot commented Oct 18, 2024

Deploy Preview for taco-demo canceled.

Name Link
🔨 Latest commit 0d750e4
🔍 Latest deploy log https://app.netlify.com/sites/taco-demo/deploys/67127fd7eaba4200083e5056

Copy link

netlify bot commented Oct 18, 2024

Deploy Preview for taco-nft-demo canceled.

Name Link
🔨 Latest commit 0d750e4
🔍 Latest deploy log https://app.netlify.com/sites/taco-nft-demo/deploys/67127fd7cb6ea10008709f5d

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (epic-v0.6.x@fcdb1da). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             epic-v0.6.x     #598   +/-   ##
==============================================
  Coverage               ?   89.19%           
==============================================
  Files                  ?       73           
  Lines                  ?     6498           
  Branches               ?      345           
==============================================
  Hits                   ?     5796           
  Misses                 ?      664           
  Partials               ?       38           

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

@cygnusv cygnusv marked this pull request as ready for review October 24, 2024 16:50
@@ -6,7 +6,8 @@ import { plainStringSchema } from './common';

export const contextParamSchema = z.string().regex(CONTEXT_PARAM_REGEXP);

const paramSchema = z.union([plainStringSchema, z.boolean(), z.number()]);
// TODO: This is too broad, but it's a start
const paramSchema = z.union([plainStringSchema, z.boolean(), z.number().int().nonnegative()]);
Copy link
Member

Choose a reason for hiding this comment

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

Is there ever a case for negative numbers?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, it is indeed acceptable (int256 type and friends). Fixed in b3902d4

Copy link
Member

@derekpierre derekpierre Oct 25, 2024

Choose a reason for hiding this comment

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

I was thinking about this some more. Perhaps we need to separate this schema into two parts.

  1. What is allowed for blockchain RPC / smart contract calls
  2. What is generally allowed

The original goal of the paraSchema on L9 was 2), but we are now limiting it to 1).

Solidity doesn't have floating point numbers, so limiting it to z.number().int() is fine. However, a JsonApiCondition can require floating point numbers. For example, the paramOrContextParamSchema is used for the value used for the returnValueTest () - and for a JSON API, checking a floating point number is perfectly fine, but now it won't be; typified by the fact that I saw you had to modify the floating point test.

Copy link
Member

Choose a reason for hiding this comment

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

^ @cygnusv wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, I was actually reverting my changes as we speak. Let's just put a pin on this so we can unblock the PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #600

Copy link
Member

@manumonti manumonti left a comment

Choose a reason for hiding this comment

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

LGTM! 👌

Copy link
Member

@derekpierre derekpierre left a comment

Choose a reason for hiding this comment

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

🎸

@cygnusv cygnusv merged commit 3b67142 into nucypher:epic-v0.6.x Oct 29, 2024
4 checks passed
@derekpierre derekpierre mentioned this pull request Nov 8, 2024
16 tasks
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.

4 participants