Skip to content

Commit

Permalink
Add ethbridge e2e test
Browse files Browse the repository at this point in the history
eth_bridge_tests changes

eth_bridge_tests changes

eth_bridge_tests changes

eth_bridge_tests changes
  • Loading branch information
james-chf committed May 12, 2022
1 parent e628cd3 commit c417cf9
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//! To keep the temporary files created by a test, use env var
//! `ANOMA_E2E_KEEP_TEMP=true`.
pub mod eth_bridge_tests;
pub mod gossip_tests;
pub mod helpers;
pub mod ledger_tests;
Expand Down
93 changes: 93 additions & 0 deletions tests/src/e2e/eth_bridge_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use crate::e2e::helpers::get_actor_rpc;
use crate::e2e::setup;
use crate::e2e::setup::constants::{
wasm_abs_path, ALBERT, TX_WRITE_STORAGE_KEY_WASM,
};
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)
}

#[test]
fn everything() {
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 anoman_ledger = run_as!(
test,
SOLE_VALIDATOR,
Bin::Node,
&["ledger"],
Some(LEDGER_STARTUP_TIMEOUT_SECONDS)
)
.unwrap();
anoman_ledger
.exp_string("Anoma ledger node started")
.unwrap();
anoman_ledger.exp_string("Tendermint node started").unwrap();
anoman_ledger.exp_string("Committed block hash").unwrap();

let tx_data_path = test.base_dir.path().join("queue_storage_key.txt");
std::fs::write(&tx_data_path, &storage_key("queue")[..]).unwrap();

let tx_code_path = wasm_abs_path(TX_WRITE_STORAGE_KEY_WASM);

let tx_data_path = tx_data_path.to_string_lossy().to_string();
let tx_code_path = tx_code_path.to_string_lossy().to_string();
let ledger_addr = get_actor_rpc(&test, &SOLE_VALIDATOR);
let tx_args = vec![
"tx",
"--signer",
ALBERT,
"--code-path",
&tx_code_path,
"--data-path",
&tx_data_path,
"--ledger-address",
&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 anomac_tx = run!(
test,
Bin::Client,
tx_args,
Some(CLIENT_COMMAND_TIMEOUT_SECONDS)
)
.unwrap();

if !dry_run {
if !cfg!(feature = "ABCI") {
anomac_tx.exp_string("Transaction accepted").unwrap();
}
anomac_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 anomac
// stdout.
anomac_tx.exp_string("Transaction is invalid").unwrap();
anomac_tx
.exp_string(&format!("Rejected: {}", ETH_BRIDGE_ADDRESS))
.unwrap();
anomac_tx.assert_success();
}
}
2 changes: 2 additions & 0 deletions tests/src/e2e/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ pub mod constants {
pub const VP_USER_WASM: &str = "wasm/vp_user.wasm";
pub const TX_NO_OP_WASM: &str = "wasm_for_tests/tx_no_op.wasm";
pub const TX_INIT_PROPOSAL: &str = "wasm_for_tests/tx_init_proposal.wasm";
pub const TX_WRITE_STORAGE_KEY_WASM: &str =
"wasm_for_tests/tx_write_storage_key.wasm";
pub const VP_ALWAYS_TRUE_WASM: &str = "wasm_for_tests/vp_always_true.wasm";
pub const VP_ALWAYS_FALSE_WASM: &str =
"wasm_for_tests/vp_always_false.wasm";
Expand Down

0 comments on commit c417cf9

Please sign in to comment.