From 6d41daad87ec36f0cc4899d3f33cc1d28ca4322e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 25 Sep 2024 12:20:17 +0100 Subject: [PATCH] test/e2e: add a test for genesis manipulation --- .github/workflows/scripts/e2e.json | 3 +- crates/tests/src/e2e/ledger_tests.rs | 74 +++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/.github/workflows/scripts/e2e.json b/.github/workflows/scripts/e2e.json index 107820fdd5..5a4f302dbf 100644 --- a/.github/workflows/scripts/e2e.json +++ b/.github/workflows/scripts/e2e.json @@ -30,5 +30,6 @@ "e2e::wallet_tests::wallet_encrypted_key_cmds_env_var": 1, "e2e::wallet_tests::wallet_unencrypted_key_cmds": 1, "e2e::ledger_tests::masp_txs_and_queries": 82, - "e2e::ledger_tests::test_genesis_chain_id_change": 35 + "e2e::ledger_tests::test_genesis_chain_id_change": 35, + "e2e::ledger_tests::test_genesis_manipulation": 103 } \ No newline at end of file diff --git a/crates/tests/src/e2e/ledger_tests.rs b/crates/tests/src/e2e/ledger_tests.rs index 3d4b94318f..eed326daed 100644 --- a/crates/tests/src/e2e/ledger_tests.rs +++ b/crates/tests/src/e2e/ledger_tests.rs @@ -22,14 +22,16 @@ use color_eyre::eyre::Result; use color_eyre::owo_colors::OwoColorize; use namada_apps_lib::cli::context::ENV_VAR_CHAIN_ID; use namada_apps_lib::client::utils::PRE_GENESIS_DIR; +use namada_apps_lib::config::genesis::chain; +use namada_apps_lib::config::genesis::templates::TokenBalances; use namada_apps_lib::config::utils::convert_tm_addr_to_socket_addr; use namada_apps_lib::config::{self, ethereum_bridge}; use namada_apps_lib::tendermint_config::net::Address as TendermintAddress; -use namada_apps_lib::wallet; +use namada_apps_lib::wallet::{self, Alias}; use namada_core::chain::ChainId; use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use namada_sdk::address::Address; -use namada_sdk::chain::Epoch; +use namada_sdk::chain::{ChainIdPrefix, Epoch}; use namada_sdk::time::DateTimeUtc; use namada_sdk::token; use namada_test_utils::TestWasms; @@ -2734,3 +2736,71 @@ fn test_genesis_chain_id_change() -> Result<()> { Ok(()) } + +/// Test that any changes done to a genesis config after a chain is finalized +/// will make it fail validation. +#[test] +fn test_genesis_manipulation() -> Result<()> { + let test = setup::single_node_net().unwrap(); + + set_ethereum_bridge_mode( + &test, + &test.net.chain_id, + Who::Validator(0), + ethereum_bridge::ledger::Mode::Off, + None, + ); + + let chain_dir = test.get_chain_dir(Who::Validator(0)); + let genesis = chain::Finalized::read_toml_files(&chain_dir).unwrap(); + + let modified_genesis = [ + { + let mut genesis = genesis.clone(); + genesis + .balances + .token + .insert(Alias::from("test"), TokenBalances(Default::default())); + genesis + }, + { + let mut genesis = genesis.clone(); + genesis.balances.token.remove(&Alias::from("NAM")); + genesis + }, + { + let mut genesis = genesis.clone(); + genesis.metadata.address_gen = None; + genesis + }, + { + let mut genesis = genesis.clone(); + // Invalid chain ID + genesis.metadata.chain_id = ChainId("Invalid ID".to_string()); + genesis + }, + { + let mut genesis = genesis.clone(); + // Random valid chain ID + genesis.metadata.chain_id = ChainId::from_genesis( + ChainIdPrefix::from_str("TEST").unwrap(), + [1, 2, 3], + ); + genesis + }, + ]; + + for genesis in modified_genesis { + // Any modification should invalide the genesis + assert!(!genesis.is_valid()); + + genesis.write_toml_files(&chain_dir).unwrap(); + + // A node should fail to start-up + let result = + start_namada_ledger_node_wait_wasm(&test, Some(0), Some(40)); + assert!(result.is_err()) + } + + Ok(()) +}