Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethereum bridge VP and e2e test clean up #796

Merged
merged 7 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Clean up some code relating to the Ethereum bridge
([#796](https://github.com/anoma/namada/pull/796))
1 change: 0 additions & 1 deletion shared/src/ledger/eth_bridge/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! Bridge from Ethereum

pub mod storage;
pub mod vp;
12 changes: 0 additions & 12 deletions shared/src/ledger/eth_bridge/storage.rs

This file was deleted.

69 changes: 27 additions & 42 deletions tests/src/e2e/eth_bridge_tests.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -6,45 +8,41 @@ use crate::e2e::setup::constants::{
use crate::e2e::setup::{Bin, Who};
use crate::{run, run_as};

const ETH_BRIDGE_ADDRESS: &str = "atest1v9hx7w36g42ysgzzwf5kgem9ypqkgerjv4ehxgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpq8f99ew";

/// # Examples
///
/// ```
/// let storage_key = storage_key("queue");
/// assert_eq!(storage_key, "#atest1v9hx7w36g42ysgzzwf5kgem9ypqkgerjv4ehxgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpq8f99ew/queue");
/// ```
fn storage_key(path: &str) -> String {
format!("#{ETH_BRIDGE_ADDRESS}/{}", path)
format!("#{}/{}", eth_bridge::vp::ADDRESS, path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same as namada_core::ledger::eth_bridge::ADDRESS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so but namada_core::ledger::eth_bridge::ADDRESS isn't present in this PR. This PR is a rework of a small cleanup PR (#323) which never got merged

}

/// 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,
&["ledger"],
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);

Expand All @@ -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();
}