diff --git a/modules/tests/model_based.rs b/modules/tests/model_based.rs index 157fcac211..3d2d7852ed 100644 --- a/modules/tests/model_based.rs +++ b/modules/tests/model_based.rs @@ -1,5 +1,5 @@ mod modelator; -mod state; +mod step; use ibc::ics02_client::client_def::AnyHeader; use ibc::ics02_client::client_def::{AnyClientState, AnyConsensusState}; @@ -24,10 +24,10 @@ use ibc::mock::context::MockContext; use ibc::mock::header::MockHeader; use ibc::mock::host::HostType; use ibc::Height; -use state::{ActionOutcome, ActionType, State}; use std::collections::HashMap; use std::error::Error; use std::fmt::{Debug, Display}; +use step::{ActionOutcome, ActionType, Step}; use tendermint::account::Id as AccountId; #[derive(Debug)] @@ -133,31 +133,31 @@ impl ICS02TestExecutor { } } -impl modelator::TestExecutor for ICS02TestExecutor { - fn check_initial_state(&mut self, state: State) -> bool { +impl modelator::TestExecutor for ICS02TestExecutor { + fn initial_step(&mut self, step: Step) -> bool { assert_eq!( - state.action.action_type, + step.action.action_type, ActionType::Null, "unexpected action type" ); assert_eq!( - state.action_outcome, + step.action_outcome, ActionOutcome::Null, "unexpected action outcome" ); true } - fn check_next_state(&mut self, state: State) -> bool { - match state.action.action_type { + fn next_step(&mut self, step: Step) -> bool { + match step.action.action_type { ActionType::Null => panic!("unexpected action type"), ActionType::ICS02CreateClient => { // get action parameters - let chain_id = state + let chain_id = step .action .chain_id .expect("create client action should have a chain identifier"); - let height = state + let height = step .action .height .expect("create client action should have a height"); @@ -174,7 +174,7 @@ impl modelator::TestExecutor for ICS02TestExecutor { let result = ctx.deliver(msg); // check the expected outcome: client create always succeeds - match state.action_outcome { + match step.action_outcome { ActionOutcome::ICS02CreateOK => { // the implementaion matches the model if no error occurs result.is_ok() @@ -184,15 +184,15 @@ impl modelator::TestExecutor for ICS02TestExecutor { } ActionType::ICS02UpdateClient => { // get action parameters - let chain_id = state + let chain_id = step .action .chain_id .expect("update client action should have a chain identifier"); - let client_id = state + let client_id = step .action .client_id .expect("update client action should have a client identifier"); - let height = state + let height = step .action .height .expect("update client action should have a height"); @@ -209,7 +209,7 @@ impl modelator::TestExecutor for ICS02TestExecutor { let result = ctx.deliver(msg); // check the expected outcome - match state.action_outcome { + match step.action_outcome { ActionOutcome::ICS02UpdateOK => { // the implementaion matches the model if no error occurs result.is_ok() @@ -236,15 +236,15 @@ impl modelator::TestExecutor for ICS02TestExecutor { } ActionType::ICS03ConnectionOpenInit => { // get action parameters - let chain_id = state + let chain_id = step .action .chain_id .expect("connection open init action should have a chain identifier"); - let client_id = state + let client_id = step .action .client_id .expect("connection open init action should have a client identifier"); - let counterparty_client_id = state.action.counterparty_client_id.expect( + let counterparty_client_id = step.action.counterparty_client_id.expect( "connection open init action should have a counterparty client identifier", ); @@ -264,7 +264,7 @@ impl modelator::TestExecutor for ICS02TestExecutor { let result = ctx.deliver(msg); // check the expected outcome - match state.action_outcome { + match step.action_outcome { ActionOutcome::ICS03ConnectionOpenInitOK => { // the implementaion matches the model if no error occurs result.is_ok() diff --git a/modules/tests/modelator.rs b/modules/tests/modelator.rs index d395119e20..91d60d6800 100644 --- a/modules/tests/modelator.rs +++ b/modules/tests/modelator.rs @@ -6,15 +6,14 @@ use std::io::BufReader; use std::path::Path; pub trait TestExecutor { - fn check_initial_state(&mut self, state: S) -> bool; - - fn check_next_state(&mut self, state: S) -> bool; + fn initial_step(&mut self, step: S) -> bool; + fn next_step(&mut self, step: S) -> bool; } -pub fn test_driver(mut executor: E, path: P) -> Result<()> +pub fn test_driver(mut executor: Executor, path: P) -> Result<()> where - E: TestExecutor + Debug, - S: DeserializeOwned + Debug + Clone, + Executor: TestExecutor + Debug, + Step: DeserializeOwned + Debug + Clone, P: AsRef, { // open test file @@ -23,27 +22,27 @@ where let reader = BufReader::new(file); // parse test file - let states: Vec = serde_json::de::from_reader(reader) + let steps: Vec = serde_json::de::from_reader(reader) .wrap_err_with(|| format!("test file {:?} could not be deserialized", path.as_ref()))?; - let mut states = states.into_iter(); + let mut steps = steps.into_iter(); - // check the initial state - if let Some(state) = states.next() { - if !executor.check_initial_state(state.clone()) { - return Err(eyre!("check failed on initial state:\n{:#?}", state)); + // check the initial step + if let Some(step) = steps.next() { + if !executor.initial_step(step.clone()) { + return Err(eyre!("check failed on initial step:\n{:#?}", step)); } } else { - println!("WARNING: test file {:?} had 0 states", path.as_ref()); + println!("WARNING: test file {:?} had 0 steps", path.as_ref()); return Ok(()); } - // check all the remaining states - for state in states { - if !executor.check_next_state(state.clone()) { + // check the remaining steps + for step in steps { + if !executor.next_step(step.clone()) { return Err(eyre!( - "check failed on state:\n{:#?}\n\nexecutor:\n{:#?}", - state, + "check failed on step:\n{:#?}\n\nexecutor:\n{:#?}", + step, executor )); } diff --git a/modules/tests/state.rs b/modules/tests/step.rs similarity index 98% rename from modules/tests/state.rs rename to modules/tests/step.rs index fdbd0820dc..a84e67bb33 100644 --- a/modules/tests/state.rs +++ b/modules/tests/step.rs @@ -2,7 +2,7 @@ use serde::Deserialize; use std::fmt::Debug; #[derive(Debug, Clone, Deserialize)] -pub struct State { +pub struct Step { pub action: Action, #[serde(alias = "actionOutcome")]