Skip to content

Commit e29fb20

Browse files
authored
Improve test-tube test configuration (#718)
* Introduce explicit test-targets with `required-features = [ "test-tube" ]`, to enable cargo picking up the dep * Introduce dummy test-tube feature in workspace quasar as a workaround to allow setting "test-tube" for rust-analyzer
1 parent 4ea83ea commit e29fb20

File tree

22 files changed

+86
-49
lines changed

22 files changed

+86
-49
lines changed

README.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,34 @@ In order to run test-tube the following dependencies are required:
6464
* go1.21 ([see here](https://go.dev/doc/install))
6565
* libwasmvm ([see here](https://github.com/CosmWasm/wasmvm) -- !Instructions don't cover installation, copy the files to your desired install location or add the subfolder `wasmvm/internal/api` to your library paths)
6666

67-
## Pre-commit hook
67+
## Git hooks
68+
To automatically use both the pre-commit hook and the post-merge hook, you can adjust the hook path of git: `git config core.hooksPath ${PWD}/scripts/git`.
69+
70+
#### Pre-commit hook
6871
Enable the pre-commit hook by copying the entrypoint to the hooks folder: `cp scripts/pre-commit .git/hooks`.
6972

7073
It forwards to `scripts/git/pre-commit`, which contains the actual implementation.
71-
If you are concerned about automatically picking up changes in a bash script from the repository you may install the pre-commit hook via: `cp scripts/git/pre-commit .git/hooks`
74+
If you are concerned about automatically picking up changes in a bash script from the repository you may install the pre-commit hook via: `cp scripts/git/pre-commit .git/hooks`
75+
76+
#### Post-merge hook
77+
The post-merge hook automatically removes branches that have been removed on the remote.
78+
WARNING: Only use this if you are disciplined with your usage of git.
79+
80+
## IDE Configuration
81+
Rust-analyzer does not pick up optional dependencies (even when specified as required-dependencies for a target). Moreover, it can get confused it it finds too many workspaces.
82+
83+
#### vscode
84+
The following template enables rust-analyzer for test-tube tests and adds the workspace paths.
85+
86+
Template for `./.vscode/settings.json`:
87+
```
88+
{
89+
"rust-analyzer.linkedProjects": [
90+
"<REPO_ROOT>/smart-contracts/osmosis/Cargo.toml",
91+
"<REPO_ROOT>/smart-contracts/quasar/Cargo.toml",
92+
],
93+
"rust-analyzer.cargo.features": [
94+
"test-tube"
95+
]
96+
}
97+
```

smart-contracts/osmosis/contracts/cl-vault/.cargo/config

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[alias]
2+
wasm = "build --release --lib --target wasm32-unknown-unknown"
3+
unit-test = "test --lib"
4+
schema = "run --bin schema"
5+
# test-tube = "test --test * --features test-tube -- --test-threads=1"
6+
test-tube = "test --test test-tube --features test-tube -- --test-threads=1"
7+
prop-test = "test --test prop-test --features test-tube -- --test-threads=1 --nocapture"
8+
test-tube-build = "build --release --lib --target wasm32-unknown-unknown --target-dir ./test-tube-build"

smart-contracts/osmosis/contracts/cl-vault/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ crate-type = ["cdylib", "rlib"]
1515
[[bin]]
1616
name = "schema"
1717

18+
[[test]]
19+
name = "test-tube"
20+
path = "tests/test-tube/integration.rs"
21+
required-features = ["test-tube"]
22+
23+
[[test]]
24+
name = "prop-test"
25+
path = "tests/test-tube/fuzzer.rs"
26+
required-features = ["test-tube"]
27+
1828
[features]
1929
backtraces = ["cosmwasm-std/backtraces"]
2030
library = []

smart-contracts/osmosis/contracts/cl-vault/tests/admin.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/admin.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{fixture_default, PERFORMANCE_FEE_DEFAULT};
1+
use crate::setup::{fixture_default, PERFORMANCE_FEE_DEFAULT};
52

63
use cl_vault::{
74
msg::{

smart-contracts/osmosis/contracts/cl-vault/tests/any_deposit.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/any_deposit.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{
1+
use crate::setup::{
52
fixture_dex_router, ACCOUNTS_INIT_BALANCE, ACCOUNTS_NUM, DENOM_BASE, DENOM_QUOTE,
63
MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT,
74
};

smart-contracts/osmosis/contracts/cl-vault/tests/authz.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/authz.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{
1+
use crate::setup::{
52
fixture_default, get_amount_from_denom, DENOM_BASE, DENOM_QUOTE, PERFORMANCE_FEE_DEFAULT,
63
};
74

smart-contracts/osmosis/contracts/cl-vault/tests/autocompound.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/autocompound.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{
1+
use crate::setup::{
52
calculate_expected_refunds, fixture_dex_router, get_balance_amount,
63
get_event_attributes_by_ty_and_key, ACCOUNTS_INIT_BALANCE, ACCOUNTS_NUM, DENOM_BASE,
74
DENOM_QUOTE, DENOM_REWARD, DEPOSIT_AMOUNT, INITIAL_POSITION_BURN, PERFORMANCE_FEE_DEFAULT,

smart-contracts/osmosis/contracts/cl-vault/tests/deposit_withdraw.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/deposit_withdraw.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{
1+
use crate::setup::{
52
fixture_default, get_event_attributes_by_ty_and_key, ACCOUNTS_INIT_BALANCE, DENOM_BASE,
63
DENOM_QUOTE, PERFORMANCE_FEE_DEFAULT,
74
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod setup;
2+
3+
mod proptest;

smart-contracts/osmosis/contracts/cl-vault/tests/initialize.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/initialize.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{fixture_default, DENOM_BASE, DENOM_QUOTE, MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT};
1+
use crate::setup::{
2+
fixture_default, DENOM_BASE, DENOM_QUOTE, MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT,
3+
};
54

65
use cl_vault::{
76
msg::{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mod setup;
2+
3+
mod admin;
4+
mod any_deposit;
5+
mod authz;
6+
mod autocompound;
7+
mod deposit_withdraw;
8+
mod initialize;
9+
mod range;
10+
mod rewards;

smart-contracts/osmosis/contracts/cl-vault/tests/proptest.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/proptest.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{
1+
use crate::setup::{
52
get_event_attributes_by_ty_and_key, init_test_contract, MAX_SLIPPAGE_HIGH,
63
PERFORMANCE_FEE_DEFAULT,
74
};
@@ -332,7 +329,6 @@ fn get_cases() -> u32 {
332329
proptest! {
333330
#![proptest_config(ProptestConfig::with_cases(get_cases()))]
334331
#[test]
335-
#[ignore]
336332
fn test_complete_works(
337333
(initial_lower_tick, initial_upper_tick) in get_initial_range(),
338334
actions in get_strategy_list(),

smart-contracts/osmosis/contracts/cl-vault/tests/range.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/range.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{
1+
use crate::setup::{
52
fixture_default, fixture_dex_router, init_test_contract, ADMIN_BALANCE_AMOUNT, DENOM_BASE,
63
DENOM_QUOTE, MAX_SLIPPAGE_HIGH, PERFORMANCE_FEE_DEFAULT,
74
};

smart-contracts/osmosis/contracts/cl-vault/tests/rewards.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/rewards.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#![cfg(feature = "test-tube")]
2-
3-
mod setup;
4-
use setup::{
1+
use crate::setup::{
52
fixture_default, get_amount_from_denom, get_balance_amount, get_event_attributes_by_ty_and_key,
63
ACCOUNTS_INIT_BALANCE, ACCOUNTS_NUM, DENOM_BASE, DENOM_QUOTE, DEPOSIT_AMOUNT,
74
PERFORMANCE_FEE_DEFAULT,

smart-contracts/osmosis/contracts/cl-vault/tests/setup/mod.rs renamed to smart-contracts/osmosis/contracts/cl-vault/tests/test-tube/setup.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg(feature = "test-tube")]
21
#![allow(dead_code)]
32

43
use cl_vault::{helpers::generic::sort_tokens, msg::InstantiateMsg, state::VaultConfig};

smart-contracts/osmosis/contracts/dex-router-osmosis/.cargo/config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
wasm = "build --release --target wasm32-unknown-unknown"
33
unit-test = "test --lib"
44
schema = "run --bin schema"
5-
test-tube = "test --features test-tube -- --include-ignored --test-threads=1"
5+
test-tube = "test --test test-tube --features test-tube -- --test-threads=1"
66
test-tube-build = "build --release --lib --target wasm32-unknown-unknown --target-dir ./test-tube-build"

smart-contracts/osmosis/contracts/dex-router-osmosis/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ crate-type = ["cdylib", "rlib"]
2222
[[bin]]
2323
name = "schema"
2424

25+
[[test]]
26+
name = "test-tube"
27+
path = "tests/integration.rs"
28+
required-features = ["test-tube"]
29+
2530
[features]
2631
default = []
2732
library = []

smart-contracts/osmosis/contracts/merkle-incentives/.cargo/config renamed to smart-contracts/osmosis/contracts/merkle-incentives/.cargo/config.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
wasm = "build --release --lib --target wasm32-unknown-unknown"
33
unit-test = "test --lib"
44
schema = "run --bin schema"
5-
test-tube = "test --features test-tube -- --include-ignored --test-threads=1"
5+
test-tube = "test --test test-tube --features test-tube -- --test-threads=1"
66
test-tube-build = "build --release --lib --target wasm32-unknown-unknown --target-dir ./test-tube-build"

smart-contracts/osmosis/contracts/merkle-incentives/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ crate-type = ["cdylib", "rlib"]
1010
[[bin]]
1111
name = "schema"
1212

13+
[[test]]
14+
name = "test-tube"
15+
path = "tests/merkle.rs"
16+
required-features = ["test-tube"]
17+
1318
[features]
1419
backtraces = ["cosmwasm-std/backtraces"]
1520
library = []

smart-contracts/quasar/proto-build/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ authors = ["Quasar"]
55
edition = "2018"
66
publish = false
77

8+
[features]
9+
# dummy feature, workaround for rust-analyzer not being able to specify features per workspace
10+
test-tube = []
11+
812
[dependencies]
913
prost = { workspace = true }
1014
prost-build = { workspace = true }

0 commit comments

Comments
 (0)