@@ -28,46 +28,50 @@ async function getTransactionHeight(channel: Channel, txnId: string) {
28
28
} )
29
29
}
30
30
31
- async function getBigestBlock ( channel : Channel , height : number ) {
31
+ async function loadBlocks ( channel : Channel , fromHeight : number , toHeight : number ) {
32
+ let n = 0
32
33
return new Promise < number > ( ( resolve , reject ) => {
33
- const blocksApi = w . api . waves . node . grpc . mkBlocksApi ( channel )
34
+ const blocksApi = w . api . waves . events . grpc . mkBlockchainUpdatesApi ( channel )
34
35
blocksApi
35
- . getBlock ( {
36
- height : height ,
37
- includeTransactions : true
38
- } ,
39
- ( error , response ) => {
40
- if ( error ) return reject ( error ) ;
41
- if ( ! response ) return reject ( "Block not found" ) ;
42
-
43
- resolve ( response . height ) ;
44
- }
45
- )
36
+ . subscribe ( {
37
+ fromHeight : fromHeight ,
38
+ toHeight : toHeight ,
39
+ } )
40
+ . on ( "data" , ( item : w . api . waves . events . grpc . SubscribeEvent ) => {
41
+ n += 1
42
+ } )
43
+ . on ( "error" , ( e : Error ) => reject ( e ) )
44
+ . on ( "end" , ( ) => resolve ( n ) )
46
45
} )
47
46
}
48
47
49
- describe ( 'Waves gRPC API' , ( ) => {
50
- let channel = w . grpc . mkDefaultChannel ( 'grpc.wavesnodes.com:6870' )
48
+ describe ( 'Waves gRPC API' , function ( ) {
49
+ this . timeout ( 5000 )
50
+
51
+ let grpcChannel = w . grpc . mkDefaultChannel ( 'grpc.wavesnodes.com:6870' )
52
+ let updatesChannel = w . grpc . mkDefaultChannel ( 'grpc.wavesnodes.com:6881' )
51
53
52
54
// One request
53
55
it ( '#AccountsApi.resolveAlias - resolves an alias' , async ( ) => {
54
- let address = await resolveAlias ( channel , 'likli' )
56
+ let address = await resolveAlias ( grpcChannel , 'likli' )
55
57
assert . equal ( address , '3PNaua1fMrQm4TArqeTuakmY1u985CgMRk6' )
56
58
} )
57
59
58
60
// Stream
59
61
it ( '#TransactionApi.getTransaction - finds a transaction' , async ( ) => {
60
- let txnHeight = await getTransactionHeight ( channel , '287XcMXPDY7pnw2tECbV86TZetPi2x9JBg9BVUsGaSJx' )
62
+ let txnHeight = await getTransactionHeight ( grpcChannel , '287XcMXPDY7pnw2tECbV86TZetPi2x9JBg9BVUsGaSJx' )
61
63
assert . equal ( txnHeight , 3131305 )
62
64
} )
63
65
64
- it ( '#BlocksApi.getBlock - reads the biggest block' , async ( ) => {
65
- const height = 1
66
- const r = await getBigestBlock ( channel , height )
67
- assert . equal ( r , height )
66
+ it ( '#BlockchainUpdatesApi.subscribe - load blocks' , async ( ) => {
67
+ const fromHeight = 3371000
68
+ const toHeight = 3371001
69
+ const n = await loadBlocks ( updatesChannel , fromHeight , toHeight )
70
+ assert . equal ( n , 2 )
68
71
} )
69
72
70
73
after ( ( ) => {
71
- channel . close ( )
74
+ updatesChannel . close ( )
75
+ grpcChannel . close ( )
72
76
} )
73
77
} )
0 commit comments