@@ -92,78 +92,54 @@ describe("evm/index", () => {
92
92
} ) ;
93
93
94
94
describe ( "validateRequest" , ( ) => {
95
- const mockAddress = "0x1111111111111111111111111111111111111111" ;
96
- const mockGetAdapterAddress = jest . fn ( ) ;
97
- jest . mock ( "../../src/evm" , ( ) => ( {
98
- ...jest . requireActual ( "../../src/evm" ) ,
99
- getAdapterAddress : mockGetAdapterAddress ,
100
- } ) ) ;
101
-
102
- it ( "returns null for valid request" , async ( ) => {
103
- const req = {
104
- headers : {
105
- get : jest . fn ( ) . mockReturnValue (
106
- JSON . stringify ( {
107
- accountId : "testAccount" ,
108
- evmAddress : "0x123" ,
109
- } ) ,
110
- ) ,
111
- } ,
112
- } as BaseRequest ;
113
-
114
- mockGetAdapterAddress . mockResolvedValue ( "0x123" ) ;
115
-
116
- const result = await validateRequest ( req , "safeSaltNonce" ) ;
117
-
118
- expect ( result ) . toBeNull ( ) ;
119
- } ) ;
120
-
121
- it ( "returns error response for missing accountId or evmAddress" , async ( ) => {
95
+ it ( "returns error response for missing accountId and evmAddress" , async ( ) => {
122
96
const req = {
123
97
headers : {
124
98
get : jest . fn ( ) . mockReturnValue ( "{}" ) ,
125
99
} ,
126
100
} as BaseRequest ;
127
101
128
- const result = await validateRequest ( req , "safeSaltNonce" ) ;
102
+ const result = await validateRequest ( req ) ;
129
103
130
104
expect ( result ) . toEqual ( {
131
105
json : expect . any ( Function ) ,
132
106
} ) ;
133
107
134
108
const jsonResponse = result ?. json ( { } , { } ) ;
135
109
expect ( jsonResponse ) . toEqual ( {
136
- data : { error : "Missing accountId or evmAddress in metadata" } ,
110
+ data : { error : "Missing accountId and evmAddress in metadata" } ,
137
111
status : 400 ,
138
112
} ) ;
139
113
} ) ;
140
114
141
- it ( "returns error response for invalid safeAddress " , async ( ) => {
115
+ it ( "returns null for valid request with accountId " , async ( ) => {
142
116
const req = {
143
117
headers : {
144
118
get : jest . fn ( ) . mockReturnValue (
145
119
JSON . stringify ( {
146
120
accountId : "testAccount" ,
147
- evmAddress : mockAddress ,
148
121
} ) ,
149
122
) ,
150
123
} ,
151
124
} as BaseRequest ;
152
125
153
- mockGetAdapterAddress . mockResolvedValue ( mockAddress ) ;
154
-
155
- const result = await validateRequest ( req , "0" ) ;
156
- expect ( result ) . toEqual ( {
157
- json : expect . any ( Function ) ,
158
- } ) ;
126
+ const result = await validateRequest ( req ) ;
127
+ expect ( result ) . toBeNull ( ) ;
128
+ } ) ;
159
129
160
- const jsonResponse = result ?. json ( { } , { } ) ;
161
- expect ( jsonResponse ) . toEqual ( {
162
- data : {
163
- error : `Invalid safeAddress in metadata: 0x123 !== ${ mockAddress } ` ,
130
+ it ( "returns null for valid request with evmAddress" , async ( ) => {
131
+ const req = {
132
+ headers : {
133
+ get : jest . fn ( ) . mockReturnValue (
134
+ JSON . stringify ( {
135
+ evmAddress : "0x123" ,
136
+ } ) ,
137
+ ) ,
164
138
} ,
165
- status : 401 ,
166
- } ) ;
139
+ } as BaseRequest ;
140
+
141
+ const result = await validateRequest ( req ) ;
142
+ expect ( result ) . toBeNull ( ) ;
167
143
} ) ;
168
144
} ) ;
169
145
@@ -182,32 +158,21 @@ describe("evm/index", () => {
182
158
} ) ,
183
159
) ;
184
160
185
- const result = await validateNextRequest ( request , "0" ) ;
186
- // Get the response data
187
- const responseData = await result ?. json ( ) ;
188
-
189
- // Assert the status and response data separately
190
- expect ( result ?. status ) . toBe ( 401 ) ;
191
- expect ( responseData ) . toEqual ( {
192
- error : `Invalid safeAddress in metadata: 0x123 !== ${ zeroAddress } ` ,
193
- } ) ;
161
+ const result = await validateNextRequest ( request ) ;
162
+ expect ( result ) . toBeNull ( ) ;
194
163
} ) ;
195
164
} ) ;
196
165
} ) ;
197
166
198
167
// TODO: Use in Next Agents.
199
168
export async function validateNextRequest (
200
169
req : NextRequest ,
201
- safeSaltNonce ?: string ,
202
170
) : Promise < NextResponse | null > {
203
171
const result = await validateRequest < NextRequest , NextResponse > (
204
172
req ,
205
- safeSaltNonce || "0" ,
206
173
( data : unknown , init ?: { status ?: number } ) =>
207
174
NextResponse . json ( data , init ) ,
208
175
) ;
209
176
210
- console . log ( "validateNextRequest result:" , result ) ; // Add this line for debugging
211
-
212
177
return result ;
213
178
}
0 commit comments