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

Unable to use JSON RPC #495

Closed
Karrq opened this issue Mar 5, 2022 · 9 comments · Fixed by #496
Closed

Unable to use JSON RPC #495

Karrq opened this issue Mar 5, 2022 · 9 comments · Fixed by #496
Labels
bug Something isn't working
Milestone

Comments

@Karrq
Copy link

Karrq commented Mar 5, 2022

Hi, I was interested in trying this tool to make a series of requests easily reproducible or parametrized but I was stuck immediately when attempting to make a json rpc request.

Here's the sample:

POST https://rpc.flashbots.net/
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "eth_getBlockByNumber",
    "params": ["0x5E3A3F", true]
}

When running with hurl file.hurl I get the following error:

error: Parsing json
  --> file.hurl:6:14
   |
 6 |     "params": ["0x5E3A3F", true]
   |              ^ json error
   |

But I tried to verify this payload and had no issue with it, even using it in postman without any trouble... Am I missing something here?

@fabricereix
Copy link
Collaborator

Hello @Karrq,
For JSON parsing, we have added the check that all items in an array should have the same type.
Can you use this payload instead?

POST https://rpc.flashbots.net/
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "eth_getBlockByNumber",
    "params": ["0x5E3A3F", "true"]
}

We need to check if this extra restriction is common and really makes sense. If not we will remove it.

@fabricereix
Copy link
Collaborator

It seems indeed that each element in an array may be of a different type.
A unique type can be enforced with a JSON schema validation.
Thanks for reporting it, we will remove this restriction in the next release.

@fabricereix fabricereix added the bug Something isn't working label Mar 5, 2022
@fabricereix fabricereix added this to the 1.7.0 milestone Mar 5, 2022
@Karrq
Copy link
Author

Karrq commented Mar 5, 2022 via email

@fabricereix
Copy link
Collaborator

Until the next release, you can send your exact payload with a mutiline string

POST https://rpc.flashbots.net/
```
{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "eth_getBlockByNumber",
    "params": ["0x5E3A3F", true]
}
```

The JSON won't be decoded by Hurl.

I'm not familiar with JSON-RPC. What kind of feature would you like?

@fabricereix
Copy link
Collaborator

Hi @Karrq,
I'm closing the issue, The fix has been merged in #496

@jcamiel jcamiel reopened this Apr 1, 2022
@jcamiel jcamiel linked a pull request Apr 1, 2022 that will close this issue
@jcamiel jcamiel closed this as completed Apr 1, 2022
@huangjj27
Copy link

If I need to check the types of the elements in an array are the same, how do I do this?

@jcamiel
Copy link
Collaborator

jcamiel commented Sep 17, 2022

Hi, you can use isInteger isFloat isString isCollection predicates and explicitely asserts all items:

GET http://api.foo.com

HTTP/* 200
[Asserts]
jsonpath "$.books[0]" isString
jsonpath "$.books[1]" isString
jsonpath "$.books[2]" isString

We'll improve this with in a future version an any, all none keywords,

https://hurl.dev/docs/asserting-response.html#predicates

@huangjj27
Copy link

huangjj27 commented Sep 17, 2022

Hi, you can use isInteger isFloat isString isCollection predicates and explicitely asserts all items:

But in the practical sense, the elements in an array usually are complex structures of the same type. It's hard to predict in such sense.

@fabricereix
Copy link
Collaborator

fabricereix commented Sep 17, 2022

you might probably be happy with a schema validation (#543)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants