@@ -2,7 +2,6 @@ import sinon from "sinon";
2
2
import { expect } from "chai" ;
3
3
import {
4
4
Account ,
5
- BlockJSON ,
6
5
AleoNetworkClient ,
7
6
TransactionObject ,
8
7
InputObject ,
@@ -17,6 +16,7 @@ import {
17
16
Transition ,
18
17
TransitionObject ,
19
18
} from "@provablehq/sdk/%%NETWORK%%.js" ;
19
+ import { BlockJSON } from "../src/models/blockJSON" ;
20
20
import { beaconPrivateKeyString } from "./data/account-data" ;
21
21
22
22
async function catchError ( f : ( ) => Promise < any > ) : Promise < Error | null > {
@@ -33,7 +33,7 @@ async function catchError(f: () => Promise<any>): Promise<Error | null> {
33
33
async function expectThrowsMessage ( f : ( ) => Promise < any > , message : string ) : Promise < void > {
34
34
const error = await catchError ( f ) ;
35
35
expect ( error ) . not . equal ( null ) ;
36
- expect ( error ! . message ) . equal ( message ) ;
36
+ expect ( error ! . message ) . contains ( message ) ;
37
37
}
38
38
async function expectThrows ( f : ( ) => Promise < any > ) : Promise < void > {
39
39
const error = await catchError ( f ) ;
@@ -69,32 +69,57 @@ describe('NodeConnection', () => {
69
69
} ) ;
70
70
71
71
describe ( 'getBlock' , ( ) => {
72
- it . skip ( 'should return a Block object' , async ( ) => {
72
+ it ( 'should return a Block object' , async ( ) => {
73
73
const block = await connection . getBlock ( 1 ) ;
74
- expect ( ( block as BlockJSON ) . block_hash ) . equal ( "ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me" ) ;
74
+ if ( network === "testnet" ) {
75
+ expect ( ( block as BlockJSON ) . block_hash ) . equal ( "ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me" ) ;
76
+ } else {
77
+ expect ( ( block as BlockJSON ) . block_hash ) . equal ( "ab1yvrttjzr7d9tu2a6e8n0908amgyjddgv6mmndh75rxkwa44hcugqy3wtc2" ) ;
78
+ }
75
79
} ) ;
76
80
77
81
it ( 'should throw an error if the request fails' , async ( ) => {
78
82
await expectThrowsMessage (
79
83
( ) => connection . getBlock ( 99999999 ) ,
80
- "Error fetching block. " ,
84
+ "Error fetching block 99999999 " ,
81
85
) ;
82
86
} ) ;
83
87
} ) ;
84
88
89
+ describe ( 'getBlockByHash' , ( ) => {
90
+ it ( 'should return a Block object' , async ( ) => {
91
+ let hash = network === "testnet" ?
92
+ "ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me" : "ab1yvrttjzr7d9tu2a6e8n0908amgyjddgv6mmndh75rxkwa44hcugqy3wtc2" ;
93
+ const block = await connection . getBlockByHash ( hash ) ;
94
+ expect ( ( block as BlockJSON ) . block_hash ) . equal ( hash ) ;
95
+ } ) ;
96
+
97
+ it ( 'should throw an error if the request fails' , async ( ) => {
98
+ await expectThrowsMessage (
99
+ ( ) => connection . getBlockByHash ( "ahhh" ) ,
100
+ "Error fetching block ahhh" ,
101
+ )
102
+ } ) ;
103
+ } ) ;
104
+
85
105
describe ( 'getBlockRange' , ( ) => {
86
- it . skip ( 'should return an array of Block objects' , async ( ) => {
106
+ it ( 'should return an array of Block objects' , async ( ) => {
87
107
const blockRange = await connection . getBlockRange ( 1 , 3 ) ;
88
108
expect ( Array . isArray ( blockRange ) ) . equal ( true ) ;
89
- expect ( ( blockRange as BlockJSON [ ] ) . length ) . equal ( 3 ) ;
90
- expect ( ( ( blockRange as BlockJSON [ ] ) [ 0 ] as BlockJSON ) . block_hash ) . equal ( "ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me" ) ;
91
- expect ( ( ( blockRange as BlockJSON [ ] ) [ 1 ] as BlockJSON ) . block_hash ) . equal ( "ab1uqmm97qk5gzhgwh6308h48aszazhfnn0xdq84lrj7e7myyrf9yyqmqdf42" ) ;
109
+ expect ( ( blockRange as BlockJSON [ ] ) . length ) . equal ( 2 ) ;
110
+ if ( network === "testnet" ) {
111
+ expect ( ( ( blockRange as BlockJSON [ ] ) [ 0 ] as BlockJSON ) . block_hash ) . equal ( "ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me" ) ;
112
+ expect ( ( ( blockRange as BlockJSON [ ] ) [ 1 ] as BlockJSON ) . block_hash ) . equal ( "ab1uqmm97qk5gzhgwh6308h48aszazhfnn0xdq84lrj7e7myyrf9yyqmqdf42" ) ;
113
+ } else {
114
+ expect ( ( ( blockRange as BlockJSON [ ] ) [ 0 ] as BlockJSON ) . block_hash ) . equal ( "ab1yvrttjzr7d9tu2a6e8n0908amgyjddgv6mmndh75rxkwa44hcugqy3wtc2" ) ;
115
+ expect ( ( ( blockRange as BlockJSON [ ] ) [ 1 ] as BlockJSON ) . block_hash ) . equal ( "ab17ddfwqlx3v4ke8h5l2lpcp5agk2flvpwgpd4l37peck7y7uvsqqsxvvnlr" ) ;
116
+ }
92
117
} ) ;
93
118
94
119
it ( 'should throw an error if the request fails' , async ( ) => {
95
120
await expectThrowsMessage (
96
121
( ) => connection . getBlockRange ( 999999999 , 1000000000 ) ,
97
- "Error fetching blocks between 999999999 and 1000000000. " ,
122
+ "Error fetching blocks between 999999999 and 1000000000" ,
98
123
) ;
99
124
} ) ;
100
125
} ) ;
@@ -141,6 +166,32 @@ describe('NodeConnection', () => {
141
166
} ) ;
142
167
} ) ;
143
168
169
+ describe ( 'getLatestHash' , ( ) => {
170
+ it ( 'should return a string' , async ( ) => {
171
+ const latestHash = await connection . getLatestHash ( ) ;
172
+ expect ( typeof latestHash ) . equal ( 'string' ) ;
173
+ } ) ;
174
+
175
+ it ( 'should set the X-Aleo-SDK-Version header' , async ( ) => {
176
+ expect ( windowFetchSpy . args ) . deep . equal ( [ ] ) ;
177
+
178
+ await connection . getLatestBlock ( ) ;
179
+
180
+ expect ( windowFetchSpy . args ) . deep . equal ( [
181
+ [
182
+ "https://api.explorer.provable.com/v1/%%NETWORK%%/block/latest" ,
183
+ {
184
+ "headers" : {
185
+ // @TODO : Run the Jest tests on the compiled Rollup code,
186
+ // so that way the version is properly replaced.
187
+ "X-Aleo-SDK-Version" : "%%VERSION%%"
188
+ }
189
+ }
190
+ ] ,
191
+ ] ) ;
192
+ } ) ;
193
+ } )
194
+
144
195
describe ( 'getLatestCommittee' , ( ) => {
145
196
it ( 'should return a string' , async ( ) => {
146
197
const latestCommittee = await connection . getLatestCommittee ( ) ;
@@ -170,6 +221,31 @@ describe('NodeConnection', () => {
170
221
} ) ;
171
222
} ) ;
172
223
224
+ describe ( 'getTransactionsByHash' , ( ) => {
225
+ it ( 'should return an array of Transaction objects' , async ( ) => {
226
+ const hash = network === 'testnet' ?
227
+ 'ab1sm6kyqle2ftg4z8gegafqrjy0jwjhzu6fmy73726dgszrtxhxvfqha0eee' : 'ab19dklwl9vp63zu3hwg57wyhvmqf92fx5g8x0t6dr72py8r87pxupqfne5t9' ;
228
+ const transactions = await connection . getTransactionsByHash ( hash ) ;
229
+ expect ( transactions . length ) . equals ( 4 ) ;
230
+ } )
231
+ } ) ;
232
+
233
+ describe ( 'getConfirmedTransaction' , ( ) => {
234
+ it ( 'should return a ConfirmedTransaction object' , async ( ) => {
235
+ const transactionId = network === 'testnet' ?
236
+ 'at13rluumel7k9cnpaulhj7lwcsc8ntqn7wkv509fye848atczwxgpqqh2p43' : 'at1uushc49p5ldhdqtkuw0gvfzrednnvzd55yrxkx5uqksjj5cqecpscgavk8' ;
237
+ const transaction = await connection . getConfirmedTransaction ( transactionId ) ;
238
+ expect ( transaction . transaction . id ) . equals ( transactionId ) ;
239
+ } ) ;
240
+
241
+ it ( 'should throw an error if the request fails' , async ( ) => {
242
+ await expectThrowsMessage (
243
+ ( ) => connection . getConfirmedTransaction ( 'badTransactionId' ) ,
244
+ 'Error fetching confirmed transaction badTransactionId' ,
245
+ ) ;
246
+ } ) ;
247
+ } )
248
+
173
249
describe ( 'getProgramImports' , ( ) => {
174
250
it ( 'should return the correct program import names' , async ( ) => {
175
251
const creditImports = await connection . getProgramImportNames ( "credits.aleo" ) ;
0 commit comments