@@ -2,6 +2,7 @@ import type {
2
2
AnotherContract ,
3
3
EventsContract ,
4
4
MatchersContract ,
5
+ OverrideEventContract ,
5
6
} from "./contracts" ;
6
7
7
8
import { expect , AssertionError } from "chai" ;
@@ -14,6 +15,7 @@ import { useEnvironment, useEnvironmentWithNode } from "./helpers";
14
15
describe ( ".to.emit (contract events)" , ( ) => {
15
16
let contract : EventsContract ;
16
17
let otherContract : AnotherContract ;
18
+ let overrideEventContract : OverrideEventContract ;
17
19
let matchers : MatchersContract ;
18
20
19
21
describe ( "with the in-process hardhat network" , function ( ) {
@@ -38,6 +40,12 @@ describe(".to.emit (contract events)", () => {
38
40
)
39
41
) . deploy ( await otherContract . getAddress ( ) ) ;
40
42
43
+ overrideEventContract = await (
44
+ await this . hre . ethers . getContractFactory < [ ] , OverrideEventContract > (
45
+ "OverrideEventContract"
46
+ )
47
+ ) . deploy ( ) ;
48
+
41
49
const Matchers = await this . hre . ethers . getContractFactory <
42
50
[ ] ,
43
51
MatchersContract
@@ -872,5 +880,30 @@ describe(".to.emit (contract events)", () => {
872
880
const tx = await contract . emitWithoutArgs ( ) ;
873
881
await expect ( tx . hash ) . to . emit ( contract , "WithoutArgs" ) ;
874
882
} ) ;
883
+
884
+ describe ( "When event is overloaded" , ( ) => {
885
+ it ( "Should fail when the event name is ambiguous" , async function ( ) {
886
+ await expect (
887
+ expect ( overrideEventContract . emitSimpleEventWithUintArg ( 1n ) ) . to . emit (
888
+ overrideEventContract ,
889
+ "simpleEvent"
890
+ )
891
+ ) . to . be . eventually . rejectedWith (
892
+ AssertionError ,
893
+ `ambiguous event description (i.e. matches "simpleEvent(uint256)", "simpleEvent()")`
894
+ ) ;
895
+ } ) ;
896
+
897
+ it ( "Should pass when the event name is not ambiguous" , async function ( ) {
898
+ await expect ( overrideEventContract . emitSimpleEventWithUintArg ( 1n ) )
899
+ . to . emit ( overrideEventContract , "simpleEvent(uint256)" )
900
+ . withArgs ( 1 ) ;
901
+
902
+ await expect ( overrideEventContract . emitSimpleEventWithoutArg ( ) ) . to . emit (
903
+ overrideEventContract ,
904
+ "simpleEvent()"
905
+ ) ;
906
+ } ) ;
907
+ } ) ;
875
908
}
876
909
} ) ;
0 commit comments