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

update comment in aptos_containers #9

Merged
merged 11 commits into from
Sep 10, 2024
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
- name: Upload to codecov.io
uses: codecov/codecov-action@v4
with:
target: 80
threshold: 5
token: ${{secrets.CODECOV_TOKEN}} # not required for public repos
verbose: true
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
[package]
description = "Test container for Apotos Node"
edition = "2021"
license = "MIT"
name = "aptos-testcontainer"
version = "0.1.0"
repository = "https://github.com/sota-zk-labs/aptos-testcontainer.git"
version = "0.0.5"

[dependencies]
anyhow = { version = "1.0.71" }
base64 = "0.22.1"
config = { version = "0.14.0" }
ed25519-dalek = { version = "2.1.1" }
hex = "0.4.3"
log = "0.4.22"
rand = "0.8.5"
regex = "1.10.6"
serde = { version = "1.0" }
testcontainers = { version = "0.21.1" }
thiserror = { version = "1.0.63" }
tiny-keccak = { version = "2.0.2", features = ["sha3"] }
tokio = { version = "1.40.0", features = ["rt", "rt-multi-thread", "macros"] }
walkdir = "2.3.3"

[dev-dependencies]
ed25519-dalek = { version = "2.1.1" }
hex = "0.4.3"
test-log = { version = "0.2.16" }
tiny-keccak = { version = "2.0.2", features = ["sha3"] }

[features]
testing = []
119 changes: 116 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,124 @@

## Introduction

Test container for Aptos Node
This module provides a simple and smart test container framework for testing interactions with an Aptos node.

## Install
## Usage
Here’s how to use the `aptos-testcontainer` in your tests:
zk-steve marked this conversation as resolved.
Show resolved Hide resolved

### 1. Initialize the Container

To start an Aptos node in a container and run tests on it, you can use the `lazy_aptos_container` function.

```rust
use aptos_testcontainer::test_utils::aptos_container_test_utils::lazy_aptos_container;

#[tokio::main]
async fn main() {
let aptos_container = lazy_aptos_container.await?;
}
```

### 2. Run Tests with Aptos Accounts

Use the `run` function to run tests with initialized `accounts`.

And use the `get_account_address` function to convert a given private key to its corresponding account address.
```rust
use aptos_testcontainer::test_utils::aptos_container_test_utils::{lazy_aptos_container, run};
use aptos_testcontainer::utils::get_account_address;

#[tokio::main]
async fn main() {
run(2, |accounts| {
Box::pin(async move {
let aptos_container = lazy_aptos_container().await?;
let module_account_private_key = accounts.first().unwrap();
let module_account_address = get_account_address(module_account_private_key);
Ok(())
})
})
.await
.unwrap();
}
```

### 3. Upload Contracts and Run Scripts

#### Using to `upload_contract`
```rust
use aptos_testcontainer::test_utils::aptos_container_test_utils::{lazy_aptos_container, run};
use aptos_testcontainer::utils::get_account_address;

#[tokio::main]
async fn main() {
run(2, |accounts| {
Box::pin(async move {
let aptos_container = lazy_aptos_container().await?;
let module_account_private_key = accounts.first().unwrap();
let module_account_address = get_account_address(module_account_private_key);

// The local directory containing the contract files.
let local_dir = "./contract-samples/sample1";

let mut named_addresses = HashMap::new();
named_addresses.insert("verifier_addr".to_string(), module_account_address);
aptos_container
.upload_contract(
local_dir,
module_account_private_key,
&named_addresses,
None,
false,
)
.await
.unwrap();
Ok(())
})
})
.await
.unwrap();
}
```

#### Using to `run_scripts`
```rust
use aptos_testcontainer::test_utils::aptos_container_test_utils::{lazy_aptos_container, run};
use aptos_testcontainer::utils::get_account_address;

#[tokio::main]
async fn main() {
run(2, |accounts| {
Box::pin(async move {
let aptos_container = lazy_aptos_container().await?;
let module_account_private_key = accounts.first().unwrap();
let module_account_address = get_account_address(module_account_private_key);

// The directory path containing contract code.
let local_dir = "./contract-samples/sample2";

let mut named_addresses = HashMap::new();
named_addresses.insert("verifier_addr".to_string(), module_account_address.clone());
named_addresses.insert("lib_addr".to_string(), module_account_address);
aptos_container
.run_script(
local_dir,
module_account_private_key,
&named_addresses,
&vec!["verifier"],
)
.await
.unwrap();
let node_url = aptos_container.get_node_url();
info!("node_url = {:#?}", node_url);
Ok(())
})
})
.await
.unwrap();
}
```

## How To Use

### Environment Variables

Expand Down
Loading
Loading