Add leader-readiness test to wallet-sanity
This commit is contained in:
parent
1733beabf7
commit
9314eea7e9
|
@ -33,6 +33,25 @@ pay_and_confirm() {
|
|||
$solana_wallet "${entrypoint[@]}" confirm "$signature"
|
||||
}
|
||||
|
||||
leader_readiness=false
|
||||
timeout=60
|
||||
while [ $timeout -gt 0 ]
|
||||
do
|
||||
expected_output="Leader ready"
|
||||
exec 42>&1
|
||||
output=$($solana_wallet "${entrypoint[@]}" leader-ready | tee >(cat - >&42))
|
||||
if [[ "$output" =~ $expected_output ]]; then
|
||||
leader_readiness=true
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
(( timeout=timeout-2 ))
|
||||
done
|
||||
if [ "$leader_readiness" = false ]; then
|
||||
echo "Timed out waiting for leader"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$solana_keygen
|
||||
$solana_wallet "${entrypoint[@]}" address
|
||||
check_balance_output "No account found" "Your balance is: 0"
|
||||
|
|
|
@ -162,6 +162,9 @@ fn main() -> Result<(), Box<error::Error>> {
|
|||
.help("/path/to/program.o"),
|
||||
)
|
||||
// TODO: Add "loader" argument; current default is bpf_loader
|
||||
).subcommand(
|
||||
SubCommand::with_name("leader-ready")
|
||||
.about("Determine leader readiness")
|
||||
).subcommand(
|
||||
SubCommand::with_name("pay")
|
||||
.about("Send a payment")
|
||||
|
|
|
@ -42,6 +42,7 @@ pub enum WalletCommand {
|
|||
Cancel(Pubkey),
|
||||
Confirm(Signature),
|
||||
Deploy(String),
|
||||
GetLeaderReadiness,
|
||||
// Pay(tokens, to, timestamp, timestamp_pubkey, witness(es), cancelable)
|
||||
Pay(
|
||||
i64,
|
||||
|
@ -145,6 +146,7 @@ pub fn parse_command(
|
|||
.unwrap()
|
||||
.to_string(),
|
||||
)),
|
||||
("leader-ready", Some(_matches)) => Ok(WalletCommand::GetLeaderReadiness),
|
||||
("pay", Some(pay_matches)) => {
|
||||
let tokens = pay_matches.value_of("tokens").unwrap().parse()?;
|
||||
let to = if pay_matches.is_present("to") {
|
||||
|
@ -452,6 +454,20 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<error::Error
|
|||
"programId": format!("{}", program.pubkey()),
|
||||
}).to_string())
|
||||
}
|
||||
WalletCommand::GetLeaderReadiness => {
|
||||
// TODO: This logic is currently only correct for initial network boot;
|
||||
// needs updating for leader rotation
|
||||
let transaction_count = RpcRequest::GetTransactionCount
|
||||
.make_rpc_request(&config.rpc_addr, 1, None)?
|
||||
.as_u64();
|
||||
match transaction_count {
|
||||
Some(0) => Ok("Leader not ready".to_string()),
|
||||
Some(_) => Ok("Leader ready".to_string()),
|
||||
None => Err(WalletError::RpcRequestError(
|
||||
"Received result of an unexpected type".to_string(),
|
||||
))?,
|
||||
}
|
||||
}
|
||||
// If client has positive balance, pay tokens to another address
|
||||
WalletCommand::Pay(tokens, to, timestamp, timestamp_pubkey, ref witnesses, cancelable) => {
|
||||
let last_id = get_last_id(&config)?;
|
||||
|
|
Loading…
Reference in New Issue