File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -191,7 +191,16 @@ export abstract class Signer {
191191
192192 const tx : Deferrable < TransactionRequest > = await resolveProperties ( this . checkTransaction ( transaction ) )
193193
194- if ( tx . to != null ) { tx . to = Promise . resolve ( tx . to ) . then ( ( to ) => this . resolveName ( to ) ) ; }
194+ if ( tx . to != null ) {
195+ tx . to = Promise . resolve ( tx . to ) . then ( async ( to ) => {
196+ if ( to == null ) { return null ; }
197+ const address = await this . resolveName ( to ) ;
198+ if ( address == null ) {
199+ logger . throwArgumentError ( "provided ENS name resolves to null" , "tx.to" , to ) ;
200+ }
201+ return address ;
202+ } ) ;
203+ }
195204 if ( tx . gasPrice == null ) { tx . gasPrice = this . getGasPrice ( ) ; }
196205 if ( tx . nonce == null ) { tx . nonce = this . getTransactionCount ( "pending" ) ; }
197206
Original file line number Diff line number Diff line change @@ -1113,3 +1113,34 @@ describe("Test Events", function() {
11131113 await testBlockEvent ( provider ) ;
11141114 } ) ;
11151115} ) ;
1116+
1117+ describe ( "Bad ENS resolution" , function ( ) {
1118+ const provider = providerFunctions [ 0 ] . create ( "ropsten" ) ;
1119+
1120+ it ( "signer has a bad ENS name" , async function ( ) {
1121+ this . timeout ( 300000 ) ;
1122+
1123+ const wallet = new ethers . Wallet ( ethers . utils . id ( "random-wallet" ) , provider ) ;
1124+
1125+ // If "to" is specified as an ENS name, it cannot resolve to null
1126+ try {
1127+ const tx = await wallet . sendTransaction ( { to : "junk" , value : 1 } ) ;
1128+ console . log ( "TX" , tx ) ;
1129+ } catch ( error ) {
1130+ assert . ok ( error . argument === "tx.to" && error . value === "junk" ) ;
1131+ }
1132+
1133+ // But promises that resolve to null are ok
1134+ const tos = [ null , Promise . resolve ( null ) ] ;
1135+ for ( let i = 0 ; i < tos . length ; i ++ ) {
1136+ const to = tos [ i ] ;
1137+ try {
1138+ const tx = await wallet . sendTransaction ( { to, value : 1 } ) ;
1139+ console . log ( "TX" , tx ) ;
1140+ } catch ( error ) {
1141+ assert . ok ( error . code === "INSUFFICIENT_FUNDS" ) ;
1142+ }
1143+ }
1144+ } ) ;
1145+
1146+ } ) ;
You can’t perform that action at this time.
0 commit comments