@@ -7,12 +7,11 @@ import {
7
7
BLSBN254SignatureScheme ,
8
8
BLSBN254SignatureScheme__factory ,
9
9
UUPSProxy__factory ,
10
- BLS__factory ,
11
10
} from "../../typechain-types" ;
12
11
import { bn254 } from "@kevincharm/noble-bn254-drand" ;
13
12
import { randomBytes } from "@noble/hashes/utils" ;
14
13
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers" ;
15
- import { expect , use } from "chai" ;
14
+ import { expect } from "chai" ;
16
15
import {
17
16
AbiCoder ,
18
17
parseEther ,
@@ -23,10 +22,8 @@ import {
23
22
keccak256 ,
24
23
toUtf8Bytes ,
25
24
ZeroAddress ,
26
- hexlify ,
27
25
} from "ethers" ;
28
26
import { ethers } from "hardhat" ;
29
- import { parse } from "path" ;
30
27
31
28
const DST_CHAIN_ID = 137 ;
32
29
@@ -344,7 +341,7 @@ describe("Router", function () {
344
341
}
345
342
346
343
const routerInterface = Router__factory . createInterface ( ) ;
347
- const [ requestId , message ] = extractSingleLog (
344
+ const [ requestId ] = extractSingleLog (
348
345
routerInterface ,
349
346
receipt ,
350
347
await router . getAddress ( ) ,
@@ -410,7 +407,7 @@ describe("Router", function () {
410
407
}
411
408
412
409
const routerInterface = Router__factory . createInterface ( ) ;
413
- const [ requestId , message ] = extractSingleLog (
410
+ const [ requestId ] = extractSingleLog (
414
411
routerInterface ,
415
412
receipt ,
416
413
await router . getAddress ( ) ,
@@ -573,10 +570,14 @@ describe("Router", function () {
573
570
expect ( await dstToken . balanceOf ( recipientAddr ) ) . to . equal ( amount ) ;
574
571
575
572
// Check receipt
576
- const receipt = await router . swapRequestReceipts ( requestId ) ;
577
- expect ( receipt . fulfilled ) . to . be . true ;
578
- expect ( receipt . amountOut ) . to . equal ( amount ) ;
579
- expect ( receipt . solver ) . to . equal ( solverRefundAddr ) ;
573
+ const swapRequestReceipt = await router . getSwapRequestReceipt ( requestId ) ;
574
+ const [ , , , , , fulfilled , solverFromReceipt , , amountOut ] = swapRequestReceipt ;
575
+
576
+ expect ( fulfilled ) . to . be . true ;
577
+ expect ( amountOut ) . to . equal ( amount ) ;
578
+ // solver address in the receipt should match the solver who called relayTokens
579
+ expect ( solverFromReceipt ) . to . equal ( solverRefundAddr ) ;
580
+ expect ( solverAddr ) . to . not . equal ( solverRefundAddr ) ;
580
581
581
582
expect ( ( await router . getFulfilledTransfers ( ) ) . includes ( requestId ) ) . to . be . equal ( true ) ;
582
583
expect ( ( await router . getFulfilledTransfers ( ) ) . length ) . to . be . equal ( 1 ) ;
@@ -626,29 +627,27 @@ describe("Router", function () {
626
627
627
628
// Relay tokens
628
629
await expect (
629
- router
630
- . connect ( solver )
631
- . relayTokens (
632
- ZeroAddress ,
633
- requestId ,
634
- userAddr ,
635
- recipientAddr ,
636
- await srcToken . getAddress ( ) ,
637
- await dstToken . getAddress ( ) ,
638
- amount ,
639
- srcChainId ,
640
- nonce ,
641
- ) ,
630
+ router . connect ( solver ) . relayTokens (
631
+ ZeroAddress , // zero address in place of solverRefundAddress should revert
632
+ requestId ,
633
+ userAddr ,
634
+ recipientAddr ,
635
+ await srcToken . getAddress ( ) ,
636
+ await dstToken . getAddress ( ) ,
637
+ amount ,
638
+ srcChainId ,
639
+ nonce ,
640
+ ) ,
642
641
) . to . revertedWithCustomError ( router , "ZeroAddress()" ) ;
643
642
644
643
// Check recipient balance after transfer
645
644
expect ( await dstToken . balanceOf ( recipientAddr ) ) . to . equal ( 0n ) ;
646
645
647
646
// Check receipt
648
- const receipt = await router . swapRequestReceipts ( requestId ) ;
649
- expect ( receipt . fulfilled ) . to . be . false ;
650
- expect ( receipt . amountOut ) . to . equal ( 0n ) ;
651
- expect ( receipt . solver ) . to . equal ( ZeroAddress ) ;
647
+ const [ , , , , , fulfilled , solverFromReceipt , , amountOut ] = await router . swapRequestReceipts ( requestId ) ;
648
+ expect ( fulfilled ) . to . be . false ;
649
+ expect ( amountOut ) . to . equal ( 0n ) ;
650
+ expect ( solverFromReceipt ) . to . equal ( ZeroAddress ) ;
652
651
653
652
expect ( ( await router . getFulfilledTransfers ( ) ) . includes ( requestId ) ) . to . be . equal ( false ) ;
654
653
expect ( ( await router . getFulfilledTransfers ( ) ) . length ) . to . be . equal ( 0n ) ;
@@ -664,7 +663,7 @@ describe("Router", function () {
664
663
router
665
664
. connect ( solver )
666
665
. relayTokens (
667
- userAddr ,
666
+ solverRefundAddr ,
668
667
requestId ,
669
668
userAddr ,
670
669
recipientAddr ,
@@ -676,7 +675,11 @@ describe("Router", function () {
676
675
) ,
677
676
) . to . emit ( router , "SwapRequestFulfilled" ) ;
678
677
678
+ // Check fulfilled transfers
679
679
expect ( ( await router . getFulfilledTransfers ( ) ) . length ) . to . be . equal ( 1 ) ;
680
+
681
+ // Check recipient balance after transfer
682
+ expect ( await dstToken . balanceOf ( recipientAddr ) ) . to . equal ( amount ) ;
680
683
} ) ;
681
684
682
685
it ( "should revert if source chain id is the same as the destination chain id" , async ( ) => {
@@ -952,20 +955,18 @@ describe("Router", function () {
952
955
expect ( ( await router . getFulfilledTransfers ( ) ) . length ) . to . be . equal ( 1 ) ;
953
956
954
957
const swapRequestReceipt = await router . getSwapRequestReceipt ( requestId ) ;
958
+ const [ , , , srcTokenAddr , dstTokenAddr , fulfilled , sender , recipient , amountOut ] = swapRequestReceipt ;
959
+
955
960
// Check receipt values
956
- expect ( swapRequestReceipt [ 0 ] ) . to . equal ( requestId ) ;
957
- expect ( swapRequestReceipt [ 1 ] ) . to . equal ( srcChainId ) ;
958
- expect ( swapRequestReceipt [ 2 ] ) . to . equal ( await router . getChainID ( ) ) ;
959
- expect ( swapRequestReceipt [ 3 ] ) . to . equal ( await dstToken . getAddress ( ) ) ;
960
- expect ( swapRequestReceipt [ 4 ] ) . to . be . true ;
961
- expect ( swapRequestReceipt [ 5 ] ) . to . equal ( solverRefundAddr ) ;
962
- expect ( swapRequestReceipt [ 6 ] ) . to . equal ( recipientAddr ) ;
963
- expect ( swapRequestReceipt [ 7 ] ) . to . equal ( amount ) ;
964
-
965
- // Check transaction receipt values compared to emitted event
966
- expect ( reqId ) . to . equal ( swapRequestReceipt [ 0 ] ) ;
967
- expect ( sourceChainId ) . to . equal ( swapRequestReceipt [ 1 ] ) ;
968
- expect ( dstChainId ) . to . equal ( swapRequestReceipt [ 2 ] ) ;
961
+ expect ( reqId ) . to . equal ( requestId ) ;
962
+ expect ( sourceChainId ) . to . equal ( srcChainId ) ;
963
+ expect ( dstChainId ) . to . equal ( await router . getChainID ( ) ) ;
964
+ expect ( srcTokenAddr ) . to . equal ( await srcToken . getAddress ( ) ) ;
965
+ expect ( dstTokenAddr ) . to . equal ( await dstToken . getAddress ( ) ) ;
966
+ expect ( fulfilled ) . to . be . true ;
967
+ expect ( sender ) . to . equal ( solverRefundAddr ) ;
968
+ expect ( recipient ) . to . equal ( recipientAddr ) ;
969
+ expect ( amountOut ) . to . equal ( amount ) ;
969
970
970
971
// Check recipient balance after transfer
971
972
expect ( await dstToken . balanceOf ( recipientAddr ) ) . to . equal ( amount ) ;
@@ -1490,7 +1491,8 @@ describe("Router", function () {
1490
1491
[ sigPointToAffine . x , sigPointToAffine . y ] ,
1491
1492
) ;
1492
1493
1493
- const tx = await router . setMinimumContractUpgradeDelay ( newDelay , sigBytes ) ;
1494
+ // anyone can call this function, not just owner
1495
+ const tx = await router . connect ( solver ) . setMinimumContractUpgradeDelay ( newDelay , sigBytes ) ;
1494
1496
await expect ( tx ) . to . emit ( router , "MinimumContractUpgradeDelayUpdated" ) . withArgs ( newDelay ) ;
1495
1497
1496
1498
expect ( await router . minimumContractUpgradeDelay ( ) ) . to . equal ( newDelay ) ;
0 commit comments