1
1
use std:: {
2
2
fs,
3
3
path:: Path ,
4
+ str:: FromStr ,
4
5
thread,
5
6
time:: { Duration , Instant } ,
6
7
} ;
7
8
8
9
use avalanche_network_runner_sdk:: { BlockchainSpec , Client , GlobalConfig , StartRequest } ;
9
- use avalanche_types:: subnet;
10
+ use avalanche_types:: { ids , subnet} ;
10
11
use spacesvm:: {
11
12
self ,
12
- api:: client:: { claim_tx, get_or_create_pk, Uri } ,
13
+ api:: client:: { claim_tx, get_or_create_pk, set_tx , Uri } ,
13
14
} ;
14
15
15
16
#[ tokio:: test]
@@ -180,19 +181,34 @@ async fn e2e() {
180
181
log:: info!( "{}: {}" , node_name, iv. uri) ;
181
182
rpc_eps. push ( iv. uri . clone ( ) ) ;
182
183
}
184
+ let mut blockchain_id = ids:: Id :: empty ( ) ;
185
+ for ( k, v) in cluster_info. custom_chains . iter ( ) {
186
+ log:: info!( "custom chain info: {}={:?}" , k, v) ;
187
+ if v. chain_name == "spacesvm" {
188
+ blockchain_id = ids:: Id :: from_str ( & v. chain_id ) . unwrap ( ) ;
189
+ break ;
190
+ }
191
+ }
192
+
193
+ log:: info!( "avalanchego RPC endpoints: {:?}" , rpc_eps) ;
183
194
184
- let ep = format ! (
185
- "{}/{}" ,
186
- rpc_eps[ 0 ] . to_owned( ) ,
187
- spacesvm:: vm:: PUBLIC_API_ENDPOINT
188
- ) ;
189
195
let private_key = get_or_create_pk ( "/tmp/.spacesvm-cli-pk" ) . expect ( "generate new private key" ) ;
196
+ let chain_url = format ! ( "{}/ext/bc/{}/public" , rpc_eps[ 0 ] , blockchain_id) ;
197
+ let mut scli =
198
+ spacesvm:: api:: client:: Client :: new ( chain_url. parse :: < Uri > ( ) . expect ( "valid endpoint" ) )
199
+ . set_private_key ( private_key) ;
200
+ for ep in rpc_eps. iter ( ) {
201
+ let chain_url = format ! ( "{}/ext/bc/{}/public" , ep, blockchain_id)
202
+ . parse :: < Uri > ( )
203
+ . expect ( "valid endpoint" ) ;
204
+ scli. set_endpoint ( chain_url) ;
205
+ let resp = scli. ping ( ) . await . unwrap ( ) ;
206
+ log:: info!( "ping response from {}: {:?}" , ep, resp) ;
207
+
208
+ thread:: sleep ( Duration :: from_millis ( 300 ) ) ;
209
+ }
190
210
191
- let mut scli = spacesvm:: api:: client:: Client :: new ( ep. parse :: < Uri > ( ) . expect ( "valid endpoint" ) )
192
- . set_private_key ( private_key) ;
193
- log:: info!( "ping request..." ) ;
194
- let resp = scli. ping ( ) . await . expect ( "ping success" ) ;
195
- log:: info!( "ping response from {}: {:?}" , ep, resp) ;
211
+ scli. set_endpoint ( chain_url. parse :: < Uri > ( ) . expect ( "valid endpoint" ) ) ;
196
212
197
213
log:: info!( "decode claim tx request..." ) ;
198
214
let resp = scli
@@ -208,6 +224,20 @@ async fn e2e() {
208
224
. expect ( "issue_tx success" ) ;
209
225
log:: info!( "issue claim tx response from {}: {:?}" , ep, resp) ;
210
226
227
+ log:: info!( "decode set tx request..." ) ;
228
+ let resp = scli
229
+ . decode_tx ( set_tx ( "test" , "foo" , "bar" ) )
230
+ . await
231
+ . expect ( "decodeTx success" ) ;
232
+ log:: info!( "decode set response from {}: {:?}" , ep, resp) ;
233
+
234
+ log:: info!( "issue set tx request..." ) ;
235
+ let resp = scli
236
+ . issue_tx ( & resp. typed_data )
237
+ . await
238
+ . expect ( "issue_tx success" ) ;
239
+ log:: info!( "issue tx tx response from {}: {:?}" , ep, resp) ;
240
+
211
241
if crate :: get_network_runner_enable_shutdown ( ) {
212
242
log:: info!( "shutdown is enabled... stopping..." ) ;
213
243
let _resp = cli. stop ( ) . await . expect ( "failed stop" ) ;
0 commit comments