-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
require sigs for some pos txs in validator VP
- Loading branch information
1 parent
e89a5a9
commit 5bed8aa
Showing
6 changed files
with
346 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3457,3 +3457,211 @@ fn change_validator_metadata() -> Result<()> { | |
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_invalid_validator_txs() -> Result<()> { | ||
let pipeline_len = 2; | ||
let unbonding_len = 4; | ||
let test = setup::network( | ||
|mut genesis, base_dir: &_| { | ||
genesis.parameters.pos_params.pipeline_len = pipeline_len; | ||
genesis.parameters.pos_params.unbonding_len = unbonding_len; | ||
// genesis.parameters.parameters.min_num_of_blocks = 6; | ||
// genesis.parameters.parameters.max_expected_time_per_block = 1; | ||
// genesis.parameters.parameters.epochs_per_year = 31_536_000; | ||
let mut genesis = setup::set_validators( | ||
2, | ||
genesis, | ||
base_dir, | ||
default_port_offset, | ||
); | ||
let bonds = genesis.transactions.bond.unwrap(); | ||
genesis.transactions.bond = Some( | ||
bonds | ||
.into_iter() | ||
.filter(|bond| { | ||
(&bond.data.validator).as_ref() != "validator-1" | ||
}) | ||
.collect(), | ||
); | ||
genesis | ||
}, | ||
None, | ||
)?; | ||
|
||
set_ethereum_bridge_mode( | ||
&test, | ||
&test.net.chain_id, | ||
&Who::Validator(0), | ||
ethereum_bridge::ledger::Mode::Off, | ||
None, | ||
); | ||
|
||
// 1. Run the ledger node | ||
let _bg_validator_0 = | ||
start_namada_ledger_node_wait_wasm(&test, Some(0), Some(40))? | ||
.background(); | ||
|
||
let _bg_validator_1 = | ||
start_namada_ledger_node_wait_wasm(&test, Some(1), Some(40))? | ||
.background(); | ||
|
||
let validator_0_rpc = get_actor_rpc(&test, &Who::Validator(0)); | ||
let validator_1_rpc = get_actor_rpc(&test, &Who::Validator(1)); | ||
|
||
// put money in the validator-1 account from its balance account so that it | ||
// can deactivate and reactivate | ||
let tx_args = vec![ | ||
"transfer", | ||
"--source", | ||
"validator-1-balance-key", | ||
"--target", | ||
"validator-1-validator-key", | ||
"--amount", | ||
"100.0", | ||
"--token", | ||
"NAM", | ||
"--node", | ||
&validator_1_rpc, | ||
]; | ||
let mut client = | ||
run_as!(test, Who::Validator(1), Bin::Client, tx_args, Some(40))?; | ||
client.exp_string("Transaction applied with result:")?; | ||
client.exp_string("Transaction is valid.")?; | ||
client.assert_success(); | ||
|
||
// put money in the validator-0 account from its balance account so that it | ||
// can deactivate and reactivate | ||
let tx_args = vec![ | ||
"transfer", | ||
"--source", | ||
"validator-0-balance-key", | ||
"--target", | ||
"validator-0-validator-key", | ||
"--amount", | ||
"100.0", | ||
"--token", | ||
"NAM", | ||
"--node", | ||
&validator_0_rpc, | ||
]; | ||
let mut client = | ||
run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?; | ||
client.exp_string("Transaction applied with result:")?; | ||
client.exp_string("Transaction is valid.")?; | ||
client.assert_success(); | ||
|
||
// Try to change validator-1 commission rate as validator-0 | ||
let tx_args = vec![ | ||
"change-commission-rate", | ||
"--validator", | ||
"validator-1", | ||
"--commission-rate", | ||
"0.06", | ||
"--signing-keys", | ||
"validator-0-validator-key", | ||
"--node", | ||
&validator_0_rpc, | ||
]; | ||
let mut client = | ||
run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?; | ||
client.exp_string("Transaction applied with result:")?; | ||
client.exp_string("Transaction is invalid.")?; | ||
client.assert_success(); | ||
|
||
// Try to deactivate validator-1 as validator-0 | ||
let tx_args = vec![ | ||
"deactivate-validator", | ||
"--validator", | ||
"validator-1", | ||
"--signing-keys", | ||
"validator-0-validator-key", | ||
"--node", | ||
&validator_0_rpc, | ||
]; | ||
let mut client = | ||
run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?; | ||
client.exp_string("Transaction applied with result:")?; | ||
client.exp_string("Transaction is invalid.")?; | ||
client.assert_success(); | ||
|
||
// Try to change the validator-1 website as validator-0 | ||
let tx_args = vec![ | ||
"change-metadata", | ||
"--validator", | ||
"validator-1", | ||
"--website", | ||
"[email protected]", | ||
"--signing-keys", | ||
"validator-0-validator-key", | ||
"--node", | ||
&validator_0_rpc, | ||
]; | ||
let mut client = | ||
run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?; | ||
client.exp_string("Transaction applied with result:")?; | ||
client.exp_string("Transaction is invalid.")?; | ||
client.assert_success(); | ||
|
||
// Deactivate validator-1 | ||
let tx_args = vec![ | ||
"deactivate-validator", | ||
"--validator", | ||
"validator-1", | ||
"--signing-keys", | ||
"validator-1-validator-key", | ||
"--node", | ||
&validator_1_rpc, | ||
]; | ||
let mut client = | ||
run_as!(test, Who::Validator(1), Bin::Client, tx_args, Some(40))?; | ||
client.exp_string("Transaction applied with result:")?; | ||
client.exp_string("Transaction is valid.")?; | ||
client.assert_success(); | ||
|
||
let deactivate_epoch = get_epoch(&test, &validator_1_rpc)?; | ||
let start = Instant::now(); | ||
let loop_timeout = Duration::new(120, 0); | ||
loop { | ||
if Instant::now().duration_since(start) > loop_timeout { | ||
panic!( | ||
"Timed out waiting for epoch: {}", | ||
deactivate_epoch + pipeline_len | ||
); | ||
} | ||
let epoch = epoch_sleep(&test, &validator_1_rpc, 40)?; | ||
if epoch >= deactivate_epoch + pipeline_len { | ||
break; | ||
} | ||
} | ||
|
||
// Check the state of validator-1 | ||
let tx_args = vec![ | ||
"validator-state", | ||
"--validator", | ||
"validator-1", | ||
"--node", | ||
&validator_1_rpc, | ||
]; | ||
let mut client = run!(test, Bin::Client, tx_args, Some(40))?; | ||
client.exp_regex(r"Validator [a-z0-9]+ is inactive")?; | ||
client.assert_success(); | ||
|
||
// Try to reactivate validator-1 as validator-0 | ||
let tx_args = vec![ | ||
"reactivate-validator", | ||
"--validator", | ||
"validator-1", | ||
"--signing-keys", | ||
"validator-0-validator-key", | ||
"--node", | ||
&validator_0_rpc, | ||
]; | ||
let mut client = | ||
run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?; | ||
client.exp_string("Transaction applied with result:")?; | ||
client.exp_string("Transaction is invalid.")?; | ||
client.assert_success(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.