lite-rpc/quic-forward-proxy/tests/proxy_request_format.rs

32 lines
1.1 KiB
Rust
Raw Normal View History

2023-07-31 05:26:21 -07:00
use solana_lite_rpc_quic_forward_proxy::proxy_request_format::TpuForwardingRequest;
2023-06-25 23:05:18 -07:00
use solana_sdk::pubkey::Pubkey;
2023-06-27 04:35:21 -07:00
use solana_sdk::signature::{Keypair, Signer};
2023-07-31 05:26:21 -07:00
use solana_sdk::transaction::Transaction;
use std::str::FromStr;
2023-06-25 23:05:18 -07:00
#[test]
fn roundtrip() {
2023-07-31 05:26:21 -07:00
let payer = Keypair::from_base58_string(
"rKiJ7H5UUp3JR18kNyTF1XPuwPKHEM7gMLWHZPWP5djrW1vSjfwjhvJrevxF9MPmUmN9gJMLHZdLMgc9ao78eKr",
);
2023-06-27 04:35:21 -07:00
let payer_pubkey = payer.pubkey();
2023-06-25 23:05:18 -07:00
2023-06-27 04:35:21 -07:00
let memo_ix = spl_memo::build_memo("Hello world".as_bytes(), &[&payer_pubkey]);
2023-06-25 23:05:18 -07:00
let tx = Transaction::new_with_payer(&[memo_ix], Some(&payer_pubkey));
2023-06-26 13:10:06 -07:00
let wire_data = TpuForwardingRequest::new(
2023-06-25 23:05:18 -07:00
"127.0.0.1:5454".parse().unwrap(),
Pubkey::from_str("Bm8rtweCQ19ksNebrLY92H7x4bCaeDJSSmEeWqkdCeop").unwrap(),
2023-07-31 05:26:21 -07:00
vec![tx.into()],
)
.serialize_wire_format();
2023-06-25 23:05:18 -07:00
println!("wire_data: {:02X?}", wire_data);
2023-06-26 13:10:06 -07:00
let request = TpuForwardingRequest::deserialize_from_raw_request(&wire_data);
2023-06-25 23:05:18 -07:00
2023-06-25 23:58:48 -07:00
assert_eq!(request.get_tpu_socket_addr().is_ipv4(), true);
assert_eq!(request.get_transactions().len(), 1);
}