Type Definition concordium_std::test_infrastructure::ReceiveContextTest [−][src]
type ReceiveContextTest<'a> = ContextTest<'a, ReceiveOnlyDataTest>;
Expand description
Placeholder for the receiving context. All the fields can be set optionally
and the getting an unset field will result in calling
fail!
. Use only in tests!
Setters
Every field have a setter function prefixed with set_
.
Example
Creating an empty context and setting the init_origin
.
let owner = AccountAddress([0u8; 32]); let mut ctx = ReceiveContextTest::empty(); ctx.set_owner(owner); ctx.set_sender(Address::Account(owner));
Set chain meta data
Chain meta data is set using setters on the context or by setters on a
mutable reference of ChainMetaTest
.
Example
Creating an empty context and setting the slot_time
metadata.
let mut ctx = ReceiveContextTest::empty(); ctx.set_metadata_slot_time(1609459200);
or
let mut ctx = ReceiveContextTest::empty(); ctx.metadata_mut().set_slot_time(1609459200);
Use case example
Creating a context for running unit tests
#[receive(contract = "mycontract", name = "receive")] fn contract_receive<R: HasReceiveContext, L: HasLogger, A: HasActions>( ctx: &R, amount: Amount, logger: &mut L, state: &mut State, ) -> ReceiveResult<A> { ensure!(ctx.sender().matches_account(&ctx.owner()), "Only the owner can increment."); Ok(A::accept()) } #[cfg(test)] mod tests { use super::*; use concordium_sc_base::test_infrastructure::*; #[test] fn test() { let owner = AccountAddress([0u8; 32]); let mut ctx = ReceiveContextTest::empty(); ctx.set_owner(owner); ctx.set_sender(Address::Account(owner)); ... let result: ReceiveResult<ActionsTree> = contract_receive(&ctx, 0, &mut logger, state); } }
Implementations
impl<'a> ReceiveContextTest<'a>
[src]
impl<'a> ReceiveContextTest<'a>
[src]pub fn empty() -> Self
[src]
pub fn empty() -> Self
[src]Create a ReceiveContextTest
where every field is unset, and getting
any of the fields will result in fail!
.
pub fn set_invoker(&mut self, value: AccountAddress) -> &mut Self
[src]
pub fn set_self_address(&mut self, value: ContractAddress) -> &mut Self
[src]
pub fn set_self_balance(&mut self, value: Amount) -> &mut Self
[src]
pub fn set_sender(&mut self, value: Address) -> &mut Self
[src]
pub fn set_owner(&mut self, value: AccountAddress) -> &mut Self
[src]
Trait Implementations
impl<'a> HasReceiveContext<()> for ReceiveContextTest<'a>
[src]
impl<'a> HasReceiveContext<()> for ReceiveContextTest<'a>
[src]type ReceiveData = ()
fn open(_data: Self::ReceiveData) -> Self
[src]
fn open(_data: Self::ReceiveData) -> Self
[src]Open the receive context for reading and accessing values.
fn invoker(&self) -> AccountAddress
[src]
fn invoker(&self) -> AccountAddress
[src]Who is the account that initiated the top-level transaction this invocation is a part of. Read more
fn self_address(&self) -> ContractAddress
[src]
fn self_address(&self) -> ContractAddress
[src]The address of the contract being invoked.
fn self_balance(&self) -> Amount
[src]
fn self_balance(&self) -> Amount
[src]Balance on the contract before the call was made.
fn sender(&self) -> Address
[src]
fn sender(&self) -> Address
[src]The immediate sender of the message. In general different from the invoker. Read more
fn owner(&self) -> AccountAddress
[src]
fn owner(&self) -> AccountAddress
[src]Account which created the contract instance.