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

refactor(experimental): add unit tests for getAccountInfo RPC method #1381

Merged
merged 1 commit into from
Jul 7, 2023

Conversation

mcintyre94
Copy link
Collaborator

This PR adds unit tests for the getAccountInfo RPC call. I'm probably going to end up refactoring this a bit to add getMultipleAccounts and getProgramAccounts so I want some tests first

Note that I've been unable to test the jsonParsed fully. I tried copying the data from a mainnet stake account (where jsonParsed works) into a fixture, but requesting jsonParsed encoding just returns the base64 encoding. I'm not sure if the test validator is missing the parsers?

Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

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

I love this! Take another crack at the jsonParsed encoding, maybe?

describe('for an account with parse-able JSON data', () => {
// TODO: not sure how to do this in the test validator
// Creating an account with data from a mainnet stake account doesn't work
// I think the testnet validator might not have the parsers?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I just tried this and it worked.

  1. Find an account that definitely parses on mainnet (eg. CSg2vQGbnwWdSyJpwK4i3qGfB6FebaV3xQTx4U1MbixN)
  2. solana-test-validator -u m --clone CSg2vQGbnwWdSyJpwK4i3qGfB6FebaV3xQTx4U1MbixN
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getAccountInfo",
    "params": [
      "CSg2vQGbnwWdSyJpwK4i3qGfB6FebaV3xQTx4U1MbixN",
      { "encoding": "jsonParsed" }
    ]
  }
'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the pointer! Figured it out, I was using the wrong owner in the fixture and I guess it uses that to figure out how to parse the account. Makes sense!

@mcintyre94 mcintyre94 merged commit 3d43623 into solana-labs:master Jul 7, 2023
6 checks passed
@mcintyre94 mcintyre94 deleted the get-account-info-tests branch July 7, 2023 10:41
@github-actions
Copy link
Contributor

Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants