@@ -13,9 +13,11 @@ const packageJson = require(path.join(__dirname, '..', 'package.json'));
13
13
14
14
type ComplexArg2 = { map : Map < string , Uint8Array > } ;
15
15
type ComplexResponse = Map < bigint , Uint8Array > [ ] ;
16
+ type OptionalParameters = { num ?: number ; str ?: string } ;
16
17
interface TestProvider extends Provider {
17
18
noArgsEmptyReturn ( ) : Promise < void > ;
18
19
complexArgsAndReturn ( { arg1, arg2 } : { arg1 : bigint ; arg2 : ComplexArg2 } ) : Promise < ComplexResponse > ;
20
+ optionalParameters ( args : OptionalParameters ) : Promise < OptionalParameters > ;
19
21
}
20
22
21
23
const apiVersion = '1.0.0' ;
@@ -34,7 +36,8 @@ const createStubHttpProviderServer = async (port: number, urlPath: string, handl
34
36
const stubProviderPaths = {
35
37
complexArgsAndReturn : '/complex' ,
36
38
healthCheck : '/health' ,
37
- noArgsEmptyReturn : '/simple'
39
+ noArgsEmptyReturn : '/simple' ,
40
+ optionalParameters : '/optional'
38
41
} ;
39
42
40
43
describe ( 'createHttpProvider' , ( ) => {
@@ -43,7 +46,7 @@ describe('createHttpProvider', () => {
43
46
let closeServer : ( ) => Promise < unknown > ;
44
47
45
48
const createTxSubmitProviderClient = (
46
- config : Pick < HttpProviderConfig < TestProvider > , 'axiosOptions' | 'mapError' > = { }
49
+ config : Pick < HttpProviderConfig < TestProvider > , 'axiosOptions' | 'mapError' | 'modifyData' > = { }
47
50
) =>
48
51
createHttpProvider < TestProvider > ( {
49
52
apiVersion,
@@ -113,6 +116,31 @@ describe('createHttpProvider', () => {
113
116
} ) ;
114
117
} ) ;
115
118
119
+ describe ( 'modifyData' , ( ) => {
120
+ beforeEach (
121
+ async ( ) =>
122
+ ( closeServer = await createStubHttpProviderServer ( port , stubProviderPaths . optionalParameters , ( req , res ) =>
123
+ res . send ( req . body )
124
+ ) )
125
+ ) ;
126
+
127
+ it ( "defaultModifyData doesn't change the input data" , async ( ) => {
128
+ const provider = createTxSubmitProviderClient ( ) ;
129
+ const data = { num : 23 } ;
130
+
131
+ const response = await provider . optionalParameters ( data ) ;
132
+ expect ( response ) . toEqual ( data ) ;
133
+ } ) ;
134
+
135
+ it ( 'modifyData changes the input data as expected' , async ( ) => {
136
+ const provider = createTxSubmitProviderClient ( { modifyData : ( _ , data ) => ( { ...data , added : true } ) } ) ;
137
+ const data = { num : 23 } ;
138
+
139
+ const response = await provider . optionalParameters ( data ) ;
140
+ expect ( response ) . toEqual ( { ...data , added : true } ) ;
141
+ } ) ;
142
+ } ) ;
143
+
116
144
describe ( 'errors' , ( ) => {
117
145
describe ( 'connection errors' , ( ) => {
118
146
it ( 'maps ECONNREFUSED and ENOTFOUND to ProviderError{ConnectionFailure}' , async ( ) => {
0 commit comments