Skip to content

Commit

Permalink
Merge pull request #151 from provenance-io/kwtalley/provwasm-test-tub…
Browse files Browse the repository at this point in the history
…e-integration-tests

Kwtalley/provwasm test tube integration tests
  • Loading branch information
kwtalley authored May 11, 2024
2 parents 7215c64 + 5fbc30e commit 94686c0
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
run: |
cd ./contracts/tutorial
make all
- name: Integration test
run: |
cargo test --test tutorial
- name: Smart Contract Test setup
uses: provenance-io/[email protected]
with:
Expand All @@ -52,6 +55,9 @@ jobs:
run: |
cd ./contracts/attrs
make all
- name: Integration test
run: |
cargo test --test attrs
- name: Smart Contract Test setup
uses: provenance-io/[email protected]
with:
Expand All @@ -73,6 +79,9 @@ jobs:
run: |
cd ./contracts/marker
make all
- name: Integration test
run: |
cargo test --test marker
- name: Provenance Test
uses: provenance-io/[email protected]
with:
Expand Down Expand Up @@ -115,6 +124,9 @@ jobs:
run: |
cd ./contracts/name
make all
- name: Integration test
run: |
cargo test --test name
- name: Smart Contract Test setup
uses: provenance-io/[email protected]
with:
Expand Down Expand Up @@ -157,6 +169,9 @@ jobs:
run: |
cd ./contracts/trigger
make all
- name: Integration test
run: |
cargo test --test trigger
- name: Smart Contract Test setup
uses: provenance-io/[email protected]
with:
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"contracts/scope",
"contracts/trigger",
"contracts/tutorial",
"integration_tests"
]

[workspace.package]
Expand All @@ -36,6 +37,7 @@ provwasm-common = { version = "0.1.0", path = "packages/provwasm-common" }
provwasm-mocks = { version = "2.2.0", path = "packages/provwasm-mocks" }
provwasm-proc-macro = { version = "0.1.1", path = "packages/provwasm-proc-macro" }
provwasm-std = { version = "2.2.0", path = "packages/provwasm-std" }
provwasm-test-tube = { git = "https://github.com/provenance-io/provwasm-test-tube", branch = "main" }

base64 = "0.22.0"
chrono = { version = "0.4.37", default-features = false }
Expand All @@ -51,6 +53,9 @@ serde = { version = "1.0.197", default-features = false, features = [
serde_json = { version = "1.0.115", features = ["std"] }
thiserror = { version = "1.0.58" }

[patch.crates-io]
provwasm-std = { version = "2.2.0", path = "packages/provwasm-std" }

[profile.release]
opt-level = 3
debug = false
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ scope:
.PHONY: trigger
trigger:
@make -C contracts/trigger

.PHONY: integration
integration:
@make -C integration_tests
8 changes: 4 additions & 4 deletions contracts/marker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ license = { workspace = true }
authors = ["Phil Story <[email protected]>", "Ken Talley <[email protected]"]

exclude = [
"marker.wasm",
"checksums.txt",
"marker.wasm",
"checksums.txt",
]

[lib]
Expand All @@ -23,10 +23,10 @@ cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
provwasm-std = { workspace = true }
schemars = {workspace = true}
schemars = { workspace = true }
serde = { workspace = true, default-features = false, features = ["derive"] }
thiserror = { workspace = true }

[dev-dependencies]
prost = {workspace = true, default-features = false}
prost = { workspace = true, default-features = false }
provwasm-mocks = { workspace = true }
25 changes: 25 additions & 0 deletions integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "integration"
version = { workspace = true }
repository = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
authors = ["Ken Talley <[email protected]"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = []

[dependencies]
cosmwasm-std = { workspace = true }
attrs = { version = "2.2.0", path = "../contracts/attrs" }
marker = { version = "2.2.0", path = "../contracts/marker" }
name = { version = "2.2.0", path = "../contracts/name" }
trigger = { version = "2.2.0", path = "../contracts/trigger" }
provwasm-tutorial = { version = "2.2.0", path = "../contracts/tutorial" }
provwasm-std = { workspace = true }

[dev-dependencies]
prost = { workspace = true, default-features = false }
provwasm-mocks = { workspace = true }
provwasm-test-tube = { workspace = true }
33 changes: 33 additions & 0 deletions integration_tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.PHONY: all
all: fmt test lint schema

UNAME_M := $(shell uname -m)

.PHONY: fmt
fmt:
@cargo fmt --all -- --check

.PHONY: build
build:
@cargo build

.PHONY: test
test:
@cargo test

.PHONY: lint
lint:
@cargo clippy

.PHONY: schema
schema:
@cargo schema

.PHONY: clean
clean:
@cargo clean
@cargo clean --target-dir artifacts

.PHONY: check
check:
@cargo check
103 changes: 103 additions & 0 deletions integration_tests/tests/attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use cosmwasm_std::Coin;
use provwasm_test_tube::wasm::Wasm;
use provwasm_test_tube::{Account, Module, ProvwasmTestApp, RunnerError};

use attrs::msg::{ExecuteMsg, InitMsg, Label, LabelNameResponse, LabelsResponse, QueryMsg};

#[test]
fn create_update_delete_attr() -> Result<(), RunnerError> {
let app = ProvwasmTestApp::default();
let accs = app.init_accounts(&[Coin::new(100_000_000_000_000, "nhash")], 1)?;
let admin = &accs[0];

let wasm = Wasm::new(&app);
let wasm_byte_code = std::fs::read("../contracts/attrs/artifacts/attrs.wasm").unwrap();
let store_res = wasm.store_code(&wasm_byte_code, None, admin);
let code_id = store_res?.data.code_id;
assert_eq!(code_id, 1);

// let init_admins = vec![admin.address()];
let contract_addr = wasm
.instantiate(
code_id,
&InitMsg {
name: "attrs-test.sc.pb".to_string(),
},
Some(&admin.address()),
None,
&[],
admin,
)?
.data
.address;

wasm.execute::<ExecuteMsg>(&contract_addr, &ExecuteMsg::BindLabelName {}, &[], admin)?;
let label_name_response =
wasm.query::<QueryMsg, LabelNameResponse>(&contract_addr, &QueryMsg::GetLabelName {})?;
assert_eq!(label_name_response.name, "label.attrs-test.sc.pb");

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::AddLabel {
text: "hello".to_string(),
},
&[],
admin,
)?;
wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::AddLabel {
text: "wasm".to_string(),
},
&[],
admin,
)?;
let label_name_response =
wasm.query::<QueryMsg, LabelsResponse>(&contract_addr, &QueryMsg::GetLabels {})?;
assert!(label_name_response.labels.contains(&Label {
text: "hello".to_string()
}));
assert!(label_name_response.labels.contains(&Label {
text: "wasm".to_string()
}));

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::UpdateLabel {
original_text: "hello".to_string(),
update_text: "goodbye".to_string(),
},
&[],
admin,
)?;
let label_name_response =
wasm.query::<QueryMsg, LabelsResponse>(&contract_addr, &QueryMsg::GetLabels {})?;
assert!(label_name_response.labels.contains(&Label {
text: "goodbye".to_string()
}));
assert!(label_name_response.labels.contains(&Label {
text: "wasm".to_string()
}));

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::DeleteDistinctLabel {
text: "wasm".to_string(),
},
&[],
admin,
)?;
let label_name_response =
wasm.query::<QueryMsg, LabelsResponse>(&contract_addr, &QueryMsg::GetLabels {})?;
assert!(label_name_response.labels.contains(&Label {
text: "goodbye".to_string()
}));

wasm.execute::<ExecuteMsg>(&contract_addr, &ExecuteMsg::DeleteLabels {}, &[], admin)?;

let label_name_response =
wasm.query::<QueryMsg, LabelsResponse>(&contract_addr, &QueryMsg::GetLabels {})?;
assert!(label_name_response.labels.is_empty());

Ok(())
}
93 changes: 93 additions & 0 deletions integration_tests/tests/marker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use cosmwasm_std::{Coin, Uint128};
use provwasm_test_tube::wasm::Wasm;
use provwasm_test_tube::{Account, Module, ProvwasmTestApp, RunnerError};

use marker::msg::{ExecuteMsg, InitMsg, QueryMsg};
use marker::types::Marker;

#[test]
fn create_and_withdraw() -> Result<(), RunnerError> {
let app = ProvwasmTestApp::default();
let accs = app.init_accounts(&[Coin::new(100_000_000_000_000, "nhash")], 1)?;
let admin = &accs[0];

let wasm = Wasm::new(&app);
let wasm_byte_code = std::fs::read("../contracts/marker/artifacts/marker.wasm").unwrap();
let store_res = wasm.store_code(&wasm_byte_code, None, admin);
let code_id = store_res?.data.code_id;
assert_eq!(code_id, 1);

// let init_admins = vec![admin.address()];
let contract_addr = wasm
.instantiate(
code_id,
&InitMsg {
name: "marker-test.sc.pb".to_string(),
},
Some(&admin.address()),
None,
&[],
admin,
)?
.data
.address;

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::Create {
supply: Uint128::new(100),
denom: "spy".into(),
allow_forced_transfer: false,
},
&[],
admin,
)?;

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::GrantAccess {
denom: "spy".into(),
},
&[],
admin,
)?;

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::Finalize {
denom: "spy".into(),
},
&[],
admin,
)?;

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::Activate {
denom: "spy".into(),
},
&[],
admin,
)?;

wasm.execute::<ExecuteMsg>(
&contract_addr,
&ExecuteMsg::Withdraw {
amount: Uint128::new(20),
denom: "spy".into(),
},
&[],
admin,
)?;

let marker = wasm.query::<QueryMsg, Marker>(
&contract_addr,
&QueryMsg::GetByDenom {
denom: "spy".into(),
},
)?;

assert_eq!(marker.marker_account.denom, "spy");

Ok(())
}
5 changes: 5 additions & 0 deletions integration_tests/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod attrs;
mod marker;
mod name;
mod trigger;
mod tutorial;
Loading

0 comments on commit 94686c0

Please sign in to comment.