conditionally implementing 'TestableContract' inside corresponding crates
This commit is contained in:
@@ -11,5 +11,5 @@ cw-storage-plus = "0.13.4"
|
||||
cosmwasm-contract-testing = { path = "../../common/cosmwasm-smart-contracts/testing" }
|
||||
nym-mixnet-contract-common = { path= "../../common/cosmwasm-smart-contracts/mixnet-contract" }
|
||||
nym-vesting-contract-common = { path= "../../common/cosmwasm-smart-contracts/vesting-contract" }
|
||||
nym-vesting-contract = { path = "../vesting"}
|
||||
nym-mixnet-contract = { path = "../mixnet"}
|
||||
nym-vesting-contract = { path = "../vesting", features = ["testing_mocks"] }
|
||||
nym-mixnet-contract = { path = "../mixnet", features = ["testing_mocks"] }
|
||||
@@ -1,98 +1,19 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use cosmwasm_contract_testing::{
|
||||
env_with_block_info, ContractState, MultiContractMock, TestableContract,
|
||||
};
|
||||
use cosmwasm_contract_testing::{env_with_block_info, ContractState, MultiContractMock};
|
||||
use cosmwasm_std::testing::mock_info;
|
||||
use cosmwasm_std::{
|
||||
Addr, BankMsg, BlockInfo, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, Timestamp,
|
||||
};
|
||||
use cosmwasm_std::{Addr, BankMsg, BlockInfo, Timestamp};
|
||||
use cw_storage_plus::Map;
|
||||
use mixnet_contract::MixnetContract;
|
||||
use nym_mixnet_contract_common::rewarding::PendingRewardResponse;
|
||||
use vesting_contract::vesting::Account;
|
||||
|
||||
struct VestingContract;
|
||||
|
||||
impl TestableContract for VestingContract {
|
||||
type ContractError = vesting_contract::errors::ContractError;
|
||||
type InstantiateMsg = nym_vesting_contract_common::InitMsg;
|
||||
type ExecuteMsg = nym_vesting_contract_common::ExecuteMsg;
|
||||
type QueryMsg = nym_vesting_contract_common::QueryMsg;
|
||||
|
||||
fn new() -> Self {
|
||||
VestingContract
|
||||
}
|
||||
|
||||
fn instantiate(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: Self::InstantiateMsg,
|
||||
) -> Result<Response, Self::ContractError> {
|
||||
vesting_contract::contract::instantiate(deps, env, info, msg)
|
||||
}
|
||||
|
||||
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 = nym_mixnet_contract_common::error::MixnetContractError;
|
||||
type InstantiateMsg = nym_mixnet_contract_common::InstantiateMsg;
|
||||
type ExecuteMsg = nym_mixnet_contract_common::ExecuteMsg;
|
||||
type QueryMsg = nym_mixnet_contract_common::QueryMsg;
|
||||
|
||||
fn new() -> Self {
|
||||
MixnetContract
|
||||
}
|
||||
|
||||
fn instantiate(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: Self::InstantiateMsg,
|
||||
) -> Result<Response, Self::ContractError> {
|
||||
mixnet_contract::contract::instantiate(deps, env, info, msg)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
use vesting_contract::VestingContract;
|
||||
|
||||
// this is not directly exported by the vesting contract, but we can easily recreate it
|
||||
const VESTING_ACCOUNTS: Map<'_, Addr, Account> = Map::new("acc");
|
||||
|
||||
// hardcoded values from the data dump sources
|
||||
const MIXNET_CONTRACT_ADDRESS: &str =
|
||||
"n14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sjyvg3g";
|
||||
const VESTING_CONTRACT_ADDRESS: &str =
|
||||
|
||||
@@ -36,15 +36,19 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] }
|
||||
thiserror = { version = "1.0.23" }
|
||||
time = { version = "0.3", features = ["macros"] }
|
||||
|
||||
cosmwasm-contract-testing = { path = "../../common/cosmwasm-smart-contracts/testing", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
cosmwasm-schema = "1.0.0"
|
||||
rand_chacha = "0.2"
|
||||
#rand = "0.7"
|
||||
nym-crypto = { path = "../../common/crypto", features = ["asymmetric", "rand"] }
|
||||
|
||||
|
||||
[build-dependencies]
|
||||
vergen = { version = "5", default-features = false, features = ["build", "git", "rustc"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
contract-testing = ["mixnet-contract-common/contract-testing"]
|
||||
testing_mocks = ["cosmwasm-contract-testing", "contract-testing"]
|
||||
|
||||
@@ -17,3 +17,6 @@ mod support;
|
||||
|
||||
#[cfg(feature = "contract-testing")]
|
||||
mod testing;
|
||||
|
||||
#[cfg(feature = "testing_mocks")]
|
||||
pub use testing::mock_helpers::MixnetContract;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::contract;
|
||||
use cosmwasm_contract_testing::TestableContract;
|
||||
use cosmwasm_std::{Deps, DepsMut, Env, MessageInfo, QueryResponse, Response};
|
||||
use mixnet_contract_common::error::MixnetContractError;
|
||||
use mixnet_contract_common::{ExecuteMsg, InstantiateMsg, QueryMsg};
|
||||
|
||||
pub struct MixnetContract;
|
||||
|
||||
impl TestableContract for MixnetContract {
|
||||
type ContractError = MixnetContractError;
|
||||
type InstantiateMsg = InstantiateMsg;
|
||||
type ExecuteMsg = ExecuteMsg;
|
||||
type QueryMsg = QueryMsg;
|
||||
|
||||
fn new() -> Self {
|
||||
MixnetContract
|
||||
}
|
||||
|
||||
fn instantiate(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: Self::InstantiateMsg,
|
||||
) -> Result<Response, Self::ContractError> {
|
||||
contract::instantiate(deps, env, info, msg)
|
||||
}
|
||||
|
||||
fn execute(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: Self::ExecuteMsg,
|
||||
) -> Result<Response, Self::ContractError> {
|
||||
contract::execute(deps, env, info, msg)
|
||||
}
|
||||
|
||||
fn query(
|
||||
deps: Deps<'_>,
|
||||
env: Env,
|
||||
msg: Self::QueryMsg,
|
||||
) -> Result<QueryResponse, Self::ContractError> {
|
||||
contract::query(deps, env, msg)
|
||||
}
|
||||
}
|
||||
@@ -2,3 +2,6 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
pub(crate) mod transactions;
|
||||
|
||||
#[cfg(feature = "testing_mocks")]
|
||||
pub mod mock_helpers;
|
||||
|
||||
@@ -31,11 +31,11 @@ schemars = "0.8"
|
||||
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
||||
thiserror = { version = "1.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
rand_chacha = "0.3.1"
|
||||
base64 = "0.21.0"
|
||||
hex = "0.4.3"
|
||||
serde_json = "1.0.66"
|
||||
cosmwasm-contract-testing = { path = "../../common/cosmwasm-smart-contracts/testing", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
vergen = { version = "5", default-features = false, features = ["build", "git", "rustc"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
testing_mocks = ["cosmwasm-contract-testing"]
|
||||
@@ -11,3 +11,6 @@ mod storage;
|
||||
mod support;
|
||||
mod traits;
|
||||
pub mod vesting;
|
||||
|
||||
#[cfg(feature = "testing_mocks")]
|
||||
pub use support::mock_helpers::VestingContract;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::contract;
|
||||
use crate::errors::ContractError;
|
||||
use cosmwasm_contract_testing::TestableContract;
|
||||
use cosmwasm_std::{Deps, DepsMut, Env, MessageInfo, QueryResponse, Response};
|
||||
use vesting_contract_common::{ExecuteMsg, InitMsg, QueryMsg};
|
||||
|
||||
pub struct VestingContract;
|
||||
|
||||
impl TestableContract for VestingContract {
|
||||
type ContractError = ContractError;
|
||||
type InstantiateMsg = InitMsg;
|
||||
type ExecuteMsg = ExecuteMsg;
|
||||
type QueryMsg = QueryMsg;
|
||||
|
||||
fn new() -> Self {
|
||||
VestingContract
|
||||
}
|
||||
|
||||
fn instantiate(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: Self::InstantiateMsg,
|
||||
) -> Result<Response, Self::ContractError> {
|
||||
contract::instantiate(deps, env, info, msg)
|
||||
}
|
||||
|
||||
fn execute(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: Self::ExecuteMsg,
|
||||
) -> Result<Response, Self::ContractError> {
|
||||
contract::execute(deps, env, info, msg)
|
||||
}
|
||||
|
||||
fn query(
|
||||
deps: Deps<'_>,
|
||||
env: Env,
|
||||
msg: Self::QueryMsg,
|
||||
) -> Result<QueryResponse, Self::ContractError> {
|
||||
contract::query(deps, env, msg)
|
||||
}
|
||||
}
|
||||
@@ -1 +1,7 @@
|
||||
// Copyright 2022-2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
pub mod tests;
|
||||
|
||||
#[cfg(feature = "testing_mocks")]
|
||||
pub mod mock_helpers;
|
||||
|
||||
Reference in New Issue
Block a user