@@ -33,7 +33,7 @@ export const calledOnContractWithTest = (provider: MockProvider) => {
33
33
34
34
expect (
35
35
( ) => expect ( 'callWithParameter' ) . to . be . calledOnContractWith ( contract , [ 1 ] )
36
- ) . to . throw ( AssertionError , 'Expected contract function with parameters to be called' ) ;
36
+ ) . to . throw ( AssertionError , 'Expected contract function callWithParameter to be called' ) ;
37
37
} ) ;
38
38
39
39
it ( 'checks that contract function with parameter was not called' , async ( ) => {
@@ -58,7 +58,8 @@ export const calledOnContractWithTest = (provider: MockProvider) => {
58
58
59
59
expect (
60
60
( ) => expect ( 'callWithParameter' ) . not . to . be . calledOnContractWith ( contract , [ 2 ] )
61
- ) . to . throw ( AssertionError , 'Expected contract function with parameters NOT to be called' ) ;
61
+ ) . to . throw ( AssertionError , 'Expected contract function callWithParameter not to be called ' +
62
+ 'with parameters 2, but it was' ) ;
62
63
} ) ;
63
64
64
65
it (
@@ -83,4 +84,89 @@ export const calledOnContractWithTest = (provider: MockProvider) => {
83
84
84
85
expect ( 'callWithParameters' ) . to . be . calledOnContractWith ( contract , [ 2 , 3 ] ) ;
85
86
} ) ;
87
+
88
+ it ( 'Checks if function called from another contract with parameter was called' , async ( ) => {
89
+ const { contract} = await setup ( provider ) ;
90
+ const { contract : secondDeployContract } = await setup ( provider ) ;
91
+ await secondDeployContract . forwardCallWithParameter ( contract . address , 2 ) ;
92
+
93
+ expect ( 'callWithParameter' ) . to . be . calledOnContractWith ( contract , [ 2 ] ) ;
94
+ expect ( 'callWithParameter' ) . not . to . be . calledOnContractWith ( secondDeployContract , [ 2 ] ) ;
95
+ } ) ;
96
+
97
+ it ( 'Throws if expected function to be called from another contract with parameter but it was not' , async ( ) => {
98
+ const { contract} = await setup ( provider ) ;
99
+ const { contract : secondDeployContract } = await setup ( provider ) ;
100
+ await secondDeployContract . callWithParameter ( 2 ) ;
101
+
102
+ expect (
103
+ ( ) => expect ( 'callWithParameter' ) . to . be . calledOnContractWith ( contract , [ 2 ] )
104
+ ) . to . throw ( AssertionError , 'Expected contract function callWithParameter to be called' ) ;
105
+ expect ( 'callWithParameter' ) . to . be . calledOnContractWith ( secondDeployContract , [ 2 ] ) ;
106
+ expect ( 'callWithParameter' ) . not . to . be . calledOnContractWith ( contract , [ 2 ] ) ;
107
+ } ) ;
108
+
109
+ it ( 'Throws if function with parameter was called from another contract but the arg is wrong' , async ( ) => {
110
+ const { contract} = await setup ( provider ) ;
111
+ const { contract : secondDeployContract } = await setup ( provider ) ;
112
+ await secondDeployContract . forwardCallWithParameter ( contract . address , 2 ) ;
113
+
114
+ expect (
115
+ ( ) => expect ( 'callWithParameter' ) . to . be . calledOnContractWith ( contract , [ 3 ] )
116
+ ) . to . throw ( AssertionError , 'Expected contract function callWithParameter to be called with parameters 3 but' +
117
+ ' it was called with parameters:\n2' ) ;
118
+ expect ( 'callWithParameter' ) . not . to . be . calledOnContract ( secondDeployContract ) ;
119
+ } ) ;
120
+
121
+ it ( 'Hides called parameters if too many' , async ( ) => {
122
+ const { contract} = await setup ( provider ) ;
123
+ const { contract : secondDeployContract } = await setup ( provider ) ;
124
+ const calledParams : number [ ] = [ ] ;
125
+ for ( let i = 0 ; i < 10 ; i ++ ) {
126
+ if ( i !== 3 ) {
127
+ await secondDeployContract . forwardCallWithParameter ( contract . address , i ) ;
128
+ calledParams . push ( i ) ;
129
+ }
130
+ }
131
+
132
+ expect (
133
+ ( ) => expect ( 'callWithParameter' ) . to . be . calledOnContractWith ( contract , [ 3 ] )
134
+ ) . to . throw ( AssertionError , 'Expected contract function callWithParameter to be called with parameters 3 but' +
135
+ ' it was called with parameters:\n' + calledParams . slice ( 0 , 3 ) . join ( '\n' ) +
136
+ '\n...and 6 more.' ) ;
137
+ expect ( 'callWithParameter' ) . not . to . be . calledOnContract ( secondDeployContract ) ;
138
+ } ) ;
139
+
140
+ it ( 'Checks if function called from another contract with parameters was called' , async ( ) => {
141
+ const { contract} = await setup ( provider ) ;
142
+ const { contract : secondDeployContract } = await setup ( provider ) ;
143
+ await secondDeployContract . forwardCallWithParameters ( contract . address , 2 , 3 ) ;
144
+
145
+ expect ( 'callWithParameters' ) . to . be . calledOnContractWith ( contract , [ 2 , 3 ] ) ;
146
+ expect ( 'callWithParameters' ) . not . to . be . calledOnContractWith ( secondDeployContract , [ 2 , 3 ] ) ;
147
+ } ) ;
148
+
149
+ it ( 'Throws if expected function to be called from another contract with parameters but it was not' , async ( ) => {
150
+ const { contract} = await setup ( provider ) ;
151
+ const { contract : secondDeployContract } = await setup ( provider ) ;
152
+ await secondDeployContract . callWithParameters ( 2 , 3 ) ;
153
+
154
+ expect (
155
+ ( ) => expect ( 'callWithParameters' ) . to . be . calledOnContractWith ( contract , [ 2 , 3 ] )
156
+ ) . to . throw ( AssertionError , 'Expected contract function callWithParameters to be called' ) ;
157
+ expect ( 'callWithParameters' ) . to . be . calledOnContractWith ( secondDeployContract , [ 2 , 3 ] ) ;
158
+ expect ( 'callWithParameters' ) . not . to . be . calledOnContractWith ( contract , [ 2 , 3 ] ) ;
159
+ } ) ;
160
+
161
+ it ( 'Throws if function with parameters was called from another contract but the arg is wrong' , async ( ) => {
162
+ const { contract} = await setup ( provider ) ;
163
+ const { contract : secondDeployContract } = await setup ( provider ) ;
164
+ await secondDeployContract . forwardCallWithParameters ( contract . address , 2 , 3 ) ;
165
+
166
+ expect (
167
+ ( ) => expect ( 'callWithParameters' ) . to . be . calledOnContractWith ( contract , [ 2 , 4 ] )
168
+ ) . to . throw ( AssertionError , 'Expected contract function callWithParameters to be called with parameters 2,4 but' +
169
+ ' it was called with parameters:\n2,3' ) ;
170
+ expect ( 'callWithParameters' ) . not . to . be . calledOnContract ( secondDeployContract ) ;
171
+ } ) ;
86
172
} ;
0 commit comments