@@ -8,7 +8,7 @@ import { increase } from "@nomicfoundation/hardhat-network-helpers/dist/src/help
88
99import { Depositor } from "@ethers-v6" ;
1010
11- import { Reverter , poseidonHash , getPoseidon } from "@utils" ;
11+ import { Reverter , getPoseidon } from "@utils" ;
1212import { impersonateAccount , setBalance , time } from "@nomicfoundation/hardhat-network-helpers" ;
1313
1414describe ( "Taprootized Atomic Swaps" , ( ) => {
@@ -38,16 +38,14 @@ describe("Taprootized Atomic Swaps", () => {
3838
3939 afterEach ( reverter . revert ) ;
4040
41- function generateSecret ( ) : [ string [ ] , string ] {
42- const part1 = ethers . hexlify ( ethers . randomBytes ( 8 ) ) ;
43- const part2 = ethers . hexlify ( ethers . randomBytes ( 8 ) ) ;
44- const part3 = ethers . hexlify ( ethers . randomBytes ( 8 ) ) ;
45- const part4 = ethers . hexlify ( ethers . randomBytes ( 8 ) ) ;
41+ function generateSecret ( ) : [ string , string ] {
42+ const parts = [ 1 , 2 , 3 , 4 ] . map ( ( ) => ethers . hexlify ( ethers . randomBytes ( 8 ) ) ) ;
43+ const wholeSecret = "0x" + parts . map ( ( hexString : string ) => hexString . replace ( "0x" , "" ) ) . join ( "" ) ;
4644
47- const inputs = [ part1 , part2 , part3 , part4 ] . map ( ( v ) => BigInt ( v ) ) ;
45+ const inputs = parts . map ( ( v ) => BigInt ( v ) ) ;
4846 const secretHash = ethers . toBeHex ( Poseidon . hash ( inputs ) , 32 ) ;
4947
50- return [ inputs . map ( ( v ) => ethers . toBeHex ( v , 32 ) ) , secretHash ] ;
48+ return [ wholeSecret , secretHash ] ;
5149 }
5250
5351 it ( "should deposit ETH with correct details" , async ( ) => {
@@ -80,7 +78,7 @@ describe("Taprootized Atomic Swaps", () => {
8078 } ) ;
8179
8280 it ( "should revert if trying to deposit with same secret hash" , async ( ) => {
83- const [ secret , secretHash ] = generateSecret ( ) ;
81+ const [ , secretHash ] = generateSecret ( ) ;
8482
8583 await depositor . deposit ( USER2 . address , secretHash , LOCK_TIME , { value : DEPOSIT_AMOUNT } ) ;
8684
@@ -90,15 +88,15 @@ describe("Taprootized Atomic Swaps", () => {
9088 } ) ;
9189
9290 it ( "should reject deposit to zero address" , async ( ) => {
93- const [ secret , secretHash ] = generateSecret ( ) ;
91+ const [ , secretHash ] = generateSecret ( ) ;
9492
9593 await expect (
9694 depositor . deposit ( ethers . ZeroAddress , secretHash , LOCK_TIME , { value : DEPOSIT_AMOUNT } )
9795 ) . to . be . revertedWithCustomError ( depositor , "ZeroAddressNotAllowed" ) ;
9896 } ) ;
9997
10098 it ( "should reject deposit with insufficient amount" , async ( ) => {
101- const [ secret , secretHash ] = generateSecret ( ) ;
99+ const [ , secretHash ] = generateSecret ( ) ;
102100
103101 await expect ( depositor . deposit ( USER2 . address , secretHash , LOCK_TIME , { value : 0 } ) ) . to . be . revertedWithCustomError (
104102 depositor ,
@@ -112,7 +110,7 @@ describe("Taprootized Atomic Swaps", () => {
112110
113111 await depositor . deposit ( USER2 . address , secretHash , LOCK_TIME , { value : DEPOSIT_AMOUNT } ) ;
114112
115- await expect ( depositor . withdraw ( [ incorrectSecret [ 0 ] , incorrectSecret [ 1 ] , incorrectSecret [ 2 ] , incorrectSecret [ 3 ] ] ) )
113+ await expect ( depositor . withdraw ( incorrectSecret ) )
116114 . to . be . revertedWithCustomError ( depositor , "DepositDoesNotExist" )
117115 . withArgs ( incorrectSecretHash ) ;
118116 } ) ;
@@ -122,7 +120,7 @@ describe("Taprootized Atomic Swaps", () => {
122120
123121 await depositor . deposit ( USER2 . address , secretHash , LOCK_TIME , { value : DEPOSIT_AMOUNT } ) ;
124122
125- await expect ( depositor . withdraw ( [ secret [ 0 ] , secret [ 1 ] , secret [ 2 ] , secret [ 3 ] ] ) )
123+ await expect ( depositor . withdraw ( secret ) )
126124 . to . emit ( depositor , "Withdrawn" )
127125 . withArgs ( USER2 . address , DEPOSIT_AMOUNT , secret , secretHash ) ;
128126 } ) ;
@@ -132,9 +130,9 @@ describe("Taprootized Atomic Swaps", () => {
132130
133131 await depositor . deposit ( USER2 . address , secretHash , LOCK_TIME , { value : DEPOSIT_AMOUNT } ) ;
134132
135- await depositor . withdraw ( [ secret [ 0 ] , secret [ 1 ] , secret [ 2 ] , secret [ 3 ] ] ) ;
133+ await depositor . withdraw ( secret ) ;
136134
137- await expect ( depositor . withdraw ( [ secret [ 0 ] , secret [ 1 ] , secret [ 2 ] , secret [ 3 ] ] ) )
135+ await expect ( depositor . withdraw ( secret ) )
138136 . to . be . revertedWithCustomError ( depositor , "DepositAlreadyWithdrawn" )
139137 . withArgs ( secretHash ) ;
140138 } ) ;
@@ -144,14 +142,11 @@ describe("Taprootized Atomic Swaps", () => {
144142
145143 await depositor . deposit ( await depositor . getAddress ( ) , secretHash , LOCK_TIME , { value : DEPOSIT_AMOUNT } ) ;
146144
147- await expect ( depositor . withdraw ( [ secret [ 0 ] , secret [ 1 ] , secret [ 2 ] , secret [ 3 ] ] ) ) . to . be . revertedWithCustomError (
148- depositor ,
149- "FailedInnerCall"
150- ) ;
145+ await expect ( depositor . withdraw ( secret ) ) . to . be . revertedWithCustomError ( depositor , "FailedInnerCall" ) ;
151146 } ) ;
152147
153148 it ( "should reject restoring before lock time expires" , async ( ) => {
154- const [ secret , secretHash ] = generateSecret ( ) ;
149+ const [ , secretHash ] = generateSecret ( ) ;
155150
156151 const nextBlockTimestamp = ( await time . latest ( ) ) + 1 ;
157152 await time . setNextBlockTimestamp ( nextBlockTimestamp ) ;
@@ -172,7 +167,7 @@ describe("Taprootized Atomic Swaps", () => {
172167 } ) ;
173168
174169 it ( "should reject restoring if the ETH transfer fails" , async ( ) => {
175- const [ secret , secretHash ] = generateSecret ( ) ;
170+ const [ , secretHash ] = generateSecret ( ) ;
176171
177172 await impersonateAccount ( await depositor . getAddress ( ) ) ;
178173 const depositorAsSigner = await ethers . getSigner ( await depositor . getAddress ( ) ) ;
@@ -190,7 +185,7 @@ describe("Taprootized Atomic Swaps", () => {
190185
191186 await depositor . deposit ( USER2 . address , secretHash , LOCK_TIME , { value : DEPOSIT_AMOUNT } ) ;
192187
193- await depositor . withdraw ( [ secret [ 0 ] , secret [ 1 ] , secret [ 2 ] , secret [ 3 ] ] ) ;
188+ await depositor . withdraw ( secret ) ;
194189
195190 await increase ( LOCK_TIME ) ;
196191
0 commit comments