Struct drink_next::session::Session
source · pub struct Session<R>{ /* private fields */ }
Expand description
Wrapper around Sandbox
that provides a convenient API for interacting with multiple contracts.
Instead of talking with a low-level Sandbox
, you can use this struct to keep context,
including: origin, gas_limit, transcoder and history of results.
Session
has two APIs: chain-ish and for singular actions. The first one can be used like:
Session::<MinimalRuntime>::new()?
.deploy_and(contract_bytes(), "new", NO_ARGS, NO_SALT, NO_ENDOWMENT, &get_transcoder())?
.call_and("foo", NO_ARGS, NO_ENDOWMENT)?
.with_actor(bob())
.call_and("bar", NO_ARGS, NO_ENDOWMENT)?;
The second one serves for one-at-a-time actions:
let mut session = Session::<MinimalRuntime>::new()?;
let _address = session.deploy(contract_bytes(), "new", NO_ARGS, NO_SALT, NO_ENDOWMENT, &get_transcoder())?;
let _result: u32 = session.call("foo", NO_ARGS, NO_ENDOWMENT)??;
session.set_actor(bob());
session.call::<_, ()>("bar", NO_ARGS, NO_ENDOWMENT)??;
You can also work with .contract
bundles like so:
// Simplest way, loading a bundle from the project's directory:
Session::<MinimalRuntime>::new()?
.deploy_bundle_and(local_contract_file!(), "new", NO_ARGS, NO_SALT, NO_ENDOWMENT)?; /* ... */
// Or choosing the file explicitly:
let contract = ContractBundle::load("path/to/your.contract")?;
Session::<MinimalRuntime>::new()?
.deploy_bundle_and(contract, "new", NO_ARGS, NO_SALT, NO_ENDOWMENT)?; /* ... */
Implementations§
source§impl<R> Session<R>
impl<R> Session<R>
sourcepub fn new() -> Result<Self, SessionError>
pub fn new() -> Result<Self, SessionError>
Creates a new Session
.
sourcepub fn with_actor(self, actor: AccountIdFor<R::Config>) -> Self
pub fn with_actor(self, actor: AccountIdFor<R::Config>) -> Self
Sets a new actor and returns updated self
.
sourcepub fn get_actor(&self) -> AccountIdFor<R::Config>
pub fn get_actor(&self) -> AccountIdFor<R::Config>
Returns currently set actor.
sourcepub fn set_actor(
&mut self,
actor: AccountIdFor<R::Config>
) -> AccountIdFor<R::Config>
pub fn set_actor( &mut self, actor: AccountIdFor<R::Config> ) -> AccountIdFor<R::Config>
Sets a new actor and returns the old one.
sourcepub fn with_gas_limit(self, gas_limit: Weight) -> Self
pub fn with_gas_limit(self, gas_limit: Weight) -> Self
Sets a new gas limit and returns updated self
.
sourcepub fn set_gas_limit(&mut self, gas_limit: Weight) -> Weight
pub fn set_gas_limit(&mut self, gas_limit: Weight) -> Weight
Sets a new gas limit and returns the old one.
sourcepub fn get_gas_limit(&self) -> Weight
pub fn get_gas_limit(&self) -> Weight
Returns currently set gas limit.
sourcepub fn with_determinism(self, determinism: Determinism) -> Self
pub fn with_determinism(self, determinism: Determinism) -> Self
Sets a new determinism policy and returns updated self
.
sourcepub fn set_determinism(&mut self, determinism: Determinism) -> Determinism
pub fn set_determinism(&mut self, determinism: Determinism) -> Determinism
Sets a new determinism policy and returns the old one.
sourcepub fn with_transcoder(
self,
contract_address: AccountIdFor<R::Config>,
transcoder: &Rc<ContractMessageTranscoder>
) -> Self
pub fn with_transcoder( self, contract_address: AccountIdFor<R::Config>, transcoder: &Rc<ContractMessageTranscoder> ) -> Self
Register a transcoder for a particular contract and returns updated self
.
sourcepub fn set_transcoder(
&mut self,
contract_address: AccountIdFor<R::Config>,
transcoder: &Rc<ContractMessageTranscoder>
)
pub fn set_transcoder( &mut self, contract_address: AccountIdFor<R::Config>, transcoder: &Rc<ContractMessageTranscoder> )
Registers a transcoder for a particular contract.
sourcepub fn mocking_api(&mut self) -> &mut impl MockingApi<R>
pub fn mocking_api(&mut self) -> &mut impl MockingApi<R>
Returns a reference for mocking API.
sourcepub fn deploy_and<S: AsRef<str> + Debug>(
self,
contract_bytes: Vec<u8>,
constructor: &str,
args: &[S],
salt: Vec<u8>,
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>,
transcoder: &Rc<ContractMessageTranscoder>
) -> Result<Self, SessionError>
pub fn deploy_and<S: AsRef<str> + Debug>( self, contract_bytes: Vec<u8>, constructor: &str, args: &[S], salt: Vec<u8>, endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>, transcoder: &Rc<ContractMessageTranscoder> ) -> Result<Self, SessionError>
Deploys a contract with a given constructor, arguments, salt and endowment. In case of
success, returns self
.
sourcepub fn deploy<S: AsRef<str> + Debug>(
&mut self,
contract_bytes: Vec<u8>,
constructor: &str,
args: &[S],
salt: Vec<u8>,
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>,
transcoder: &Rc<ContractMessageTranscoder>
) -> Result<AccountIdFor<R::Config>, SessionError>
pub fn deploy<S: AsRef<str> + Debug>( &mut self, contract_bytes: Vec<u8>, constructor: &str, args: &[S], salt: Vec<u8>, endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>, transcoder: &Rc<ContractMessageTranscoder> ) -> Result<AccountIdFor<R::Config>, SessionError>
Deploys a contract with a given constructor, arguments, salt and endowment. In case of success, returns the address of the deployed contract.
sourcepub fn deploy_bundle<S: AsRef<str> + Debug>(
&mut self,
contract_file: ContractBundle,
constructor: &str,
args: &[S],
salt: Vec<u8>,
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>
) -> Result<AccountIdFor<R::Config>, SessionError>
pub fn deploy_bundle<S: AsRef<str> + Debug>( &mut self, contract_file: ContractBundle, constructor: &str, args: &[S], salt: Vec<u8>, endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance> ) -> Result<AccountIdFor<R::Config>, SessionError>
Similar to deploy
but takes the parsed contract file (ContractBundle
) as a first argument.
You can get it with ContractBundle::load("some/path/your.contract")
or local_contract_file!()
sourcepub fn deploy_bundle_and<S: AsRef<str> + Debug>(
self,
contract_file: ContractBundle,
constructor: &str,
args: &[S],
salt: Vec<u8>,
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>
) -> Result<Self, SessionError>
pub fn deploy_bundle_and<S: AsRef<str> + Debug>( self, contract_file: ContractBundle, constructor: &str, args: &[S], salt: Vec<u8>, endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance> ) -> Result<Self, SessionError>
Similar to deploy_and
but takes the parsed contract file (ContractBundle
) as a first argument.
You can get it with ContractBundle::load("some/path/your.contract")
or local_contract_file!()
sourcepub fn upload_and(self, contract_bytes: Vec<u8>) -> Result<Self, SessionError>
pub fn upload_and(self, contract_bytes: Vec<u8>) -> Result<Self, SessionError>
Uploads a raw contract code. In case of success, returns self
.
sourcepub fn upload(
&mut self,
contract_bytes: Vec<u8>
) -> Result<HashFor<R::Config>, SessionError>
pub fn upload( &mut self, contract_bytes: Vec<u8> ) -> Result<HashFor<R::Config>, SessionError>
Uploads a raw contract code. In case of success returns the code hash.
sourcepub fn upload_bundle_and(
self,
contract_file: ContractBundle
) -> Result<Self, SessionError>
pub fn upload_bundle_and( self, contract_file: ContractBundle ) -> Result<Self, SessionError>
Similar to upload_and
but takes the contract bundle as the first argument.
You can obtain it using ContractBundle::load("some/path/your.contract")
or local_contract_file!()
sourcepub fn upload_bundle(
&mut self,
contract_file: ContractBundle
) -> Result<HashFor<R::Config>, SessionError>
pub fn upload_bundle( &mut self, contract_file: ContractBundle ) -> Result<HashFor<R::Config>, SessionError>
Similar to upload
but takes the contract bundle as the first argument.
You can obtain it using ContractBundle::load("some/path/your.contract")
or local_contract_file!()
sourcepub fn call_and<S: AsRef<str> + Debug>(
self,
message: &str,
args: &[S],
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>
) -> Result<Self, SessionError>
pub fn call_and<S: AsRef<str> + Debug>( self, message: &str, args: &[S], endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance> ) -> Result<Self, SessionError>
Calls a contract with a given address. In case of a successful call, returns self
.
sourcepub fn call_with_address_and<S: AsRef<str> + Debug>(
self,
address: AccountIdFor<R::Config>,
message: &str,
args: &[S],
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>
) -> Result<Self, SessionError>
pub fn call_with_address_and<S: AsRef<str> + Debug>( self, address: AccountIdFor<R::Config>, message: &str, args: &[S], endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance> ) -> Result<Self, SessionError>
Calls the last deployed contract. In case of a successful call, returns self
.
sourcepub fn call<S: AsRef<str> + Debug, T: Decode>(
&mut self,
message: &str,
args: &[S],
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>
) -> Result<MessageResult<T>, SessionError>
pub fn call<S: AsRef<str> + Debug, T: Decode>( &mut self, message: &str, args: &[S], endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance> ) -> Result<MessageResult<T>, SessionError>
Calls the last deployed contract. In case of a successful call, returns the encoded result.
sourcepub fn call_with_address<S: AsRef<str> + Debug, T: Decode>(
&mut self,
address: AccountIdFor<R::Config>,
message: &str,
args: &[S],
endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance>
) -> Result<MessageResult<T>, SessionError>
pub fn call_with_address<S: AsRef<str> + Debug, T: Decode>( &mut self, address: AccountIdFor<R::Config>, message: &str, args: &[S], endowment: Option<<<R::Config as Config>::Currency as Inspect<AccountIdFor<R::Config>>>::Balance> ) -> Result<MessageResult<T>, SessionError>
Calls a contract with a given address. In case of a successful call, returns the encoded result.
sourcepub fn set_tracing_extension(&mut self, d: TracingExt)
pub fn set_tracing_extension(&mut self, d: TracingExt)
Set the tracing extension
Trait Implementations§
source§impl<R: Runtime> MockingApi<R> for Session<R>
impl<R: Runtime> MockingApi<R> for Session<R>
source§fn deploy(&mut self, mock: ContractMock) -> AccountIdFor<R::Config>
fn deploy(&mut self, mock: ContractMock) -> AccountIdFor<R::Config>
mock
as a standard contract. Returns the address of the deployed contract.source§fn mock_existing_contract(
&mut self,
_mock: ContractMock,
_address: AccountIdFor<R::Config>
)
fn mock_existing_contract( &mut self, _mock: ContractMock, _address: AccountIdFor<R::Config> )
Auto Trait Implementations§
impl<R> !RefUnwindSafe for Session<R>
impl<R> !Send for Session<R>
impl<R> !Sync for Session<R>
impl<R> Unpin for Session<R>
impl<R> !UnwindSafe for Session<R>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<I> RecreateContext<I> for I
impl<I> RecreateContext<I> for I
§fn recreate_context(_original_input: I, tail: I) -> I
fn recreate_context(_original_input: I, tail: I) -> I
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T
. Read more§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.§impl<T> TryConv for T
impl<T> TryConv for T
§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.