@@ -17,6 +17,7 @@ describe('txSubmitHttpProvider', () => {
1717 await expect ( provider . healthCheck ( ) ) . resolves . toEqual ( { ok : false } ) ;
1818 } ) ;
1919 } ) ;
20+ // eslint-disable-next-line sonarjs/cognitive-complexity
2021 describe ( 'mocked' , ( ) => {
2122 let axiosMock : MockAdapter ;
2223 beforeAll ( ( ) => {
@@ -53,37 +54,55 @@ describe('txSubmitHttpProvider', () => {
5354 } ) ;
5455
5556 describe ( 'errors' , ( ) => {
56- const testError = ( bodyError : Error , providerErrorType : unknown ) => async ( ) => {
57- try {
58- axiosMock . onPost ( ) . replyOnce ( ( ) => {
59- throw axiosError ( bodyError ) ;
60- } ) ;
61- const provider = txSubmitHttpProvider ( config ) ;
62- await provider . submitTx ( { signedTransaction : emptyUintArrayAsHexString } ) ;
63- throw new Error ( 'Expected to throw' ) ;
64- } catch ( error ) {
65- if ( error instanceof ProviderError ) {
66- expect ( error . reason ) . toBe ( ProviderFailure . BadRequest ) ;
67- const innerError = error . innerError as Cardano . TxSubmissionError ;
68- expect ( innerError ) . toBeInstanceOf ( providerErrorType ) ;
69- } else {
70- throw new TypeError ( 'Expected ProviderError' ) ;
57+ const testError =
58+ ( bodyError : Error , providerFailure : ProviderFailure , providerErrorType : unknown ) => async ( ) => {
59+ try {
60+ axiosMock . onPost ( ) . replyOnce ( ( ) => {
61+ throw axiosError ( bodyError ) ;
62+ } ) ;
63+ const provider = txSubmitHttpProvider ( config ) ;
64+ await provider . submitTx ( { signedTransaction : emptyUintArrayAsHexString } ) ;
65+ throw new Error ( 'Expected to throw' ) ;
66+ } catch ( error ) {
67+ if ( error instanceof ProviderError ) {
68+ expect ( error . reason ) . toBe ( providerFailure ) ;
69+ const innerError = error . innerError as Cardano . TxSubmissionError ;
70+ expect ( innerError ) . toBeInstanceOf ( providerErrorType ) ;
71+ } else {
72+ throw new TypeError ( 'Expected ProviderError' ) ;
73+ }
7174 }
72- }
73- } ;
75+ } ;
7476
7577 it (
7678 'rehydrates errors' ,
7779 testError (
7880 new Cardano . TxSubmissionErrors . BadInputsError ( { badInputs : [ ] } ) ,
81+ ProviderFailure . BadRequest ,
7982 Cardano . TxSubmissionErrors . BadInputsError
8083 )
8184 ) ;
8285
8386 it (
8487 'maps unrecognized errors to UnknownTxSubmissionError' ,
85- testError ( new Error ( 'Unknown error' ) , Cardano . UnknownTxSubmissionError )
88+ testError ( new Error ( 'Unknown error' ) , ProviderFailure . Unknown , Cardano . UnknownTxSubmissionError )
8689 ) ;
90+
91+ it ( 'does not re-wrap UnknownTxSubmissionError' , async ( ) => {
92+ expect . assertions ( 3 ) ;
93+ axiosMock . onPost ( ) . replyOnce ( ( ) => {
94+ throw axiosError ( new Cardano . UnknownTxSubmissionError ( 'Unknown error' ) ) ;
95+ } ) ;
96+ const provider = txSubmitHttpProvider ( config ) ;
97+ try {
98+ await provider . submitTx ( { signedTransaction : emptyUintArrayAsHexString } ) ;
99+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
100+ } catch ( error : any ) {
101+ expect ( error ) . toBeInstanceOf ( ProviderError ) ;
102+ expect ( error . innerError ) . toBeInstanceOf ( Cardano . UnknownTxSubmissionError ) ;
103+ expect ( error . innerError . innerError . name ) . not . toBe ( Cardano . UnknownTxSubmissionError . name ) ;
104+ }
105+ } ) ;
87106 } ) ;
88107 } ) ;
89108 } ) ;
0 commit comments