@@ -6,8 +6,16 @@ import { SharedArray } from 'k6/data';
66import  {  check  }  from  'k6' ; 
77import  ws  from  'k6/ws' ; 
88
9- const  {  HD_ACTIVE_ADDR_COUNT ,  HD_MAX_TX_HISTORY ,  TARGET_NET ,  WALLETS  }  =  Object . assign ( 
10-   {  HD_ACTIVE_ADDR_COUNT : '10' ,  HD_MAX_TX_HISTORY : '100' ,  TARGET_NET : 'mainnet' ,  WALLETS : '100'  } , 
9+ const  parameters  =  Object . assign ( 
10+   { 
11+     CONNECTIONS_SECONDS : '3' , 
12+     HD_ACTIVE_ADDR_COUNT : '10' , 
13+     HD_MAX_TX_HISTORY : '100' , 
14+     IDLE_SECONDS : '60' , 
15+     TARGET_NET : 'mainnet' , 
16+     WALLET_RESTORATION : 'false' , 
17+     WALLETS : '100' 
18+   } , 
1119  // eslint-disable-next-line no-undef 
1220  __ENV 
1321) ; 
@@ -16,9 +24,12 @@ const { HD_ACTIVE_ADDR_COUNT, HD_MAX_TX_HISTORY, TARGET_NET, WALLETS } = Object.
1624const  dut  =  k6Utils . getDut ( __ENV ,  {  networks : [ 'mainnet' ,  'preprod' ]  } ) ; 
1725const  url  =  `wss://${ dut }  /ws` ; 
1826
19- const  activeAddrCount  =  Number . parseInt ( HD_ACTIVE_ADDR_COUNT ,  10 ) ; 
20- const  maxTxHistory  =  Number . parseInt ( HD_MAX_TX_HISTORY ,  10 ) ; 
21- const  numWallets  =  Number . parseInt ( WALLETS ,  10 ) ; 
27+ const  activeAddrCount  =  Number . parseInt ( parameters . HD_ACTIVE_ADDR_COUNT ,  10 ) ; 
28+ const  idleSeconds  =  Number . parseInt ( parameters . IDLE_SECONDS ,  10 ) ; 
29+ const  connectionsSeconds  =  Number . parseInt ( parameters . CONNECTIONS_SECONDS ,  10 ) ; 
30+ const  maxTxHistory  =  Number . parseInt ( parameters . HD_MAX_TX_HISTORY ,  10 ) ; 
31+ const  numWallets  =  Number . parseInt ( parameters . WALLETS ,  10 ) ; 
32+ const  walletRestoration  =  parameters . WALLETS  ===  'true' ; 
2233
2334export  const  options  =  { 
2435  ext : { 
@@ -31,15 +42,15 @@ export const options = {
3142    connections : { 
3243      executor : 'ramping-vus' , 
3344      gracefulRampDown : '0s' , 
34-       gracefulStop : '10m ' , 
35-       stages : [ {  duration : '3s' ,  target : numWallets  } ] , 
45+       gracefulStop : '60m ' , 
46+       stages : [ {  duration : ` ${ connectionsSeconds } s` ,  target : numWallets  } ] , 
3647      startVUs : 1 
3748    } 
3849  } 
3950} ; 
4051
4152/** Wallet addresses extracted from the JSON dump file */ 
42- const  fileName  =  `../../dump/addresses/${ TARGET_NET }  .json` ; 
53+ const  fileName  =  `../../dump/addresses/${ parameters . TARGET_NET }  .json` ; 
4354// eslint-disable-next-line no-undef 
4455const  walletsOrig  =  new  SharedArray ( 'walletsData' ,  ( )  =>  JSON . parse ( open ( fileName ) ) ) ; 
4556
@@ -77,7 +88,9 @@ export const run = ({ wallets }) => {
7788  const  vu  =  __VU ; 
7889  const  wallet  =  wallets [ vu  %  wallets . length ] ;  // each wallet is a collection of addresses 
7990
91+   // eslint-disable-next-line sonarjs/cognitive-complexity 
8092  const  res  =  ws . connect ( url ,  null ,  ( socket )  =>  { 
93+     let  blockNo  =  0 ; 
8194    let  closed  =  false ; 
8295    let  requestId  =  0 ; 
8396    let  transactionsCount  =  0 ; 
@@ -92,23 +105,31 @@ export const run = ({ wallets }) => {
92105        return  socket . setTimeout ( ( )  =>  { 
93106          closed  =  true ; 
94107          socket . close ( ) ; 
95-         } ,  1000 ) ; 
108+         } ,  idleSeconds   *   1000 ) ; 
96109      } 
97110
98111      const  address  = 
99112        requestId  <=  wallet . length 
100113          ? wallet [ requestId  -  1 ] . address 
101114          : getDummyAddr ( wallet [ 0 ] . address ,  requestId  -  wallet . length ) ; 
102115
103-       socket . send ( JSON . stringify ( {  requestId,  txsByAddresses : {  addresses : [ address ] ,  lower : 0  }  } ) ) ; 
116+       const  lower  =  walletRestoration  ? 0  : blockNo ; 
117+ 
118+       socket . send ( JSON . stringify ( {  requestId,  txsByAddresses : {  addresses : [ address ] ,  lower }  } ) ) ; 
104119    } ; 
105120
106121    socket . on ( 'message' ,  ( message )  =>  { 
107-       const  {  clientId,  responseTo,  transactions }  =  JSON . parse ( message ) ; 
122+       const  {  clientId,  networkInfo ,   responseTo,  transactions }  =  JSON . parse ( message ) ; 
108123
124+       // Set operational stat 
109125      if  ( clientId )  operationalTrend . add ( Date . now ( )  -  begin ) ; 
126+ 
127+       // Perform init with or without restoration 
128+       if  ( networkInfo )  ( {  blockNo }  =  networkInfo . ledgerTip ) ; 
110129      if  ( clientId  ||  responseTo )  nextAddress ( ) ; 
111-       if  ( transactions )  transactionsCount  +=  transactions . length ; 
130+ 
131+       // Count the incoming transactions 
132+       if  ( Array . isArray ( transactions ) )  transactionsCount  +=  transactions . length ; 
112133    } ) ; 
113134
114135    // Count unexpected close 
0 commit comments