rountrip test with instruction

This commit is contained in:
GroovieGermanikus 2023-06-25 21:53:19 +02:00
parent b812f81719
commit 47fd8b15d3
2 changed files with 33 additions and 12 deletions

View File

@ -37,3 +37,6 @@ async-trait = { workspace = true }
chrono = { workspace = true }
tokio = { version = "1.28.2", features = ["full", "fs"]}
rcgen = "0.9.3"
[dev-dependencies]
spl-memo = "3.0.1"

View File

@ -1,4 +1,5 @@
use std::net::SocketAddrV4;
use anyhow::Context;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::transaction::VersionedTransaction;
@ -27,13 +28,7 @@ impl TpuForwardingRequest {
}
}
// TODO reame
fn deserialize_request(raw_tx: &Vec<u8>) -> TpuForwardingRequest {
todo!();
}
fn serialize_transactions_for_tpu(
fn serialize_tpu_forwarding_request(
tpu_socket_addr: SocketAddrV4,
tpu_identity: Pubkey,
transactions: Vec<VersionedTransaction>) -> Vec<u8> {
@ -43,22 +38,45 @@ fn serialize_transactions_for_tpu(
bincode::serialize(&request).expect("Expect to serialize transactions")
}
// TODO reame
fn deserialize_tpu_forwarding_request(raw_proxy_request: &Vec<u8>) -> TpuForwardingRequest {
let request = bincode::deserialize::<TpuForwardingRequest>(&raw_proxy_request)
.context("deserialize proxy request")
.unwrap();
request
}
mod test {
use std::str::FromStr;
use log::info;
use solana_sdk::pubkey::Pubkey;
use crate::proxy_request_format::serialize_transactions_for_tpu;
use solana_sdk::transaction::Transaction;
use spl_memo::solana_program::message::VersionedMessage;
use crate::proxy_request_format::*;
#[test]
fn deser() {
let wire_data = serialize_transactions_for_tpu(
fn roundtrip() {
let payer_pubkey = Pubkey::new_unique();
let signer_pubkey = Pubkey::new_unique();
let memo_ix = spl_memo::build_memo("Hello world".as_bytes(), &[&signer_pubkey]);
let tx = Transaction::new_with_payer(&[memo_ix], Some(&payer_pubkey));
let wire_data = serialize_tpu_forwarding_request(
"127.0.0.1:5454".parse().unwrap(),
Pubkey::from_str("Bm8rtweCQ19ksNebrLY92H7x4bCaeDJSSmEeWqkdCeop").unwrap(),
vec![]);
vec![tx.into()]);
println!("wire_data: {:02X?}", wire_data);
let request = deserialize_tpu_forwarding_request(&wire_data);
let TpuForwardingRequest::V1(req1) = request;
assert_eq!(req1.transactions.len(), 1);
}
}