File tree 1 file changed +16
-5
lines changed 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change 1
1
const { Client, AccountBalanceQuery } = require ( "@hashgraph/sdk" ) ;
2
2
3
3
describe ( "CommonJS" , function ( ) {
4
- it ( "it should query each node's balance" , async function ( ) {
4
+ it ( "should query each node's balance" , async function ( ) {
5
5
const client = Client . forTestnet ( ) ;
6
6
7
+ let succeededAtLeastOnce = false ;
8
+
9
+ // Iterate over the nodes in the network
7
10
for ( const [ , nodeAccountId ] of Object . entries ( client . network ) ) {
8
- await new AccountBalanceQuery ( )
9
- . setNodeAccountIds ( [ nodeAccountId ] )
10
- . setAccountId ( nodeAccountId )
11
- . execute ( client ) ;
11
+ try {
12
+ await new AccountBalanceQuery ( )
13
+ . setNodeAccountIds ( [ nodeAccountId ] )
14
+ . setAccountId ( nodeAccountId )
15
+ . execute ( client ) ;
16
+ succeededAtLeastOnce = true ;
17
+ } catch ( error ) {
18
+ console . log ( `Failed for ${ nodeAccountId } ` ) ;
19
+ }
12
20
}
13
21
client . close ( ) ;
22
+ if ( ! succeededAtLeastOnce ) {
23
+ throw new Error ( "No successful query attempts were made." ) ;
24
+ }
14
25
} ) ;
15
26
} ) ;
You can’t perform that action at this time.
0 commit comments