diff --git a/.changelog/unreleased/miscellaneous/796-ethbridge-e2e-cleanup.md b/.changelog/unreleased/miscellaneous/796-ethbridge-e2e-cleanup.md new file mode 100644 index 0000000000..738678102c --- /dev/null +++ b/.changelog/unreleased/miscellaneous/796-ethbridge-e2e-cleanup.md @@ -0,0 +1,2 @@ +- Clean up some code relating to the Ethereum bridge + ([#796](https://github.com/anoma/namada/pull/796)) \ No newline at end of file diff --git a/shared/src/ledger/eth_bridge/mod.rs b/shared/src/ledger/eth_bridge/mod.rs index ff8505b08e..817623e54c 100644 --- a/shared/src/ledger/eth_bridge/mod.rs +++ b/shared/src/ledger/eth_bridge/mod.rs @@ -1,4 +1,3 @@ //! Bridge from Ethereum -pub mod storage; pub mod vp; diff --git a/shared/src/ledger/eth_bridge/storage.rs b/shared/src/ledger/eth_bridge/storage.rs deleted file mode 100644 index e67abf921c..0000000000 --- a/shared/src/ledger/eth_bridge/storage.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! storage helpers -use super::vp::ADDRESS; -use crate::types::storage::{Key, KeySeg}; - -const QUEUE_STORAGE_KEY: &str = "queue"; - -/// Get the key corresponding to @EthBridge/queue -pub fn queue_key() -> Key { - Key::from(ADDRESS.to_db_key()) - .push(&QUEUE_STORAGE_KEY.to_owned()) - .expect("Cannot obtain a storage key") -} diff --git a/tests/src/e2e/eth_bridge_tests.rs b/tests/src/e2e/eth_bridge_tests.rs index 7cc1bd6aee..54647eacbc 100644 --- a/tests/src/e2e/eth_bridge_tests.rs +++ b/tests/src/e2e/eth_bridge_tests.rs @@ -1,3 +1,5 @@ +use namada::ledger::eth_bridge; + use crate::e2e::helpers::get_actor_rpc; use crate::e2e::setup; use crate::e2e::setup::constants::{ @@ -6,8 +8,6 @@ use crate::e2e::setup::constants::{ use crate::e2e::setup::{Bin, Who}; use crate::{run, run_as}; -const ETH_BRIDGE_ADDRESS: &str = "atest1v9hx7w36g42ysgzzwf5kgem9ypqkgerjv4ehxgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpq8f99ew"; - /// # Examples /// /// ``` @@ -15,18 +15,20 @@ const ETH_BRIDGE_ADDRESS: &str = "atest1v9hx7w36g42ysgzzwf5kgem9ypqkgerjv4ehxgpq /// assert_eq!(storage_key, "#atest1v9hx7w36g42ysgzzwf5kgem9ypqkgerjv4ehxgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpq8f99ew/queue"); /// ``` fn storage_key(path: &str) -> String { - format!("#{ETH_BRIDGE_ADDRESS}/{}", path) + format!("#{}/{}", eth_bridge::vp::ADDRESS, path) } +/// Test that a regular transaction cannot modify arbitrary keys of the Ethereum +/// bridge VP. #[test] -fn everything() { +fn test_unauthorized_tx_cannot_write_storage() { const LEDGER_STARTUP_TIMEOUT_SECONDS: u64 = 30; const CLIENT_COMMAND_TIMEOUT_SECONDS: u64 = 30; const SOLE_VALIDATOR: Who = Who::Validator(0); let test = setup::single_node_net().unwrap(); - let mut namadan_ledger = run_as!( + let mut ledger = run_as!( test, SOLE_VALIDATOR, Bin::Node, @@ -34,17 +36,13 @@ fn everything() { Some(LEDGER_STARTUP_TIMEOUT_SECONDS) ) .unwrap(); - namadan_ledger - .exp_string("Namada ledger node started") - .unwrap(); - namadan_ledger - .exp_string("Tendermint node started") - .unwrap(); - namadan_ledger.exp_string("Committed block hash").unwrap(); - let _bg_ledger = namadan_ledger.background(); + ledger.exp_string("Namada ledger node started").unwrap(); + ledger.exp_string("Tendermint node started").unwrap(); + ledger.exp_string("Committed block hash").unwrap(); + let _bg_ledger = ledger.background(); - let tx_data_path = test.test_dir.path().join("queue_storage_key.txt"); - std::fs::write(&tx_data_path, &storage_key("queue")[..]).unwrap(); + let tx_data_path = test.test_dir.path().join("arbitrary_storage_key.txt"); + std::fs::write(&tx_data_path, &storage_key("arbitrary")[..]).unwrap(); let tx_code_path = wasm_abs_path(TX_WRITE_STORAGE_KEY_WASM); @@ -63,32 +61,19 @@ fn everything() { &ledger_addr, ]; - for &dry_run in &[true, false] { - let tx_args = if dry_run { - vec![tx_args.clone(), vec!["--dry-run"]].concat() - } else { - tx_args.clone() - }; - let mut namadac_tx = run!( - test, - Bin::Client, - tx_args, - Some(CLIENT_COMMAND_TIMEOUT_SECONDS) - ) - .unwrap(); + let mut client_tx = run!( + test, + Bin::Client, + tx_args, + Some(CLIENT_COMMAND_TIMEOUT_SECONDS) + ) + .unwrap(); - if !dry_run { - namadac_tx.exp_string("Transaction accepted").unwrap(); - namadac_tx.exp_string("Transaction applied").unwrap(); - } - // TODO: we should check here explicitly with the ledger via a - // Tendermint RPC call that the path `value/#EthBridge/queue` - // is unchanged rather than relying solely on looking at namadac - // stdout. - namadac_tx.exp_string("Transaction is invalid").unwrap(); - namadac_tx - .exp_string(&format!("Rejected: {}", ETH_BRIDGE_ADDRESS)) - .unwrap(); - namadac_tx.assert_success(); - } + client_tx.exp_string("Transaction accepted").unwrap(); + client_tx.exp_string("Transaction applied").unwrap(); + client_tx.exp_string("Transaction is invalid").unwrap(); + client_tx + .exp_string(&format!("Rejected: {}", eth_bridge::vp::ADDRESS)) + .unwrap(); + client_tx.assert_success(); }