@@ -5,19 +5,20 @@ import {
55 SERVER_ERROR_CODE ,
66 CUSTOM_ERROR_CODE ,
77} from './__fixtures__' ;
8- import { ethErrors , errorCodes } from '.' ;
8+ import { providerErrors } from './errors' ;
9+ import { rpcErrors , errorCodes } from '.' ;
910
10- describe ( 'ethErrors.rpc .invalidInput' , ( ) => {
11+ describe ( 'rpcErrors .invalidInput' , ( ) => {
1112 it ( 'accepts a single string argument where appropriate' , ( ) => {
12- const err = ethErrors . rpc . invalidInput ( CUSTOM_ERROR_MESSAGE ) ;
13+ const err = rpcErrors . invalidInput ( CUSTOM_ERROR_MESSAGE ) ;
1314 expect ( err . code ) . toBe ( errorCodes . rpc . invalidInput ) ;
1415 expect ( err . message ) . toBe ( CUSTOM_ERROR_MESSAGE ) ;
1516 } ) ;
1617} ) ;
1718
18- describe ( 'ethErrors.provider .unauthorized' , ( ) => {
19+ describe ( 'providerErrors .unauthorized' , ( ) => {
1920 it ( 'accepts a single string argument where appropriate' , ( ) => {
20- const err = ethErrors . provider . unauthorized ( CUSTOM_ERROR_MESSAGE ) ;
21+ const err = providerErrors . unauthorized ( CUSTOM_ERROR_MESSAGE ) ;
2122 expect ( err . code ) . toBe ( errorCodes . provider . unauthorized ) ;
2223 expect ( err . message ) . toBe ( CUSTOM_ERROR_MESSAGE ) ;
2324 } ) ;
@@ -27,7 +28,7 @@ describe('custom provider error options', () => {
2728 it ( 'throws if the value is not an options object' , ( ) => {
2829 expect ( ( ) => {
2930 // @ts -expect-error Invalid input
30- ethErrors . provider . custom ( 'bar' ) ;
31+ providerErrors . custom ( 'bar' ) ;
3132 } ) . toThrow (
3233 'Ethereum Provider custom errors must provide single object argument.' ,
3334 ) ;
@@ -36,11 +37,11 @@ describe('custom provider error options', () => {
3637 it ( 'throws if the value is invalid' , ( ) => {
3738 expect ( ( ) => {
3839 // @ts -expect-error Invalid input
39- ethErrors . provider . custom ( { code : 4009 , message : 2 } ) ;
40+ providerErrors . custom ( { code : 4009 , message : 2 } ) ;
4041 } ) . toThrow ( '"message" must be a nonempty string' ) ;
4142
4243 expect ( ( ) => {
43- ethErrors . provider . custom ( { code : 4009 , message : '' } ) ;
44+ providerErrors . custom ( { code : 4009 , message : '' } ) ;
4445 } ) . toThrow ( '"message" must be a nonempty string' ) ;
4546 } ) ;
4647} ) ;
@@ -49,24 +50,24 @@ describe('ethError.rpc.server', () => {
4950 it ( 'throws on invalid input' , ( ) => {
5051 expect ( ( ) => {
5152 // @ts -expect-error Invalid input
52- ethErrors . rpc . server ( 'bar' ) ;
53+ rpcErrors . server ( 'bar' ) ;
5354 } ) . toThrow (
5455 'Ethereum RPC Server errors must provide single object argument.' ,
5556 ) ;
5657
5758 expect ( ( ) => {
5859 // @ts -expect-error Invalid input
59- ethErrors . rpc . server ( { code : 'bar' } ) ;
60+ rpcErrors . server ( { code : 'bar' } ) ;
6061 } ) . toThrow ( '"code" must be an integer such that: -32099 <= code <= -32005' ) ;
6162
6263 expect ( ( ) => {
63- ethErrors . rpc . server ( { code : 1 } ) ;
64+ rpcErrors . server ( { code : 1 } ) ;
6465 } ) . toThrow ( '"code" must be an integer such that: -32099 <= code <= -32005' ) ;
6566 } ) ;
6667} ) ;
6768
68- describe ( 'ethError.rpc ' , ( ) => {
69- it . each ( Object . entries ( ethErrors . rpc ) . filter ( ( [ key ] ) => key !== 'server' ) ) (
69+ describe ( 'rpcErrors ' , ( ) => {
70+ it . each ( Object . entries ( rpcErrors ) . filter ( ( [ key ] ) => key !== 'server' ) ) (
7071 '%s returns appropriate value' ,
7172 ( key , value ) => {
7273 const createError = value as any ;
@@ -86,7 +87,7 @@ describe('ethError.rpc', () => {
8687 ) ;
8788
8889 it ( 'server returns appropriate value' , ( ) => {
89- const error = ethErrors . rpc . server ( {
90+ const error = rpcErrors . server ( {
9091 code : SERVER_ERROR_CODE ,
9192 data : Object . assign ( { } , dummyData ) ,
9293 } ) ;
@@ -96,24 +97,25 @@ describe('ethError.rpc', () => {
9697 } ) ;
9798} ) ;
9899
99- describe ( 'ethError.provider' , ( ) => {
100- it . each (
101- Object . entries ( ethErrors . provider ) . filter ( ( [ key ] ) => key !== 'custom' ) ,
102- ) ( '%s returns appropriate value' , ( key , value ) => {
103- const createError = value as any ;
104- const error = createError ( {
105- message : null ,
106- data : Object . assign ( { } , dummyData ) ,
107- } ) ;
108- // @ts -expect-error TypeScript does not like indexing into this with the key
109- const providerCode = errorCodes . provider [ key ] ;
110- expect ( error . code >= 1000 && error . code < 5000 ) . toBe ( true ) ;
111- expect ( error . code ) . toBe ( providerCode ) ;
112- expect ( error . message ) . toBe ( getMessageFromCode ( providerCode ) ) ;
113- } ) ;
100+ describe ( 'providerErrors' , ( ) => {
101+ it . each ( Object . entries ( providerErrors ) . filter ( ( [ key ] ) => key !== 'custom' ) ) (
102+ '%s returns appropriate value' ,
103+ ( key , value ) => {
104+ const createError = value as any ;
105+ const error = createError ( {
106+ message : null ,
107+ data : Object . assign ( { } , dummyData ) ,
108+ } ) ;
109+ // @ts -expect-error TypeScript does not like indexing into this with the key
110+ const providerCode = errorCodes . provider [ key ] ;
111+ expect ( error . code >= 1000 && error . code < 5000 ) . toBe ( true ) ;
112+ expect ( error . code ) . toBe ( providerCode ) ;
113+ expect ( error . message ) . toBe ( getMessageFromCode ( providerCode ) ) ;
114+ } ,
115+ ) ;
114116
115117 it ( 'custom returns appropriate value' , ( ) => {
116- const error = ethErrors . provider . custom ( {
118+ const error = providerErrors . custom ( {
117119 code : CUSTOM_ERROR_CODE ,
118120 message : CUSTOM_ERROR_MESSAGE ,
119121 data : Object . assign ( { } , dummyData ) ,
0 commit comments