-
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.
- Loading branch information
Showing
9 changed files
with
204 additions
and
84 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
.changelog/unreleased/bug-fixes/4036-validate-validator-metadata.md
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Validate validator metadata from on-chain validator creation and metadata | ||
changes. ([\#4036](https://github.com/anoma/namada/pull/4036)) |
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
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
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ use namada_sdk::account::AccountPublicKeysMap; | |
use namada_sdk::collections::HashMap; | ||
use namada_sdk::error::TxSubmitError; | ||
use namada_sdk::migrations; | ||
use namada_sdk::proof_of_stake::parameters::MAX_VALIDATOR_METADATA_LEN; | ||
use namada_sdk::queries::RPC; | ||
use namada_sdk::token::{self, DenominatedAmount}; | ||
use namada_sdk::tx::{self, Tx, TX_TRANSFER_WASM, VP_USER_WASM}; | ||
|
@@ -2565,6 +2566,95 @@ fn wrap_tx_by_elsewho() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
/// Test for PoS validator metadata validation. | ||
/// | ||
/// 1. Run the ledger node. | ||
/// 2. Submit a valid metadata change tx. | ||
/// 3. Check that the metadata has changed. | ||
/// 4. Submit an invalid metadata change tx. | ||
/// 5. Check that the metadata has not changed. | ||
/// 6. Submit a tx to become validator with invalid metadata. | ||
#[test] | ||
fn pos_validator_metadata_validation() -> Result<()> { | ||
// 1. Run the ledger node. | ||
let (node, _services) = setup::setup()?; | ||
|
||
// 2. Submit a valid metadata change tx. | ||
let valid_desc: String = "0123456789".repeat(50); | ||
assert_eq!(valid_desc.len() as u64, MAX_VALIDATOR_METADATA_LEN); | ||
let tx_args = apply_use_device(vec![ | ||
"change-metadata", | ||
"--validator", | ||
"validator-0-validator", | ||
"--description", | ||
&valid_desc, | ||
]); | ||
let captured = CapturedOutput::of(|| run(&node, Bin::Client, tx_args)); | ||
println!("{:?}", captured.result); | ||
assert_matches!(captured.result, Ok(_)); | ||
assert!(captured.contains(TX_APPLIED_SUCCESS)); | ||
|
||
// 3. Check that the metadata has changed. | ||
let query_args = apply_use_device(vec![ | ||
"validator-metadata", | ||
"--validator", | ||
"validator-0-validator", | ||
]); | ||
let captured = | ||
CapturedOutput::of(|| run(&node, Bin::Client, query_args.clone())); | ||
println!("{:?}", captured.result); | ||
assert!(captured.contains(&valid_desc)); | ||
|
||
// 4. Submit an invalid metadata change tx. | ||
let invalid_desc: String = format!("N{valid_desc}"); | ||
assert!(invalid_desc.len() as u64 > MAX_VALIDATOR_METADATA_LEN); | ||
let tx_args = apply_use_device(vec![ | ||
"change-metadata", | ||
"--validator", | ||
"validator-0-validator", | ||
"--description", | ||
&invalid_desc, | ||
"--force", | ||
]); | ||
let captured = CapturedOutput::of(|| run(&node, Bin::Client, tx_args)); | ||
println!("{:?}", captured.result); | ||
assert_matches!(captured.result, Ok(_)); | ||
assert!(captured.contains(TX_REJECTED)); | ||
|
||
// 5. Check that the metadata has not changed. | ||
let captured = CapturedOutput::of(|| run(&node, Bin::Client, query_args)); | ||
println!("{:?}", captured.result); | ||
assert!(captured.contains(&valid_desc)); | ||
|
||
// 6. Submit a tx to become validator with invalid metadata. | ||
let new_validator = "new-validator"; | ||
let tx_args = apply_use_device(vec![ | ||
"init-validator", | ||
"--alias", | ||
new_validator, | ||
"--name", | ||
new_validator, | ||
"--account-keys", | ||
"bertha-key", | ||
"--commission-rate", | ||
"0.05", | ||
"--max-commission-rate-change", | ||
"0.01", | ||
"--email", | ||
"[email protected]", | ||
"--signing-keys", | ||
"bertha-key", | ||
"--description", | ||
&invalid_desc, | ||
"--unsafe-dont-encrypt", | ||
]); | ||
let captured = CapturedOutput::of(|| run(&node, Bin::Client, tx_args)); | ||
assert_matches!(captured.result, Err(_)); | ||
assert!(captured.contains(TX_REJECTED)); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn make_migration_json() -> (Hash, tempfile::NamedTempFile) { | ||
let file = tempfile::Builder::new().tempfile().expect("Test failed"); | ||
let updates = [migrations::DbUpdateType::Add { | ||
|