@@ -19,7 +19,7 @@ contract OrdersTest is Test {
1919    uint256  amount =  200 ;
2020    uint256  deadline =  block .timestamp ;
2121
22-     event OutputFilled  ( uint256   indexed   originChainId ,  address   indexed   recipient ,  address   indexed   token ,  uint256   amount );
22+     event Filled  (Output[]  outputs );
2323
2424    event Order  (uint256  deadline , Input[] inputs , Output[] outputs );
2525
@@ -122,13 +122,13 @@ contract OrdersTest is Test {
122122        assertEq (address (target).balance, amount *  3 );
123123    }
124124
125-     function test_initiate_underflowETH   () public  {
125+     function test_underflowETH   () public  {
126126        // change first input to ETH 
127127        inputs[0 ].token =  address (0 );
128128        // add second ETH input 
129129        inputs.push (Input (address (0 ), 1 ));
130130
131-         // total ETH inputs should be ` amount`  + 1; function should underflow only sending ` amount`  
131+         // total ETH inputs should be amount + 1; function should underflow only sending amount 
132132        vm.expectRevert ();
133133        target.initiate {value: amount}(deadline, inputs, outputs);
134134    }
@@ -140,7 +140,7 @@ contract OrdersTest is Test {
140140        target.initiate (deadline, inputs, outputs);
141141    }
142142
143-     function test_sweep_ETH   () public  {
143+     function test_sweepETH   () public  {
144144        // set self as Builder 
145145        vm.coinbase (address (this ));
146146
@@ -158,7 +158,7 @@ contract OrdersTest is Test {
158158        assertEq (recipient.balance, amount);
159159    }
160160
161-     function test_sweep_ERC20   () public  {
161+     function test_sweepERC20   () public  {
162162        // set self as Builder 
163163        vm.coinbase (address (this ));
164164
@@ -176,4 +176,63 @@ contract OrdersTest is Test {
176176        vm.expectRevert (OrderOrigin.OnlyBuilder.selector );
177177        target.sweep (recipient, token);
178178    }
179+ 
180+     function test_fill_ETH  () public  {
181+         outputs[0 ].token =  address (0 );
182+ 
183+         vm.expectEmit ();
184+         emit  Filled (outputs);
185+         target.fill {value: amount}(outputs);
186+ 
187+         // ETH is transferred to recipient 
188+         assertEq (recipient.balance, amount);
189+     }
190+ 
191+     function test_fill_ERC20  () public  {
192+         vm.expectEmit ();
193+         emit  Filled (outputs);
194+         vm.expectCall (token, abi.encodeWithSelector (ERC20 .transferFrom.selector , address (this ), recipient, amount));
195+         target.fill (outputs);
196+     }
197+ 
198+     function test_fill_both  () public  {
199+         // add ETH output 
200+         outputs.push (Output (address (0 ), amount *  2 , recipient, chainId));
201+ 
202+         // expect Outputs are filled, ERC20 is transferred 
203+         vm.expectEmit ();
204+         emit  Filled (outputs);
205+         vm.expectCall (token, abi.encodeWithSelector (ERC20 .transferFrom.selector , address (this ), recipient, amount));
206+         target.fill {value: amount *  2 }(outputs);
207+ 
208+         // ETH is transferred to recipient 
209+         assertEq (recipient.balance, amount *  2 );
210+     }
211+ 
212+     // fill multiple ETH outputs 
213+     function test_fill_multiETH  () public  {
214+         // change first output to ETH 
215+         outputs[0 ].token =  address (0 );
216+         // add second ETH oputput 
217+         outputs.push (Output (address (0 ), amount *  2 , recipient, chainId));
218+ 
219+         // expect Order event is initiated 
220+         vm.expectEmit ();
221+         emit  Filled (outputs);
222+         target.fill {value: amount *  3 }(outputs);
223+ 
224+         // ETH is transferred to recipient 
225+         assertEq (recipient.balance, amount *  3 );
226+     }
227+ 
228+     function test_fill_underflowETH  () public  {
229+         // change first output to ETH 
230+         outputs[0 ].token =  address (0 );
231+         // add second ETH output 
232+         outputs.push (Output (address (0 ), 1 , recipient, chainId));
233+ 
234+         // total ETH outputs should be `amount` + 1; function should underflow only sending `amount` 
235+         vm.expectRevert ();
236+         target.fill {value: amount}(outputs);
237+     }
179238}
0 commit comments