@@ -2,10 +2,12 @@ import { expect } from "chai";
2
2
import {
3
3
AUTHORIZE_FULL_CONTROL ,
4
4
Operation ,
5
+ TestToken ,
6
+ TestToken__factory ,
5
7
getPerSecondFlowRateByMonth ,
6
8
toBN ,
7
9
} from "../src" ;
8
- import { ethers } from "ethers" ;
10
+ import { BigNumber , Contract , ethers } from "ethers" ;
9
11
import { createCallAppActionOperation } from "./2_operation.test" ;
10
12
import { TestEnvironment , makeSuite } from "./TestEnvironment" ;
11
13
@@ -408,4 +410,115 @@ makeSuite("Batch Call Tests", (testEnv: TestEnvironment) => {
408
410
"0"
409
411
) ;
410
412
} ) ;
413
+
414
+
415
+ it ( "Should be able to execute SimpleForwarder batch call" , async ( ) => {
416
+ const contract = ( new Contract (
417
+ testEnv . wrapperSuperToken . underlyingToken . address ,
418
+ TestToken__factory . abi
419
+ ) as TestToken ) . connect ( testEnv . alice ) ;
420
+
421
+ const beforeBalance = await contract . balanceOf ( testEnv . alice . address ) ;
422
+
423
+ const txn1 = contract
424
+ . populateTransaction . mint (
425
+ testEnv . alice . address ,
426
+ "100"
427
+ ) ;
428
+ const txn2 = contract
429
+ . populateTransaction . mint (
430
+ testEnv . alice . address ,
431
+ "200"
432
+ ) ;
433
+
434
+ const operation1 = testEnv . sdkFramework . operation (
435
+ txn1 ,
436
+ "SIMPLE_FORWARD_CALL"
437
+ ) ;
438
+ const operation2 = testEnv . sdkFramework . operation (
439
+ txn2 ,
440
+ "SIMPLE_FORWARD_CALL"
441
+ ) ;
442
+
443
+ const batchCall = testEnv . sdkFramework . batchCall (
444
+ [
445
+ operation1 ,
446
+ operation2
447
+ ]
448
+ ) ;
449
+
450
+ const txResponse = await batchCall . exec ( testEnv . alice ) ;
451
+ const txReceipt = await txResponse . wait ( ) ;
452
+ expect ( txReceipt . status ) . to . equal ( 1 ) ;
453
+
454
+ const afterBalance = await contract . balanceOf ( testEnv . alice . address ) ;
455
+
456
+ expect ( beforeBalance . lt ( afterBalance ) ) . to . be . true ;
457
+ expect ( afterBalance . sub ( BigNumber . from ( 300 ) ) . eq ( beforeBalance ) ) . to . be . true ;
458
+ } ) ;
459
+
460
+ it ( "Should be able to move ETH value" , async ( ) => {
461
+ const value = BigNumber . from ( Number ( 0.1e18 ) . toString ( ) ) ;
462
+
463
+ const beforeBalanceAlice = await testEnv . alice . getBalance ( ) ;
464
+ const beforeBalanceBob = await testEnv . bob . getBalance ( ) ;
465
+
466
+ expect ( beforeBalanceAlice . gt ( value ) ) . to . be . true ;
467
+
468
+ const operation = testEnv . sdkFramework . operation (
469
+ testEnv . alice . populateTransaction ( {
470
+ to : testEnv . bob . address ,
471
+ value,
472
+ data : "0x"
473
+ } ) as Promise < ethers . PopulatedTransaction > ,
474
+ "SIMPLE_FORWARD_CALL"
475
+ ) ;
476
+
477
+ const batchCall = testEnv . sdkFramework . batchCall (
478
+ [
479
+ operation
480
+ ]
481
+ ) ;
482
+
483
+ const txn = await batchCall . exec ( testEnv . alice , 2 ) ;
484
+
485
+ const txReceipt = await txn . wait ( ) ;
486
+ expect ( txReceipt . status ) . to . equal ( 1 ) ;
487
+
488
+ const afterBalanceAlice = await testEnv . alice . getBalance ( ) ;
489
+ const afterBalanceBob = await testEnv . bob . getBalance ( ) ;
490
+
491
+ expect ( afterBalanceBob . sub ( beforeBalanceBob ) ) . to . equal ( value ) ;
492
+ expect ( beforeBalanceAlice . sub ( afterBalanceAlice ) . gte ( value ) ) . to . be . true ;
493
+ } ) ;
494
+
495
+ it ( "Should throw an error when multiple Operations with ETH value" , async ( ) => {
496
+ const operation1 = testEnv . sdkFramework . operation (
497
+ testEnv . alice . populateTransaction ( {
498
+ to : testEnv . bob . address ,
499
+ value : BigNumber . from ( Number ( 0.1e18 ) . toString ( ) ) ,
500
+ data : "0x"
501
+ } ) as Promise < ethers . PopulatedTransaction > ,
502
+ "SIMPLE_FORWARD_CALL"
503
+ ) ;
504
+
505
+ const operation2 = testEnv . sdkFramework . operation (
506
+ testEnv . alice . populateTransaction ( {
507
+ to : testEnv . bob . address ,
508
+ value : BigNumber . from ( Number ( 0.2e18 ) . toString ( ) ) ,
509
+ data : "0x"
510
+ } ) as Promise < ethers . PopulatedTransaction > ,
511
+ "SIMPLE_FORWARD_CALL"
512
+ ) ;
513
+
514
+ const batchCall = testEnv . sdkFramework . batchCall (
515
+ [
516
+ operation1 ,
517
+ operation2
518
+ ]
519
+ ) ;
520
+
521
+ await expect ( batchCall . exec ( testEnv . alice , 2 ) )
522
+ . to . be . rejectedWith ( "multiple values in the batch call" ) ;
523
+ } ) ;
411
524
} ) ;
0 commit comments