message: use ContextAction::Checkout message for context hash validation in integration test
diff: @@ -137,7 +137,9 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
  let commit_log_db_path = PathBuf::from("/tmp/commit_log/");
  let key_value_db_path = PathBuf::from("/tmp/key_value_store/");
  - let input_file = env::var("INPUT").expect("test input not set");
  + let input_file = env::var("INPUT").expect("test input 'INPUT' not set");
  + let backend = env::var("BACKEND").expect("test backend 'BACKEND' not set");
  +
  let actions_storage_path = PathBuf::from(input_file.as_str());
  let _ = fs::remove_dir_all(&commit_log_db_path);
  @@ -151,7 +153,13 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
  kv.clone(),
  kv,
  commit_log,
  - storage::KeyValueStoreBackend::RocksDB, // TODO: test others too?
  + match backend.as_str() {
  + "inmem" => storage::KeyValueStoreBackend::InMem,
  + "sled" => storage::KeyValueStoreBackend::Sled,
  + "btree" => storage::KeyValueStoreBackend::BTreeMap,
  + "rocksdb" => storage::KeyValueStoreBackend::RocksDB,
  + _ => panic!("unknown backend"),
  + },
  );
  let mut context: Box<dyn ContextApi> = Box::new(TezedgeContext::new(
  BlockStorage::new(&storage),
  @@ -177,7 +185,7 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
  counter += 1;
  let progress = counter as f64 / blocks_count as f64 * 100.0;
  - match messages.iter().last() {
  + match messages.last() {
  Some(action) => match action {
  ContextAction::Commit {
  block_hash: Some(block_hash),
  @@ -200,6 +208,7 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
  }
  };
  + let mut context_hash_verified = false;
  for action in messages.iter() {
  if let ContextAction::Commit {
  block_hash: Some(block_hash),
  @@ -214,6 +223,17 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
  block_storage.put_block_header(&b).unwrap();
  }
  + // in the begining of the each block there is Checkout message
  + // lets use that and check if current context hash is equal to
  + // one current context hash even before applying the action
  + if let ContextAction::Checkout { context_hash, .. } = action {
  + assert_eq!(
  + context_hash.as_slice(),
  + context.get_last_commit_hash().unwrap().as_slice()
  + );
  + context_hash_verified = true;
  + }
  +
  match action {
  // actions that does not mutate staging area can be ommited here
  ContextAction::Set { .. }
  @@ -234,17 +254,15 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
  };
  // verify context hashes after each block
  - if let ContextAction::Checkout { context_hash, .. } = action {
  - assert_eq!(
  - context_hash.as_slice(),
  - context.get_last_commit_hash().unwrap().as_slice()
  - );
  - }
  if let Some(expected_hash) = get_new_tree_hash(&action) {
  assert_eq!(context.get_merkle_root(), expected_hash);
  }
  }
  + // ignore genesis_block
  + if counter > 1 {
  + assert!(context_hash_verified);
  + }
  }
  println!("{:#?}", storage.merkle().read().unwrap().get_merkle_stats());
  Ok(())
  