Skip to main content

TestEnvironmentBuilder

Struct TestEnvironmentBuilder 

Source
pub struct TestEnvironmentBuilder { /* private fields */ }
Expand description

Builder for a TestEnvironment that needs something other than the stock chain settings.

The plain constructors (TestEnvironment::new, no_cost, and the rest) cover the ordinary case and are unaffected by this type. Reach for the builder when a test wants to drive contract behavior that a network config parameter governs – what a contract does as it approaches a cap the chain sets, which is otherwise only observable on a chain configured that way:

use thruput_native_exec::test_environment::TestEnvironment;

let env = TestEnvironment::builder()
    .no_cost()
    .with_max_sha256_buffers(2)
    .build();

Every setter is optional and independent; an unset one keeps what TestEnvironment::new would have used, and unstated config parameters keep their stock values (see stock_network_config). A builder with no configuration overrides at all creates its database exactly as the plain constructors do. A parameter setter needs a hogd build that knows the parameter; see NetworkConfigBuilder.

Implementations§

Source§

impl TestEnvironmentBuilder

Source

pub fn new() -> Self

A builder that would produce exactly TestEnvironment::new(None).

Source

pub fn with_cost_model(self, cost_model: StorageCostModel) -> Self

Charge storage against cost_model instead of the chain default.

Source

pub fn no_cost(self) -> Self

Make every storage operation free, as TestEnvironment::no_cost does.

Source

pub fn with_network_hash(self, network_hash: NetworkHash) -> Self

Run on network_hash instead of test_network_hash.

The network hash is part of every transaction signature preimage, so pin it when a test’s signatures were produced for a specific network.

Source

pub fn with_genesis_root_contract(self, contract: Contract) -> Self

Install contract as the genesis root deployment instead of mock_genesis_root_contract.

Source

pub fn with_network_config(self, config: NetworkConfig) -> Self

Apply the parameter setters below to config rather than to the stock configuration.

This is the whole-configuration escape hatch: pass one read back off another environment, or one built by hand. Anything the setters do not restate is taken from it verbatim.

Source

pub fn with_config_param(self, param: ConfigParam) -> Self

State one config parameter the typed setters below do not cover.

Source

pub fn with_max_sha256_buffers(self, max_sha256_buffers: u32) -> Self

Concurrently open incremental SHA-256 buffers permitted per invocation frame (the cap thruput_sdk::Hasher allocates against).

Source

pub fn with_max_cross_invoke_depth(self, max_cross_invoke_depth: u32) -> Self

Invocation frames one transaction may have open at once.

The harness opens its frames directly, so one the executor refuses is an unrecoverable panic rather than the error a contract would observe. To assert on the cap, have the frame call through the Invoke syscall (thruput_sdk::call::try_call_raw_with), which reports it as RawCallError::DepthExceeded.

Source

pub fn with_max_new_contracts_per_tx( self, max_new_contracts_per_tx: u32, ) -> Self

Contracts one transaction may attach in contracts_to_deploy.

Source

pub fn with_max_bytestring_len(self, max_bytestring_len: u32) -> Self

Bytes one bytestring storage item may hold.

Source

pub fn with_max_contract_size_bytes(self, max_contract_size_bytes: u32) -> Self

Bytes one attached contract’s code blob (ContractBlob.data) may hold, checked before any attached contract is verified or executed.

Source

pub fn with_max_savepoint_depth(self, max_savepoint_depth: u32) -> Self

Storage savepoints one transaction may have open at once: one per TryInvoke frame still executing, plus the one the root commit takes.

Source

pub fn with_max_sha256_buffer_bytes(self, max_sha256_buffer_bytes: u32) -> Self

Bytes one incremental SHA-256 buffer may absorb between resets, the per-buffer companion of with_max_sha256_buffers.

Source

pub fn with_max_auth_token_depth(self, max_auth_token_depth: u32) -> Self

Levels of AuthTokenNode nesting an auth token may carry, counted from its root.

Source

pub fn with_max_rv32_code_bytes(self, max_rv32_code_bytes: u32) -> Self

Bytes of code (code_size in the artifact header) an RV32 artifact may carry to be attached as a contract.

Source

pub fn with_max_rv32_memory_bytes(self, max_rv32_memory_bytes: u32) -> Self

Bytes of guest data memory (memory_bytes in the artifact header) an RV32 artifact may declare to be attached as a contract.

Source

pub fn build(self) -> TestEnvironmentHandle

Create the configured environment.

Trait Implementations§

Source§

impl Default for TestEnvironmentBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> StaticIfNoAlloc for T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.