File tree Expand file tree Collapse file tree 4 files changed +490
-471
lines changed Expand file tree Collapse file tree 4 files changed +490
-471
lines changed Original file line number Diff line number Diff line change 1+ import '@solana/test-matchers/toBeFrozenObject' ;
2+
13import { isSolanaError , SolanaError } from '../error' ;
24import { getErrorMessage } from '../message-formatter' ;
35
@@ -25,6 +27,9 @@ describe('SolanaError', () => {
2527 it ( 'calls the message formatter with the code and context' , ( ) => {
2628 expect ( getErrorMessage ) . toHaveBeenCalledWith ( 123 , expect . objectContaining ( { foo : 'bar' } ) ) ;
2729 } ) ;
30+ it ( 'freezes the context object' , ( ) => {
31+ expect ( errorWithContext . context ) . toBeFrozenObject ( ) ;
32+ } ) ;
2833 } ) ;
2934 describe ( 'given an error with no context' , ( ) => {
3035 beforeEach ( ( ) => {
Original file line number Diff line number Diff line change @@ -39,11 +39,17 @@ if (unknownError.context.__code === SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSIN
3939const e = null as unknown ;
4040if ( isSolanaError ( e ) ) {
4141 e . context satisfies Readonly < { __code : SolanaErrorCode } > ;
42+ // @ts -expect-error Code is read-only
43+ e . context . __code = SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING ;
4244}
4345if ( isSolanaError ( e , SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING ) ) {
4446 e . context satisfies SolanaErrorContext [ typeof SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING ] ;
4547 // @ts -expect-error Context belongs to another error code
4648 e . context satisfies SolanaErrorContext [ typeof SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING ] ;
49+ // @ts -expect-error Context is read-only
50+ e . context . addresses = [ ] as unknown as typeof e . context . addresses ;
51+ // @ts -expect-error Objects in context are read-only
52+ e . context . addresses . push ( 'abc' as unknown as ( typeof e . context . addresses ) [ number ] ) ;
4753}
4854
4955// `SolanaErrorContext` must not contain any keys reserved by `ErrorOptions` (eg. `cause`)
You can’t perform that action at this time.
0 commit comments