Remove socket from rpc test and move integration test
This commit is contained in:
parent
c7e5006bcf
commit
35764225ed
134
src/rpc.rs
134
src/rpc.rs
|
@ -20,8 +20,7 @@ use std::str::FromStr;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::thread::{self, sleep, Builder, JoinHandle};
|
use std::thread::{self, sleep, Builder, JoinHandle};
|
||||||
use std::time::Duration;
|
use std::time::{Duration, Instant};
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
pub const RPC_PORT: u16 = 8899;
|
pub const RPC_PORT: u16 = 8899;
|
||||||
|
|
||||||
|
@ -447,24 +446,13 @@ fn verify_signature(input: &str) -> Result<Signature> {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::bank::Bank;
|
use crate::bank::Bank;
|
||||||
use crate::cluster_info::{Node, NodeInfo};
|
use crate::cluster_info::NodeInfo;
|
||||||
use crate::db_ledger::create_tmp_ledger_with_mint;
|
|
||||||
use crate::fullnode::Fullnode;
|
|
||||||
use crate::jsonrpc_core::Response;
|
use crate::jsonrpc_core::Response;
|
||||||
use crate::leader_scheduler::LeaderScheduler;
|
|
||||||
use crate::mint::Mint;
|
use crate::mint::Mint;
|
||||||
use crate::rpc_request::get_rpc_request_str;
|
|
||||||
use crate::storage_stage::STORAGE_ROTATE_TEST_COUNT;
|
|
||||||
use crate::vote_signer_proxy::VoteSignerProxy;
|
|
||||||
use bincode::serialize;
|
|
||||||
use reqwest;
|
|
||||||
use reqwest::header::CONTENT_TYPE;
|
|
||||||
use solana_sdk::hash::{hash, Hash};
|
use solana_sdk::hash::{hash, Hash};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_vote_signer::rpc::LocalVoteSigner;
|
|
||||||
use std::fs::remove_dir_all;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
|
||||||
fn start_rpc_handler_with_tx(pubkey: Pubkey) -> (MetaIoHandler<Meta>, Meta, Hash, Keypair) {
|
fn start_rpc_handler_with_tx(pubkey: Pubkey) -> (MetaIoHandler<Meta>, Meta, Hash, Keypair) {
|
||||||
|
@ -513,23 +501,17 @@ mod tests {
|
||||||
let thread = rpc_service.thread_hdl.thread();
|
let thread = rpc_service.thread_hdl.thread();
|
||||||
assert_eq!(thread.name().unwrap(), "solana-jsonrpc");
|
assert_eq!(thread.name().unwrap(), "solana-jsonrpc");
|
||||||
|
|
||||||
let rpc_string = get_rpc_request_str(rpc_addr, false);
|
assert_eq!(
|
||||||
let client = reqwest::Client::new();
|
10_000,
|
||||||
let request = json!({
|
rpc_service
|
||||||
"jsonrpc": "2.0",
|
.request_processor
|
||||||
"id": 1,
|
.read()
|
||||||
"method": "getBalance",
|
.unwrap()
|
||||||
"params": [alice.pubkey().to_string()],
|
.get_balance(alice.pubkey())
|
||||||
});
|
.unwrap()
|
||||||
let mut response = client
|
);
|
||||||
.post(&rpc_string)
|
|
||||||
.header(CONTENT_TYPE, "application/json")
|
|
||||||
.body(request.to_string())
|
|
||||||
.send()
|
|
||||||
.unwrap();
|
|
||||||
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(10_000, json["result"].as_u64().unwrap());
|
rpc_service.close().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -714,98 +696,6 @@ mod tests {
|
||||||
assert_eq!(expected, result);
|
assert_eq!(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rpc_send_tx() {
|
|
||||||
let leader_keypair = Arc::new(Keypair::new());
|
|
||||||
let leader = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
|
||||||
|
|
||||||
let alice = Mint::new(10_000_000);
|
|
||||||
let mut bank = Bank::new(&alice);
|
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
|
||||||
let leader_data = leader.info.clone();
|
|
||||||
let ledger_path = create_tmp_ledger_with_mint("rpc_send_tx", &alice);
|
|
||||||
|
|
||||||
let last_id = bank.last_id();
|
|
||||||
let tx = Transaction::system_move(&alice.keypair(), bob_pubkey, 20, last_id, 0);
|
|
||||||
let serial_tx = serialize(&tx).unwrap();
|
|
||||||
|
|
||||||
let leader_scheduler = Arc::new(RwLock::new(LeaderScheduler::from_bootstrap_leader(
|
|
||||||
leader_data.id,
|
|
||||||
)));
|
|
||||||
bank.leader_scheduler = leader_scheduler;
|
|
||||||
|
|
||||||
let vote_account_keypair = Arc::new(Keypair::new());
|
|
||||||
let vote_signer =
|
|
||||||
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
|
|
||||||
let entry_height = alice.create_entries().len() as u64;
|
|
||||||
let server = Fullnode::new_with_bank(
|
|
||||||
leader_keypair,
|
|
||||||
Arc::new(vote_signer),
|
|
||||||
bank,
|
|
||||||
None,
|
|
||||||
entry_height,
|
|
||||||
&last_id,
|
|
||||||
leader,
|
|
||||||
None,
|
|
||||||
&ledger_path,
|
|
||||||
false,
|
|
||||||
None,
|
|
||||||
STORAGE_ROTATE_TEST_COUNT,
|
|
||||||
);
|
|
||||||
sleep(Duration::from_millis(900));
|
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let request = json!({
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": 1,
|
|
||||||
"method": "sendTransaction",
|
|
||||||
"params": json!([serial_tx])
|
|
||||||
});
|
|
||||||
let rpc_addr = leader_data.rpc;
|
|
||||||
let rpc_string = get_rpc_request_str(rpc_addr, false);
|
|
||||||
let mut response = client
|
|
||||||
.post(&rpc_string)
|
|
||||||
.header(CONTENT_TYPE, "application/json")
|
|
||||||
.body(request.to_string())
|
|
||||||
.send()
|
|
||||||
.unwrap();
|
|
||||||
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
|
||||||
let signature = &json["result"];
|
|
||||||
|
|
||||||
let mut confirmed_tx = false;
|
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
|
||||||
let request = json!({
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": 1,
|
|
||||||
"method": "confirmTransaction",
|
|
||||||
"params": [signature],
|
|
||||||
});
|
|
||||||
|
|
||||||
for _ in 0..5 {
|
|
||||||
let mut response = client
|
|
||||||
.post(&rpc_string)
|
|
||||||
.header(CONTENT_TYPE, "application/json")
|
|
||||||
.body(request.to_string())
|
|
||||||
.send()
|
|
||||||
.unwrap();
|
|
||||||
let response_json_text = response.text().unwrap();
|
|
||||||
let json: Value = serde_json::from_str(&response_json_text).unwrap();
|
|
||||||
|
|
||||||
if true == json["result"] {
|
|
||||||
confirmed_tx = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep(Duration::from_millis(250));
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(confirmed_tx);
|
|
||||||
|
|
||||||
server.close().unwrap();
|
|
||||||
remove_dir_all(ledger_path).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_send_bad_tx() {
|
fn test_rpc_send_bad_tx() {
|
||||||
let alice = Mint::new(10_000);
|
let alice = Mint::new(10_000);
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
use bincode::serialize;
|
||||||
|
use reqwest;
|
||||||
|
use reqwest::header::CONTENT_TYPE;
|
||||||
|
use serde_json::{json, Value};
|
||||||
|
use solana::bank::Bank;
|
||||||
|
use solana::cluster_info::Node;
|
||||||
|
use solana::db_ledger::create_tmp_ledger_with_mint;
|
||||||
|
use solana::fullnode::Fullnode;
|
||||||
|
use solana::leader_scheduler::LeaderScheduler;
|
||||||
|
use solana::mint::Mint;
|
||||||
|
use solana::rpc_request::get_rpc_request_str;
|
||||||
|
use solana::storage_stage::STORAGE_ROTATE_TEST_COUNT;
|
||||||
|
use solana::vote_signer_proxy::VoteSignerProxy;
|
||||||
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
|
use solana_sdk::transaction::Transaction;
|
||||||
|
use solana_vote_signer::rpc::LocalVoteSigner;
|
||||||
|
use std::fs::remove_dir_all;
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rpc_send_tx() {
|
||||||
|
let leader_keypair = Arc::new(Keypair::new());
|
||||||
|
let leader = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||||
|
|
||||||
|
let alice = Mint::new(10_000_000);
|
||||||
|
let mut bank = Bank::new(&alice);
|
||||||
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
|
let leader_data = leader.info.clone();
|
||||||
|
let ledger_path = create_tmp_ledger_with_mint("rpc_send_tx", &alice);
|
||||||
|
|
||||||
|
let last_id = bank.last_id();
|
||||||
|
let tx = Transaction::system_move(&alice.keypair(), bob_pubkey, 20, last_id, 0);
|
||||||
|
let serial_tx = serialize(&tx).unwrap();
|
||||||
|
|
||||||
|
let leader_scheduler = Arc::new(RwLock::new(LeaderScheduler::from_bootstrap_leader(
|
||||||
|
leader_data.id,
|
||||||
|
)));
|
||||||
|
bank.leader_scheduler = leader_scheduler;
|
||||||
|
|
||||||
|
let vote_account_keypair = Arc::new(Keypair::new());
|
||||||
|
let vote_signer =
|
||||||
|
VoteSignerProxy::new(&vote_account_keypair, Box::new(LocalVoteSigner::default()));
|
||||||
|
let entry_height = alice.create_entries().len() as u64;
|
||||||
|
let server = Fullnode::new_with_bank(
|
||||||
|
leader_keypair,
|
||||||
|
Arc::new(vote_signer),
|
||||||
|
bank,
|
||||||
|
None,
|
||||||
|
entry_height,
|
||||||
|
&last_id,
|
||||||
|
leader,
|
||||||
|
None,
|
||||||
|
&ledger_path,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
STORAGE_ROTATE_TEST_COUNT,
|
||||||
|
);
|
||||||
|
sleep(Duration::from_millis(900));
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let request = json!({
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"id": 1,
|
||||||
|
"method": "sendTransaction",
|
||||||
|
"params": json!([serial_tx])
|
||||||
|
});
|
||||||
|
let rpc_addr = leader_data.rpc;
|
||||||
|
let rpc_string = get_rpc_request_str(rpc_addr, false);
|
||||||
|
let mut response = client
|
||||||
|
.post(&rpc_string)
|
||||||
|
.header(CONTENT_TYPE, "application/json")
|
||||||
|
.body(request.to_string())
|
||||||
|
.send()
|
||||||
|
.unwrap();
|
||||||
|
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
||||||
|
let signature = &json["result"];
|
||||||
|
|
||||||
|
let mut confirmed_tx = false;
|
||||||
|
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let request = json!({
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"id": 1,
|
||||||
|
"method": "confirmTransaction",
|
||||||
|
"params": [signature],
|
||||||
|
});
|
||||||
|
|
||||||
|
for _ in 0..5 {
|
||||||
|
let mut response = client
|
||||||
|
.post(&rpc_string)
|
||||||
|
.header(CONTENT_TYPE, "application/json")
|
||||||
|
.body(request.to_string())
|
||||||
|
.send()
|
||||||
|
.unwrap();
|
||||||
|
let response_json_text = response.text().unwrap();
|
||||||
|
let json: Value = serde_json::from_str(&response_json_text).unwrap();
|
||||||
|
|
||||||
|
if true == json["result"] {
|
||||||
|
confirmed_tx = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(Duration::from_millis(250));
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(confirmed_tx, true);
|
||||||
|
|
||||||
|
server.close().unwrap();
|
||||||
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
}
|
Loading…
Reference in New Issue