@@ -184,6 +184,11 @@ describe("Simple Time-Lock Vault", () => {
184184 let recipient1 : SignerWithAddress ;
185185 let recipient2 : SignerWithAddress ;
186186
187+ let recipient1Amount : BigNumber ;
188+ let depositIds1Included : boolean [ ] ;
189+ let recipient2Amount : BigNumber ;
190+ let depositIds2Included : boolean [ ] ;
191+
187192 const oneDayInterval = 3600 * 24 ;
188193
189194 beforeEach ( async ( ) => {
@@ -213,11 +218,11 @@ describe("Simple Time-Lock Vault", () => {
213218 describe ( "Withdrawal Preview" , ( ) => {
214219 describe ( "When all deposit IDs are not matured yet" , ( ) => {
215220 it ( "should return zero as the amount" , async ( ) => {
216- const recipient1Amount = await simpleVaultContract . previewWithdraw (
221+ const [ recipient1Amount ] = await simpleVaultContract . previewWithdraw (
217222 recipient1 . address ,
218223 [ 0 , 2 , 4 ] ,
219224 ) ;
220- const recipient2Amount = await simpleVaultContract . previewWithdraw (
225+ const [ recipient2Amount ] = await simpleVaultContract . previewWithdraw (
221226 recipient2 . address ,
222227 [ 1 , 3 ] ,
223228 ) ;
@@ -228,55 +233,75 @@ describe("Simple Time-Lock Vault", () => {
228233 } ) ;
229234
230235 describe ( "When some of the deposit IDs are matured" , ( ) => {
231- it ( "should return the total amount of the specified deposit IDs that are matured for withdrawal" , async ( ) => {
236+ beforeEach ( async ( ) => {
232237 // Deposit ID 4 for recipient 1 should not be matured yet
233238 await time . increase ( oneDayInterval * 6 ) ;
234239
235- const recipient1Amount = await simpleVaultContract . previewWithdraw (
240+ [ recipient1Amount , depositIds1Included ] = await simpleVaultContract . previewWithdraw (
236241 recipient1 . address ,
237242 [ 0 , 2 , 4 ] ,
238243 ) ;
239- const recipient2Amount = await simpleVaultContract . previewWithdraw (
244+ [ recipient2Amount , depositIds2Included ] = await simpleVaultContract . previewWithdraw (
240245 recipient2 . address ,
241246 [ 1 , 3 ] ,
242247 ) ;
248+ } ) ;
243249
250+ it ( "should return the total amount of the specified deposit IDs that are matured for withdrawal" , async ( ) => {
244251 expect ( recipient1Amount ) . to . equal ( parseEther ( "200" ) ) ;
245252 expect ( recipient2Amount ) . to . equal ( parseEther ( "200" ) ) ;
246253 } ) ;
254+
255+ it ( "should return the included result for the specified deposit IDs that are matured for withdrawal" , async ( ) => {
256+ expect ( depositIds1Included ) . to . deep . equal ( [ true , true , false ] ) ;
257+ expect ( depositIds2Included ) . to . deep . equal ( [ true , true ] ) ;
258+ } ) ;
247259 } ) ;
248260
249261 describe ( "When some of the deposit IDs are inactive deposits" , ( ) => {
250- it ( "should return only the total amount of the deposit IDs that are active" , async ( ) => {
262+ beforeEach ( async ( ) => {
251263 await time . increase ( oneDayInterval * 6 ) ;
252264 await simpleVaultContract . connect ( recipient2 ) . withdraw ( 1 ) ;
253265
254- const recipient2Amount = await simpleVaultContract . previewWithdraw (
266+ [ recipient2Amount , depositIds2Included ] = await simpleVaultContract . previewWithdraw (
255267 recipient2 . address ,
256268 [ 1 , 3 ] ,
257269 ) ;
270+ } ) ;
258271
272+ it ( "should return only the total amount of the deposit IDs that are active" , async ( ) => {
259273 expect ( recipient2Amount ) . to . equal ( parseEther ( "100" ) ) ;
260274 } ) ;
275+
276+ it ( "should return the included result for the specified deposit IDs that are active" , async ( ) => {
277+ expect ( depositIds2Included ) . to . deep . equal ( [ false , true ] ) ;
278+ } ) ;
261279 } ) ;
262280
263281 describe ( "When all the deposit IDs are matured" , ( ) => {
264- it ( "should return the total amount of the specified deposit IDs" , async ( ) => {
282+ beforeEach ( async ( ) => {
265283 // 7 days later... All payments matured.
266284 await time . increase ( oneDayInterval * 7 ) ;
267285
268- const recipient1Amount = await simpleVaultContract . previewWithdraw (
286+ [ recipient1Amount , depositIds1Included ] = await simpleVaultContract . previewWithdraw (
269287 recipient1 . address ,
270288 [ 0 , 2 , 4 ] ,
271289 ) ;
272- const recipient2Amount = await simpleVaultContract . previewWithdraw (
290+ [ recipient2Amount , depositIds2Included ] = await simpleVaultContract . previewWithdraw (
273291 recipient2 . address ,
274292 [ 1 , 3 ] ,
275293 ) ;
294+ } ) ;
276295
296+ it ( "should return the total amount of the specified deposit IDs" , async ( ) => {
277297 expect ( recipient1Amount ) . to . equal ( parseEther ( "300" ) ) ;
278298 expect ( recipient2Amount ) . to . equal ( parseEther ( "200" ) ) ;
279299 } ) ;
300+
301+ it ( "should return the included result for the specified deposit IDs of all matured deposits" , async ( ) => {
302+ expect ( depositIds1Included ) . to . deep . equal ( [ true , true , true ] ) ;
303+ expect ( depositIds2Included ) . to . deep . equal ( [ true , true ] ) ;
304+ } ) ;
280305 } ) ;
281306
282307 it ( "should revert if withdraws a premature deposit" , async ( ) => {
0 commit comments