1- import { NODE_URL } from '../_state' ;
1+ // import {NODE_URL} from '../_state';
22import { create } from '../../src' ;
33import { fetchHeadersAt , fetchHeadersLast , IBlockHeader } from '../../src/api-node/blocks' ;
44
5-
5+ const NODE_URL = "https://nodes-testnet.wavesnodes.com"
66const api = create ( NODE_URL ) ;
77
88const checkBlockHeader = ( block : IBlockHeader ) => {
@@ -24,6 +24,35 @@ const checkBlockHeader = (block: IBlockHeader) => {
2424 expect ( typeof block [ "nxt-consensus" ] [ "generation-signature" ] ) . toBe ( 'string' )
2525} ;
2626
27+ const checkChallengedBlockHeader = ( block : IBlockHeader ) => {
28+ expect ( typeof block . blocksize ) . toBe ( 'number' ) ;
29+ expect ( typeof block . reward ) . toBe ( 'number' ) ;
30+ expect ( typeof block . desiredReward ) . toBe ( 'number' ) ;
31+ expect ( typeof block . signature ) . toBe ( 'string' ) ;
32+ expect ( typeof block . generator ) . toBe ( 'string' ) ;
33+ expect ( typeof block . version ) . toBe ( 'number' ) ;
34+ expect ( typeof block . reference ) . toBe ( 'string' ) ;
35+ expect ( block . features ) . toBeInstanceOf ( Array )
36+ expect ( typeof block . totalFee ) . toBe ( 'number' ) ;
37+ expect ( typeof block . transactionCount ) . toBe ( 'number' ) ;
38+ expect ( typeof block . timestamp ) . toBe ( 'number' ) ;
39+ expect ( typeof block . height ) . toBe ( 'number' ) ;
40+ expect ( typeof block . VRF ) . toBe ( 'string' ) ;
41+ expect ( typeof block . id ) . toBe ( 'string' ) ;
42+ expect ( typeof block [ "nxt-consensus" ] [ "base-target" ] ) . toBe ( 'number' )
43+ expect ( typeof block [ "nxt-consensus" ] [ "generation-signature" ] ) . toBe ( 'string' )
44+ expect ( typeof block . challengedHeader ?. headerSignature ) . toBe ( 'string' )
45+ expect ( block . challengedHeader ?. features ) . toBeInstanceOf ( Array )
46+ expect ( typeof block . challengedHeader ?. generatorPublicKey ) . toBe ( 'string' )
47+ expect ( typeof block . challengedHeader ?. desiredReward ) . toBe ( 'number' )
48+ expect ( typeof block . challengedHeader ?. stateHash ) . toBe ( 'string' )
49+ expect ( typeof block . stateHash ) . toBe ( 'string' )
50+ }
51+
52+ it ( 'fetch challenged block' , async ( ) => {
53+ checkChallengedBlockHeader ( await api . blocks . fetchHeadersAt ( 34 ) )
54+ } )
55+
2756it ( 'fetchHeadersLast' , async ( ) => {
2857 checkBlockHeader ( await api . blocks . fetchHeadersLast ( ) ) ;
2958 checkBlockHeader ( await fetchHeadersLast ( NODE_URL ) ) ;
@@ -76,47 +105,47 @@ it('first block', async () => {
76105} ) ;
77106
78107it ( 'fetch block delay' , async ( ) => {
79- const { height } = await api . blocks . fetchHeadersLast ( ) ;
80- const { id } = await api . blocks . fetchHeadersAt ( Math . floor ( height / 2 ) ) ;
81- const { delay } = await api . blocks . fetchDelay ( id , height ) ;
108+ const { height} = await api . blocks . fetchHeadersLast ( ) ;
109+ const { id } = await api . blocks . fetchHeadersAt ( Math . floor ( height / 2 ) ) ;
110+ const { delay} = await api . blocks . fetchDelay ( id , height ) ;
82111 expect ( typeof delay ) . toBe ( 'number' ) ;
83112} ) ;
84113
85114it ( 'block last' , async ( ) => {
86- const block = await api . blocks . fetchLast ( ) ;
115+ const block = await api . blocks . fetchLast ( ) ;
87116 checkBlockHeader ( block ) ;
88117 expect ( block . transactions ) . toBeInstanceOf ( Array ) ;
89118 expect ( block . transactionCount ) . toBe ( block . transactions . length ) ;
90119} ) ;
91120
92121it ( 'block at' , async ( ) => {
93- const { height } = await api . blocks . fetchHeadersLast ( ) ;
94- const block = await api . blocks . fetchBlockAt ( height - 1 ) ;
122+ const { height} = await api . blocks . fetchHeadersLast ( ) ;
123+ const block = await api . blocks . fetchBlockAt ( height - 1 ) ;
95124 checkBlockHeader ( block ) ;
96125 expect ( block . transactions ) . toBeInstanceOf ( Array ) ;
97126 expect ( block . transactionCount ) . toBe ( block . transactions . length ) ;
98127} ) ;
99128
100129it ( 'blocks by address' , async ( ) => {
101- const { generator, height } = await api . blocks . fetchHeadersLast ( ) ;
130+ const { generator, height} = await api . blocks . fetchHeadersLast ( ) ;
102131 const minHeight = height - 10 > 1 ? height - 10 : 2 ;
103- const blocks = await api . blocks . fetchBlocksByAddress ( generator , minHeight , height ) ;
132+ const blocks = await api . blocks . fetchBlocksByAddress ( generator , minHeight , height ) ;
104133
105134 blocks . forEach ( checkBlockHeader ) ;
106135} ) ;
107136
108137it ( 'block by id' , async ( ) => {
109- const { id } = await api . blocks . fetchHeadersLast ( ) ;
110- const block = await api . blocks . fetchBlockById ( id ) ;
138+ const { id } = await api . blocks . fetchHeadersLast ( ) ;
139+ const block = await api . blocks . fetchBlockById ( id ) ;
111140
112141 checkBlockHeader ( block ) ;
113142 expect ( block . transactions ) . toBeInstanceOf ( Array ) ;
114143 expect ( block . transactionCount ) . toBe ( block . transactions . length ) ;
115144} ) ;
116145
117146it ( 'block headers by id' , async ( ) => {
118- const { id } = await api . blocks . fetchHeadersLast ( ) ;
119- const block = await api . blocks . fetchHeadersById ( id ) ;
147+ const { id } = await api . blocks . fetchHeadersLast ( ) ;
148+ const block = await api . blocks . fetchHeadersById ( id ) ;
120149
121150 checkBlockHeader ( block ) ;
122151} ) ;
0 commit comments