Struct CloneTesting

Source
pub struct CloneTesting<S: StateInterface = MockState> {
    pub chain: ChainInfoOwned,
    pub sender: Addr,
    pub state: Rc<RefCell<S>>,
    pub app: Rc<RefCell<App<BankKeeper, MockApiBech32>>>,
}
Expand description

Wrapper around a cw-multi-test App backend.

Stores a local state with a mapping of contract_id -> code_id/address

The state is customizable by implementing the StateInterface trait on a custom struct and providing it on the custom constructor.

§Example

use cw_orch_clone_testing::CloneTesting;
use cw_orch_core::environment::TxHandler;

let chain = cw_orch_daemon::networks::JUNO_1;
let mock: CloneTesting = CloneTesting::new(chain.clone()).unwrap();
let sender = mock.sender();

// set a balance
mock.set_balance(&sender, vec![coin(100u128, "token")]).unwrap();

// query the balance
let balance: Uint128 = mock.query_balance(&sender, "token").unwrap();
assert_eq!(balance.u128(), 100u128);

§Example with custom state

use cw_orch_clone_testing::CloneTesting;
use cw_orch_core::environment::StateInterface;
// We just use the MockState as an example here, but you can implement your own state struct.
use cw_orch_clone_testing::MockState as CustomState;

let rt = tokio::runtime::Runtime::new().unwrap();
let chain = cw_orch_daemon::networks::JUNO_1;
let mock: CloneTesting = CloneTesting::new_custom(&rt, chain.clone(), CustomState::new(chain.clone().into(), "mock")).unwrap();

Fields§

§chain: ChainInfoOwned

Chain data of the chain you want to fork

§sender: Addr

Address used for the operations.

§state: Rc<RefCell<S>>

Inner mutable state storage for contract addresses and code-ids

§app: Rc<RefCell<App<BankKeeper, MockApiBech32>>>

Inner mutable cw-multi-test app backend

Implementations§

Source§

impl CloneTesting

Source

pub fn init_account(&self) -> Addr

Ceates a new valid account

Source

pub fn set_balance( &self, address: &Addr, amount: Vec<Coin>, ) -> Result<(), CwEnvError>

Set the bank balance of an address.

Source

pub fn add_balance( &self, address: &Addr, amount: Vec<Coin>, ) -> Result<(), CwEnvError>

Adds the bank balance of an address.

Source

pub fn set_balances( &self, balances: &[(&Addr, &[Coin])], ) -> Result<(), CwEnvError>

Set the balance for multiple coins at once.

Source

pub fn query_balance( &self, address: &Addr, denom: &str, ) -> Result<Uint128, CwEnvError>

Query the (bank) balance of a native token for and address. Returns the amount of the native token.

Source

pub fn query_all_balances( &self, address: &Addr, ) -> Result<Vec<Coin>, CwEnvError>

Fetch all the balances of an address.

Source

pub fn upload_wasm<T: Uploadable + ContractInstance<CloneTesting>>( &self, contract: &T, ) -> Result<<Self as TxHandler>::Response, CwEnvError>

Source§

impl CloneTesting<MockState>

Source

pub fn new(chain: impl Into<ChainInfoOwned>) -> Result<Self, CwEnvError>

Create a mock environment with the default mock state.

Source

pub fn new_with_runtime( rt: &Runtime, chain: impl Into<ChainInfoOwned>, ) -> Result<Self, CwEnvError>

Create a mock environment with the default mock state. It uses a custom runtime object to control async requests

Source

pub fn new_with_deployment_id( rt: &Runtime, chain: impl Into<ChainInfoOwned>, deployment_id: &str, ) -> Result<Self, CwEnvError>

Source§

impl<S: StateInterface> CloneTesting<S>

Source

pub fn new_custom( rt: &Runtime, chain: impl Into<ChainInfoOwned>, custom_state: S, ) -> Result<Self, CwEnvError>

Create a mock environment with a custom mock state. The state is customizable by implementing the StateInterface trait on a custom struct and providing it on the custom constructor.

Source

pub fn storage_analysis(&self) -> StorageAnalyzer

Trait Implementations§

Source§

impl BankSetter for CloneTesting

Source§

type T = CloneBankQuerier

Source§

fn set_balance( &mut self, address: &Addr, amount: Vec<Coin>, ) -> Result<(), <Self as TxHandler>::Error>

Source§

fn add_balance( &mut self, address: &Addr, amount: Vec<Coin>, ) -> Result<(), Self::Error>

Source§

impl<S: StateInterface> ChainState for CloneTesting<S>

Source§

type Out = Rc<RefCell<S>>

The type of the underlying state.
Source§

fn state(&self) -> Self::Out

Get the underlying state.
Source§

fn can_load_state_from_state_file(&self) -> bool

Returns wether this environment can load state from the state file. Read more
Source§

impl<S: Clone + StateInterface> Clone for CloneTesting<S>

Source§

fn clone(&self) -> CloneTesting<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl DefaultQueriers for CloneTesting

Source§

impl EnvironmentQuerier for CloneTesting

Source§

fn env_info(&self) -> EnvironmentInfo

Get some details about the environment.
Source§

impl<S: StateInterface> QuerierGetter<CloneBankQuerier> for CloneTesting<S>

Source§

impl<S: StateInterface> QuerierGetter<CloneNodeQuerier> for CloneTesting<S>

Source§

impl<S: StateInterface> QuerierGetter<CloneWasmQuerier<S>> for CloneTesting<S>

Source§

impl QueryHandler for CloneTesting

Source§

type Error = CwEnvError

Source§

fn wait_blocks(&self, amount: u64) -> Result<(), CwEnvError>

Wait for an amount of blocks.
Source§

fn wait_seconds(&self, secs: u64) -> Result<(), CwEnvError>

Wait for an amount of seconds.
Source§

fn next_block(&self) -> Result<(), CwEnvError>

Wait for next block.
Source§

fn block_info(&self) -> Result<BlockInfo, <Self::Node as Querier>::Error>

Return current block info see BlockInfo.
Source§

fn balance( &self, address: &Addr, denom: Option<String>, ) -> Result<Vec<Coin>, <Self::Bank as Querier>::Error>

Source§

fn query<Q, T>( &self, query_msg: &Q, contract_address: &Addr, ) -> Result<T, <Self::Wasm as Querier>::Error>

Send a QueryMsg to a contract.
Source§

impl<S: StateInterface> TxHandler for CloneTesting<S>

Source§

type Response = AppResponse

Response type for transactions on an environment.
Source§

type Error = CwEnvError

Error type for transactions on an environment.
Source§

type ContractSource = Box<dyn Contract<Empty>>

Source type for uploading to the environment.
Source§

type Sender = Addr

Source§

fn sender(&self) -> &Addr

Get a read-only Sender
Source§

fn sender_addr(&self) -> Addr

Gets the address of the current wallet used to sign transactions.
Source§

fn set_sender(&mut self, sender: Self::Sender)

Sets wallet to sign transactions.
Source§

fn upload<T: Uploadable>( &self, _contract: &T, ) -> Result<Self::Response, CwEnvError>

Uploads a contract to the chain.
Source§

fn upload_with_access_config<T: Uploadable>( &self, contract_source: &T, _access_config: Option<AccessConfig>, ) -> Result<Self::Response, Self::Error>

Uploads a contract to the chain and specify the permissions for instantiating
Source§

fn execute<E: Serialize + Debug>( &self, exec_msg: &E, coins: &[Coin], contract_address: &Addr, ) -> Result<Self::Response, CwEnvError>

Send a ExecMsg to a contract.
Source§

fn instantiate<I: Serialize + Debug>( &self, code_id: u64, init_msg: &I, label: Option<&str>, admin: Option<&Addr>, coins: &[Coin], ) -> Result<Self::Response, CwEnvError>

Send a InstantiateMsg to a contract.
Source§

fn migrate<M: Serialize + Debug>( &self, migrate_msg: &M, new_code_id: u64, contract_address: &Addr, ) -> Result<Self::Response, CwEnvError>

Send a MigrateMsg to a contract.
Source§

fn instantiate2<I: Serialize + Debug>( &self, code_id: u64, init_msg: &I, label: Option<&str>, admin: Option<&Addr>, coins: &[Coin], salt: Binary, ) -> Result<Self::Response, Self::Error>

Send a Instantiate2Msg to a contract.
Source§

fn bank_send( &self, receiver: &Addr, amount: &[Coin], ) -> Result<Self::Response, Self::Error>

Source§

fn call_as(&self, sender: &Self::Sender) -> Self

Clones the chain with a different sender. Usually used to call a contract as a different sender.
Source§

impl<T> WasmUpload<CloneTesting> for T

Auto Trait Implementations§

§

impl<S> Freeze for CloneTesting<S>

§

impl<S = MockState> !RefUnwindSafe for CloneTesting<S>

§

impl<S = MockState> !Send for CloneTesting<S>

§

impl<S = MockState> !Sync for CloneTesting<S>

§

impl<S> Unpin for CloneTesting<S>

§

impl<S = MockState> !UnwindSafe for CloneTesting<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> CwEnv for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MutCwEnv for T
where T: BankSetter + CwEnv,