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 simulateTransaction RPC call #1526

Merged
merged 2 commits into from
Aug 25, 2023

Conversation

mcintyre94
Copy link
Collaborator

This PR adds the simulateTransaction RPC call to the experimental web3js

  • commitment and minContextSlot are optional, as in most of these configs. Note that here commitment defaults to finalized. Like with sendTransaction this means that tests specify the commitment because finalized may fail shortly after the validator starts up.
  • There are two mutually exclusive optional params: sigVerify and replaceRecentBlockhash, which both default to false. Their mutual exclusivity is enforced with types
  • An optional encoding parameter defaults to base58, but should be set to base64 since this is deprecated. As with sendTransaction this means that excluding the config object, or not setting encoding on it, is deprecated. Most tests use the base64 version and I haven't duplicated them all with the deprecated base58 one.
  • There's an optional accounts parameter which can be used to request account data for a subset of accounts involved in a transaction. This contains a list of addresses, and an encoding (unrelated to the transaction level one) for those accounts returned. This is responsible for most of the overloads, because this encoding affects the structure of the returned accounts. Note that base58 is not supported: https://github.com/solana-labs/solana/blob/7902ac106d1c537149b44143d080247a6ec85891/rpc/src/rpc.rs#L3774

The tests in this PR are modified from the sendTransaction ones, including the specific transaction structure used.

Ref #1449

@mcintyre94 mcintyre94 marked this pull request as draft August 22, 2023 11:21
@mcintyre94
Copy link
Collaborator Author

Moved this to draft - this API can return jsonParsed accounts so need to add to the allowed numeric accounts

Should probably do after #1528 to make it less annoying!

@mcintyre94 mcintyre94 marked this pull request as ready for review August 23, 2023 15:57
@buffalojoec
Copy link
Collaborator

lgtm but summoning @steveluscher

@steveluscher
Copy link
Collaborator

Their mutual exclusivity is enforced with types

<3

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.

giphy-2

Comment on lines 27 to 46
// Both are optional booleans, but conflict - so cannot both be true
type SigVerifyAndReplaceRecentBlockhashConfig =
| Readonly<{
/** if `true` the transaction signatures will be verified (conflicts with `replaceRecentBlockhash`) */
sigVerify: true;
/** if `true` the transaction recent blockhash will be replaced with the most recent blockhash. (conflicts with `sigVerify`) */
replaceRecentBlockhash?: false;
}>
| Readonly<{
/** if `true` the transaction recent blockhash will be replaced with the most recent blockhash. (conflicts with `sigVerify`) */
replaceRecentBlockhash: true;
/** if `true` the transaction signatures will be verified (conflicts with `replaceRecentBlockhash`) */
sigVerify?: false;
}>
| Readonly<{
/** if `true` the transaction signatures will be verified (conflicts with `replaceRecentBlockhash`) */
sigVerify?: false;
/** if `true` the transaction recent blockhash will be replaced with the most recent blockhash. (conflicts with `sigVerify`) */
replaceRecentBlockhash?: false;
}>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

damn-so-good-perfection


await expect(resultPromise).rejects.toMatchObject({
code: -32602 satisfies (typeof SolanaJsonRpcErrorCode)['JSON_RPC_INVALID_PARAMS'],
message: expect.stringContaining('failed to fill whole buffer'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

🙄

@mcintyre94 mcintyre94 force-pushed the simulate-tx branch 4 times, most recently from 69db34b to d9ffdf3 Compare August 25, 2023 11:39
value: expect.objectContaining({
accounts: [
expect.objectContaining({
// falls back to base64
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment is out of place, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops yep, removed!

@mcintyre94 mcintyre94 merged commit 7192f3d into solana-labs:master Aug 25, 2023
3 of 6 checks passed
@mcintyre94 mcintyre94 deleted the simulate-tx branch August 25, 2023 18:21
@github-actions
Copy link
Contributor

🎉 This PR is included in version 1.78.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@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 Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants