@@ -16,9 +16,9 @@ interface InitResult {
1616 networkConfig : NetworkConfig ;
1717}
1818
19- describe ( "gas config behavior" , ( ) => {
19+ describe ( "network config behavior" , ( ) => {
2020 describe ( "in-process hardhat network" , ( ) => {
21- defineGasConfigTests ( ( ) => initializeTestEthers ( ARTIFACTS ) ) ;
21+ defineNetworkConfigTests ( ( ) => initializeTestEthers ( ARTIFACTS ) ) ;
2222 } ) ;
2323
2424 describe ( "local http node" , ( ) => {
@@ -34,7 +34,7 @@ describe("gas config behavior", () => {
3434 await server . close ( ) ;
3535 } ) ;
3636
37- defineGasConfigTests ( ( ) =>
37+ defineNetworkConfigTests ( ( ) =>
3838 initializeTestEthers ( ARTIFACTS , {
3939 networks : {
4040 localhost : { type : "http" , url : `http://${ address } :${ port } ` } ,
@@ -44,7 +44,7 @@ describe("gas config behavior", () => {
4444 } ) ;
4545} ) ;
4646
47- function defineGasConfigTests ( initEthers : ( ) => Promise < InitResult > ) {
47+ function defineNetworkConfigTests ( initEthers : ( ) => Promise < InitResult > ) {
4848 describe ( "gas: auto (default)" , ( ) => {
4949 let ethers : HardhatEthers ;
5050
@@ -254,6 +254,48 @@ function defineGasConfigTests(initEthers: () => Promise<InitResult>) {
254254 } ) ;
255255 } ) ;
256256
257+ describe ( "from config" , ( ) => {
258+ let ethers : HardhatEthers ;
259+
260+ before ( async ( ) => {
261+ ( { ethers } = await initEthers ( ) ) ;
262+ } ) ;
263+
264+ it ( "default signer sends from its own address" , async ( ) => {
265+ const [ firstSigner , secondSigner ] = await ethers . getSigners ( ) ;
266+ const tx = await firstSigner . sendTransaction ( { to : secondSigner } ) ;
267+ assert . equal ( tx . from , firstSigner . address ) ;
268+ } ) ;
269+
270+ it ( "non-first signer sends from its own address" , async ( ) => {
271+ const [ firstSigner , secondSigner ] = await ethers . getSigners ( ) ;
272+ const tx = await secondSigner . sendTransaction ( { to : firstSigner } ) ;
273+ assert . equal ( tx . from , secondSigner . address ) ;
274+ } ) ;
275+
276+ it ( "respects explicit from matching the signer" , async ( ) => {
277+ const [ firstSigner , secondSigner ] = await ethers . getSigners ( ) ;
278+ const tx = await firstSigner . sendTransaction ( {
279+ to : secondSigner ,
280+ from : firstSigner . address ,
281+ } ) ;
282+ assert . equal ( tx . from , firstSigner . address ) ;
283+ } ) ;
284+
285+ it ( "throws when explicit from doesn't match the signer" , async ( ) => {
286+ const [ firstSigner , secondSigner ] = await ethers . getSigners ( ) ;
287+
288+ // eslint-disable-next-line no-restricted-syntax -- it tests a non Hardhat error
289+ await assert . rejects (
290+ firstSigner . sendTransaction ( {
291+ to : firstSigner ,
292+ from : secondSigner . address ,
293+ } ) ,
294+ / f r o m a d d r e s s m i s m a t c h / ,
295+ ) ;
296+ } ) ;
297+ } ) ;
298+
257299 describe ( "non-interference with explicit gas-related calls" , ( ) => {
258300 let ethers : HardhatEthers ;
259301 let provider : EthereumProvider ;
0 commit comments