Summary

Your test.rs file should look similar to this:

#![allow(unused)]
fn main() {
use counter_app::*;
use essential_app_utils as utils;

#[tokio::test]
async fn test() {
    let path: std::path::PathBuf = concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/../contract/out/debug/counter.json"
    )
    .into();

    let counter =
        serde_json::from_reader(std::io::BufReader::new(std::fs::File::open(path).unwrap()))
            .unwrap();

    let dbs = utils::db::new_dbs().await;

    // Deploy the contract
    essential_app_utils::deploy::deploy_contract(&dbs.builder, &counter)
        .await
        .unwrap();

    let count = read_count(&dbs).await;
    assert_eq!(count, 0);

    increment(&dbs).await;

    let o = utils::builder::build_default(&dbs).await.unwrap();
    assert_eq!(o.succeeded.len(), 3);
    assert!(o.failed.is_empty());

    let count = read_count(&dbs).await;
    assert_eq!(count, 1);

    increment(&dbs).await;
    increment(&dbs).await;

    let o = utils::builder::build_default(&dbs).await.unwrap();
    assert_eq!(o.succeeded.len(), 2);

    let count = read_count(&dbs).await;
    assert_eq!(count, 2);
}

async fn read_count(dbs: &utils::db::Dbs) -> essential_types::Word {
    let r = utils::node::query_state_head(&dbs.node, &ADDRESS, &counter_key().0)
        .await
        .unwrap();
    extract_count(r).unwrap()
}

async fn increment(dbs: &utils::db::Dbs) {
    let current_count = extract_count(
        utils::node::query_state_head(&dbs.node, &ADDRESS, &counter_key().0)
            .await
            .unwrap(),
    )
    .unwrap();

    utils::builder::submit(&dbs.builder, create_solution(current_count + 1))
        .await
        .unwrap();
}
}