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

40 lines
1.3 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));
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()],
)
2023-08-08 06:41:29 -07:00
.try_serialize_wire_format()
.unwrap();
2023-06-25 23:05:18 -07:00
println!("wire_data: {:02X?}", wire_data);
2023-08-08 06:41:29 -07:00
let request = TpuForwardingRequest::try_deserialize_from_wire_format(&wire_data).unwrap();
2023-06-25 23:05:18 -07:00
2023-08-02 05:55:11 -07:00
assert!(request.get_tpu_socket_addr().is_ipv4());
2023-06-25 23:58:48 -07:00
assert_eq!(request.get_transactions().len(), 1);
}
2023-08-08 06:41:29 -07:00
#[test]
fn deserialize_error() {
let value: &[u8] = &[1, 2, 3, 4];
let result = TpuForwardingRequest::try_deserialize_from_wire_format(value);
assert_eq!(result.unwrap_err().to_string(), "deserialize proxy request");
}