11// write tests that get the metadata from an rpc and then inject the metadata into the controller
22
33import { ApiPromise , WsProvider } from '@polkadot/api' ;
4+ import { ISidecarConfig } from 'src/types/sidecar-config' ;
45
5- import { specToControllerMap } from '../chains-config' ;
6+ import { getControllers , specToControllerMap } from '../chains-config' ;
67import { defaultControllers } from '../chains-config/defaultControllers' ;
78import { controllers } from '.' ;
89
@@ -13,6 +14,42 @@ import { controllers } from '.';
1314 * @param implName
1415 */
1516
17+ const mockSidecarConfig : ISidecarConfig = {
18+ EXPRESS : {
19+ HOST : '' ,
20+ PORT : 3000 ,
21+ KEEP_ALIVE_TIMEOUT : 5000 ,
22+ MAX_BODY : '100kb' ,
23+ INJECTED_CONTROLLERS : false ,
24+ } ,
25+ SUBSTRATE : {
26+ URL : '' ,
27+ TYPES_BUNDLE : '' ,
28+ TYPES_CHAIN : '' ,
29+ TYPES_SPEC : '' ,
30+ TYPES : '' ,
31+ CACHE_CAPACITY : 1000 ,
32+ } ,
33+ LOG : {
34+ LEVEL : 'info' ,
35+ JSON : false ,
36+ FILTER_RPC : false ,
37+ STRIP_ANSI : false ,
38+ WRITE : false ,
39+ WRITE_PATH : '' ,
40+ WRITE_MAX_FILE_SIZE : 0 ,
41+ WRITE_MAX_FILES : 0 ,
42+ } ,
43+ METRICS : {
44+ ENABLED : false ,
45+ PROM_HOST : '' ,
46+ PROM_PORT : 0 ,
47+ LOKI_HOST : '' ,
48+ LOKI_PORT : 0 ,
49+ INCLUDE_QUERYPARAMS : false ,
50+ } ,
51+ } ;
52+
1653const chainsToNode : Record < string , string > = {
1754 'asset-hub-kusama' : 'wss://asset-hub-kusama-rpc.dwellir.com' ,
1855 kusama : 'wss://kusama-rpc.dwellir.com' ,
@@ -58,4 +95,44 @@ describe('controllerInjection', () => {
5895 expect ( filtered ) . toHaveLength ( 0 ) ;
5996 } ) ;
6097 }
98+
99+ it ( 'should inject default controllers when pallets are not checked (injected-controllers: false) and a custom config is not available' , async ( ) => {
100+ const wsProvider = new WsProvider ( 'wss://kusama-rpc.dwellir.com' ) ;
101+ const api = await ApiPromise . create ( { provider : wsProvider } ) ;
102+ try {
103+ await api . isReady ;
104+ } finally {
105+ await api ?. disconnect ( ) ; // Close WebSocket connection
106+ }
107+
108+ const controllers = getControllers (
109+ api ,
110+ {
111+ ...mockSidecarConfig ,
112+ EXPRESS : {
113+ ...mockSidecarConfig . EXPRESS ,
114+ INJECTED_CONTROLLERS : true ,
115+ } ,
116+ } ,
117+ 'kusama_go_default' ,
118+ ) ;
119+
120+ expect ( controllers ) . toBeDefined ( ) ;
121+ expect ( controllers ) . not . toHaveLength ( 0 ) ;
122+
123+ const controllersDefault = getControllers (
124+ api ,
125+ {
126+ ...mockSidecarConfig ,
127+ EXPRESS : {
128+ ...mockSidecarConfig . EXPRESS ,
129+ INJECTED_CONTROLLERS : false ,
130+ } ,
131+ } ,
132+ 'kusama_go_default' ,
133+ ) ;
134+
135+ expect ( controllersDefault ) . toBeDefined ( ) ;
136+ expect ( controllersDefault ) . toHaveLength ( defaultControllers . controllers . length ) ;
137+ } ) ;
61138} ) ;
0 commit comments