-
Notifications
You must be signed in to change notification settings - Fork 800
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
Add functions to narrow instructions to IInstructionWithAccounts
and IInstructionWithData
#2212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits but I think this is valuable.
packages/errors/src/messages.ts
Outdated
[SOLANA_ERROR__EXPECTED_INSTRUCTION_TO_HAVE_ACCOUNTS]: | ||
'The instruction with program address `$programAddress` and data `$data` does not have any accounts.', | ||
[SOLANA_ERROR__EXPECTED_INSTRUCTION_TO_HAVE_DATA]: | ||
'The instruction with program address `$programAddress` and accounts `$accountAddresses` does not have any data.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't know for sure that an account without data has accounts and vice versa, I wouldn't explicitly add them in the error message. I think it's fine to have in the context if someone wants to check their values but would be confusing in the error message for instruction that have neither.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's what I was missing, I thought context was just about getting values into the error message but it's displayed separately too. Agreed, I'll remove the accounts/data from the messages and just include them in context.
13f8a02
to
3607732
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('interpolates a Uint8Array variable into a error message format string', () => { | ||
const messagesSpy = jest.spyOn(MessagesModule, 'SolanaErrorMessages', 'get'); | ||
messagesSpy.mockReturnValue({ | ||
// @ts-expect-error Mock error config doesn't conform to exported config. | ||
123: 'Here is some data: $data', | ||
}); | ||
const message = getErrorMessage( | ||
// @ts-expect-error Mock error context doesn't conform to exported context. | ||
123, | ||
{ data: new Uint8Array([1, 2, 3, 4]) }, | ||
); | ||
expect(message).toBe('Here is some data: 1,2,3,4'); | ||
}); | ||
it('interpolates an undefined variable into a error message format string', () => { | ||
const messagesSpy = jest.spyOn(MessagesModule, 'SolanaErrorMessages', 'get'); | ||
messagesSpy.mockReturnValue({ | ||
// @ts-expect-error Mock error config doesn't conform to exported config. | ||
123: 'Here is a variable: $variable', | ||
}); | ||
const message = getErrorMessage( | ||
// @ts-expect-error Mock error context doesn't conform to exported context. | ||
123, | ||
{ variable: undefined }, | ||
); | ||
expect(message).toBe('Here is a variable: undefined'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
840b11d
to
4695dd0
Compare
🎉 This PR is included in version 1.90.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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. |
Our
IInstruction
type may not include accounts/data. When we serialize a transaction we only know that it hasinstructions: IInstruction[]
The generated Kinobi clients sensibly require data to identify eg a system instruction:
And accounts and data to parse one:
This PR adds functions to narrow the type of an
IInstruction
toIInstruction & IInstructionWithAccounts
andIInstruction & IInstructionWithData
This will allow code using generated clients to do eg:
Notes: