@@ -42,4 +42,63 @@ describe("Load configuration from JSON file", () => {
4242 const chain = new config . Chain ( "GNOSIS" , 123 , new Array < config . RPCEndpoint > ( ) , new config . Contracts ( ) )
4343 assert . equal ( chain . toString ( ) , "gnosis" )
4444 } )
45+ describe ( "Chain constructor" , ( ) => {
46+ const testCases : {
47+ name : string ;
48+ chain : {
49+ name : string ;
50+ id : number ;
51+ rpcEndpoints : config . RPCEndpoint [ ] ;
52+ contracts : config . Contracts ;
53+ } ;
54+ expectedErrorMessage : string ;
55+ } [ ] = [
56+ {
57+ name : "name cannot be empty" ,
58+ chain : {
59+ name : "" ,
60+ id : 0 ,
61+ rpcEndpoints : new Array < config . RPCEndpoint > ( ) ,
62+ contracts : new config . Contracts ( ) ,
63+ } ,
64+ expectedErrorMessage : "Chain name is required" ,
65+ } ,
66+ {
67+ name : "id cannot be negative" ,
68+ chain : {
69+ name : "ethereum" ,
70+ id : - 1 ,
71+ rpcEndpoints : new Array < config . RPCEndpoint > ( ) ,
72+ contracts : new config . Contracts ( ) ,
73+ } ,
74+ expectedErrorMessage : "Chain ID cannot be negative" ,
75+ } ,
76+ {
77+ name : "all good" ,
78+ chain : {
79+ name : "ethereum" ,
80+ id : 1 ,
81+ rpcEndpoints : new Array < config . RPCEndpoint > ( ) ,
82+ contracts : new config . Contracts ( ) ,
83+ } ,
84+ expectedErrorMessage : "" ,
85+ } ,
86+ ]
87+ testCases . forEach ( ( tc ) => {
88+ it ( tc . name , async ( ) => {
89+ try {
90+ new config . Chain ( tc . chain . name , tc . chain . id , tc . chain . rpcEndpoints , tc . chain . contracts )
91+ if ( tc . expectedErrorMessage !== "" ) {
92+ assert . fail ( "expecting error" )
93+ }
94+ } catch ( err : any ) {
95+ if ( tc . expectedErrorMessage !== "" ) {
96+ assert . equal ( err . message , tc . expectedErrorMessage )
97+ } else {
98+ assert . fail ( `unexpected error: "${ err } "` )
99+ }
100+ }
101+ } )
102+ } )
103+ } )
45104} )
0 commit comments