@@ -172,13 +172,23 @@ function buildWrappedFallback(contract: BaseContract): WrappedFallback {
172
172
173
173
const iface = contract . interface ;
174
174
175
+ const noValue = ( ( tx . value || BN_0 ) === BN_0 ) ;
176
+ const noData = ( ( tx . data || "0x" ) === "0x" ) ;
177
+
178
+ if ( iface . fallback && ! iface . fallback . payable && iface . receive && ! noData && ! noValue ) {
179
+ assertArgument ( false , "cannot send data to receive or send value to non-payable fallback" , "overrides" , overrides ) ;
180
+ }
181
+
182
+ assertArgument ( iface . fallback || noData ,
183
+ "cannot send data to receive-only contract" , "overrides.data" , tx . data ) ;
184
+
175
185
// Only allow payable contracts to set non-zero value
176
186
const payable = iface . receive || ( iface . fallback && iface . fallback . payable ) ;
177
- assertArgument ( payable || ( tx . value || BN_0 ) === BN_0 ,
178
- "cannot send value to non-payable contract " , "overrides.value" , tx . value ) ;
187
+ assertArgument ( payable || noValue ,
188
+ "cannot send value to non-payable fallback " , "overrides.value" , tx . value ) ;
179
189
180
190
// Only allow fallback contracts to set non-empty data
181
- assertArgument ( iface . fallback || ( tx . data || "0x" ) === "0x" ,
191
+ assertArgument ( iface . fallback || noData ,
182
192
"cannot send data to receive-only contract" , "overrides.data" , tx . data ) ;
183
193
184
194
return tx ;
0 commit comments