Type Definition concordium_std::test_infrastructure::InitContextTest [−][src]
type InitContextTest<'a> = ContextTest<'a, InitOnlyDataTest>;
Expand description
Placeholder for the initial 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 has a setter function prefixed with set_
.
Example
Creating an empty context and setting the init_origin
.
let mut ctx = InitContextTest::empty(); ctx.set_init_origin(AccountAddress([0u8; 32]));
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 = InitContextTest::empty(); ctx.set_metadata_slot_time(1609459200);
or
let mut ctx = InitContextTest::empty(); ctx.metadata_mut().set_slot_time(1609459200);
Use case example
#[init(contract = "noop")] fn contract_init<I: HasInitContext, L: HasLogger>( ctx: &I, _amount: Amount, _logger: &mut L, ) -> InitResult<()> { let init_origin = ctx.init_origin(); let parameter: SomeParameterType = ctx.parameter_cursor().get()?; Ok(()) } #[cfg(test)] mod tests { use super::*; use concordium_sc_base::test_infrastructure::*; #[test] fn test() { let mut ctx = InitContextTest::empty(); ctx.set_init_origin(AccountAddress([0u8; 32])); ... let result = contract_init(&ctx, 0, &mut logger); // Reads the init_origin without any problems. // But then fails because the parameter is not set. } }
Implementations
impl<'a> InitContextTest<'a>
[src]
impl<'a> InitContextTest<'a>
[src]pub fn empty() -> Self
[src]
pub fn empty() -> Self
[src]Create an InitContextTest
where every field is unset, and getting any
of the fields will result in fail!
.
pub fn set_init_origin(&mut self, value: AccountAddress) -> &mut Self
[src]
pub fn set_init_origin(&mut self, value: AccountAddress) -> &mut Self
[src]Set init_origin
in the InitContextTest
Trait Implementations
impl<'a> HasInitContext<()> for InitContextTest<'a>
[src]
impl<'a> HasInitContext<()> for InitContextTest<'a>
[src]fn init_origin(&self) -> AccountAddress
[src]
fn init_origin(&self) -> AccountAddress
[src]Who invoked this init call.