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/add osmosis test tube #150

Merged
merged 11 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ impl<Chain: CwEnv> Example<Chain> {
}
```

### Testing with OsmosisTestTube

OsmosisTestTube is available for testing in cw-orchestrator. In order to use it, you may need to install [clang] and [go] to compile the osmosis blockchain that serves as the backend for this env.
Kayanski marked this conversation as resolved.
Show resolved Hide resolved

## Contributing

We'd really appreciate your help! Please read our [contributing guidelines](docs/src/contributing.md) to get started.
Expand Down
2 changes: 1 addition & 1 deletion contracts/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ counter-contract = { path = ".", features = ["interface"] }
# Deps for deployment
dotenv = { version = "0.15.0" }
env_logger = { version = "0.10.0" }
cw-orch = { path = "../../cw-orch", features = ["daemon"] }
cw-orch = { path = "../../cw-orch", features = ["daemon", "test-tube"] }
90 changes: 90 additions & 0 deletions contracts/counter/tests/test-tube.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ANCHOR: all
use cosmwasm_std::coins;
use counter_contract::{
contract::CONTRACT_NAME,
msg::{GetCountResponse, InstantiateMsg, QueryMsg},
CounterContract,
};
use cw_orch::test_tube::OsmosisTestTube;
// Use prelude to get all the necessary imports
use cw_orch::prelude::*;

// ANCHOR: integration_test
// ANCHOR: setup
/// Instantiate the contract in any CosmWasm environment
fn setup<Chain: CwEnv>(chain: Chain) -> CounterContract<Chain> {
// ANCHOR: constructor
// Construct the counter interface
let contract = CounterContract::new(CONTRACT_NAME, chain.clone());
// ANCHOR_END: constructor

// Upload the contract
let upload_resp = contract.upload().unwrap();

// Get the code-id from the response.
let code_id = upload_resp.uploaded_code_id().unwrap();
// or get it from the interface.
assert_eq!(code_id, contract.code_id().unwrap());

// Instantiate the contract
let msg = InstantiateMsg { count: 1i32 };
let init_resp = contract
.instantiate(&msg, Some(&chain.sender()), None)
.unwrap();

// Get the address from the response
let contract_addr = init_resp.instantiated_contract_address().unwrap();
// or get it from the interface.
assert_eq!(contract_addr, contract.address().unwrap());

// Return the interface
contract
}
// ANCHOR_END: setup

// ANCHOR: count_test
#[test]
fn count() {
// Create the mock
let test_tube = OsmosisTestTube::new(coins(100_000_000_000, "uosmo"));

let account = test_tube
.init_account(coins(100_000_000_000, "uosmo"))
.unwrap();

// Set up the contract
let contract = setup(test_tube);

// Increment the count of the contract
contract
// Set the caller to user
.call_as(&account)
// Call the increment function (auto-generated function provided by CounterExecuteMsgFns)
.increment()
.unwrap();

// ANCHOR: query
// Get the count.
use counter_contract::CounterQueryMsgFns;
let count1 = contract.get_count().unwrap();
// ANCHOR_END: query

// or query it manually
let count2: GetCountResponse = contract.query(&QueryMsg::GetCount {}).unwrap();

assert_eq!(count1, count2);

// Check the count
assert_eq!(count1.count, 2);
// ANCHOR: reset
// Reset
use counter_contract::CounterExecuteMsgFns;
contract.reset(0).unwrap();

let count = contract.get_count().unwrap();
assert_eq!(count.count, 0);
// ANCHOR_END: reset
}
// ANCHOR_END: count_test
// ANCHOR_END: integration_test
// ANCHOR_END: all
4 changes: 4 additions & 0 deletions cw-orch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ daemon = [
"dep:prost",
]
eth = ["daemon", "dep:ethers-signers", "dep:ethers-core", "dep:snailquote"]
test-tube = ["dep:osmosis-test-tube"]

[dependencies]
# Default deps
Expand Down Expand Up @@ -103,6 +104,9 @@ ethers-signers = { version = "2.0.7", optional = true }
ethers-core = { version = "2.0.7", optional = true }
snailquote = { version = "0.3.1", optional = true }

# Test Tube env deps
osmosis-test-tube = { version = "15.1.0", optional = true }

[dev-dependencies]
cw-orch = { features = ["daemon"], path = "." }
uid = "0.1.7"
Expand Down
3 changes: 3 additions & 0 deletions cw-orch/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub enum CwOrchError {
#[cfg(feature = "daemon")]
#[error(transparent)]
DaemonError(#[from] DaemonError),
#[cfg(feature = "test-tube")]
#[error(transparent)]
TestTubeError(#[from] osmosis_test_tube::RunnerError),
#[error("JSON Conversion Error")]
SerdeJson(#[from] ::serde_json::Error),
#[error(transparent)]
Expand Down
1 change: 1 addition & 0 deletions cw-orch/src/keys/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ mod tst {
Ok(())
}

#[cfg(feature = "eth")]
#[test]
pub fn inj() -> anyhow::Result<()> {
let str_1: &str = "across left ignore gold echo argue track joy hire release captain enforce hotel wide flash hotel brisk joke midnight duck spare drop chronic stool";
Expand Down
2 changes: 2 additions & 0 deletions cw-orch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ mod interface_traits;
mod keys;
pub mod mock;
mod paths;
#[cfg(feature = "test-tube")]
pub mod test_tube;

pub mod state;

Expand Down
Loading