sample integration test for mixnet-vesting contracts

This commit is contained in:
Jędrzej Stuczyński
2023-02-15 17:47:32 +00:00
parent fdd5b55e14
commit 2d7b2b1fda
8 changed files with 179 additions and 1 deletions
Generated
+35
View File
@@ -902,6 +902,19 @@ dependencies = [
"thiserror",
]
[[package]]
name = "cosmwasm-contract-testing"
version = "0.1.0"
dependencies = [
"base64 0.21.0",
"cosmwasm-std",
"cosmwasm-storage",
"hex",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "cosmwasm-crypto"
version = "1.0.0"
@@ -941,6 +954,16 @@ dependencies = [
"uint",
]
[[package]]
name = "cosmwasm-storage"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d18403b07304d15d304dad11040d45bbcaf78d603b4be3fb5e2685c16f9229b5"
dependencies = [
"cosmwasm-std",
"serde",
]
[[package]]
name = "cpufeatures"
version = "0.2.5"
@@ -2729,6 +2752,18 @@ dependencies = [
"web-sys",
]
[[package]]
name = "integration-tests"
version = "0.1.0"
dependencies = [
"cosmwasm-contract-testing",
"cosmwasm-std",
"mixnet-contract",
"mixnet-contract-common",
"vesting-contract",
"vesting-contract-common",
]
[[package]]
name = "io-lifetimes"
version = "1.0.5"
+2
View File
@@ -34,8 +34,10 @@ members = [
"common/cosmwasm-smart-contracts/coconut-dkg",
"common/cosmwasm-smart-contracts/contracts-common",
"common/cosmwasm-smart-contracts/group-contract",
"common/cosmwasm-smart-contracts/integration-tests",
"common/cosmwasm-smart-contracts/mixnet-contract",
"common/cosmwasm-smart-contracts/multisig-contract",
"common/cosmwasm-smart-contracts/testing",
"common/cosmwasm-smart-contracts/vesting-contract",
"common/mobile-storage",
"common/credential-storage",
@@ -0,0 +1,14 @@
[package]
name = "integration-tests"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cosmwasm-std = "1.0.0"
cosmwasm-contract-testing = { path = "../testing" }
mixnet-contract-common = { path= "../mixnet-contract" }
vesting-contract-common = { path= "../vesting-contract" }
vesting-contract = { path = "../../../contracts/vesting"}
mixnet-contract = { path = "../../../contracts/mixnet"}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,123 @@
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
use cosmwasm_contract_testing::{
env_with_block_info, ContractMock, MultiContractMock, TestableContract,
};
use cosmwasm_std::testing::mock_info;
use cosmwasm_std::{
coin, BlockInfo, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, Timestamp,
};
struct VestingContract;
impl TestableContract for VestingContract {
type ContractError = vesting_contract::errors::ContractError;
type ExecuteMsg = vesting_contract_common::ExecuteMsg;
type QueryMsg = vesting_contract_common::QueryMsg;
fn new() -> Self {
VestingContract
}
fn execute(
deps: DepsMut<'_>,
env: Env,
info: MessageInfo,
msg: Self::ExecuteMsg,
) -> Result<Response, Self::ContractError> {
vesting_contract::contract::execute(deps, env, info, msg)
}
fn query(
deps: Deps<'_>,
env: Env,
msg: Self::QueryMsg,
) -> Result<QueryResponse, Self::ContractError> {
vesting_contract::contract::query(deps, env, msg)
}
}
struct MixnetContract;
impl TestableContract for MixnetContract {
type ContractError = mixnet_contract_common::error::MixnetContractError;
type ExecuteMsg = mixnet_contract_common::ExecuteMsg;
type QueryMsg = mixnet_contract_common::QueryMsg;
fn new() -> Self {
MixnetContract
}
fn execute(
deps: DepsMut<'_>,
env: Env,
info: MessageInfo,
msg: Self::ExecuteMsg,
) -> Result<Response, Self::ContractError> {
mixnet_contract::contract::execute(deps, env, info, msg)
}
fn query(
deps: Deps<'_>,
env: Env,
msg: Self::QueryMsg,
) -> Result<QueryResponse, Self::ContractError> {
mixnet_contract::contract::query(deps, env, msg)
}
}
#[test]
fn multi_mock() {
let mixnet_contract_address = "n14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sjyvg3g";
let vesting_contract_address = "n1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrq73f2nw";
let current_block = BlockInfo {
height: 1928125,
time: Timestamp::from_seconds(1676482616),
chain_id: "nymnet".to_string(),
};
let custom_env = env_with_block_info(current_block);
let mix_mock = ContractMock::try_from_state_dump(
"contract-states/15.02.23-173000-qwerty-mixnet.json",
Some(custom_env.clone()),
)
.unwrap()
.with_contract_address(mixnet_contract_address);
let vesting_mock = ContractMock::try_from_state_dump(
"contract-states/15.02.23-173000-qwerty-vesting.json",
Some(custom_env),
)
.unwrap()
.with_contract_address(vesting_contract_address);
let mut multi_mock = MultiContractMock::new();
multi_mock.add_contract::<MixnetContract>(mix_mock).unwrap();
multi_mock
.add_contract::<VestingContract>(vesting_mock)
.unwrap();
let res = multi_mock.execute_full::<VestingContract>(
vesting_contract_address,
mock_info("n1vuz06p7cgagxcaplfezchvpu99u4np7erfxa4c", &[]),
vesting_contract_common::ExecuteMsg::DelegateToMixnode {
mix_id: 7,
amount: coin(1000, "unym"),
on_behalf_of: None,
},
);
match res {
Ok(success) => {
// first we should have emitted a "vesting_delegation" event from the vesting contract
// followed by "v2_pending_delegation" from the mixnet contract
assert_eq!("vesting_delegation", success.steps[0].events[0].ty);
assert_eq!("v2_pending_delegation", success.steps[1].events[0].ty);
// println!("{}", success.pretty())
}
Err(err) => panic!("{err}"),
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
#![warn(clippy::unwrap_used)]
pub mod contract;
mod errors;
pub mod errors;
mod queued_migrations;
mod storage;
mod support;