#Unit testing with external contracts in Rust (local-testing mode) with `rlib` removed?

11 messages · Page 1 of 1 (latest)

willow rover
#

It doesn't appear unit testing with external contracts in rust (no wasm) without the rlib library is functional. (removed here: https://github.com/stellar/soroban-examples/commit/3f0388bc2b079f28223e5d6443811e61e26af0c7).

Use case was some basic unit testing for some functions that relied on an external contract. (I can get this to work by deploying the WASM version of the external contract)

Curious if this is an intentional change? Or if the rlib crate-type is safe to add back for this use case?

#

Unit with testing external contracts in Rust (local-testing mode) with rlib removed?

#

Unit testing with external contracts in Rust (local-testing mode) with rlib removed?

willow rover
#

Aside: how difficult would it be to allow a test to write to contract storage through the env? Currently, the test cannot call env.data().set... because the host throws with Status(HostContextError(NoContractRunning)) (which makes sense, given there is no contract running and no contract_id can be passed to the env to provide context)

vast flame
#

re test storage: there is an open issue regarding this, so it should eventually work they way you want

glossy zenith
#

To set contract data inside a test, use this:

#
env.as_contract(&contract_id, || {
    // sweet sweet code
})
#

Why this is required: Contract data is keyed against the currently executing contract, so the Env needs to know which contract you're wanting to set contract data for. Many host functions have similar requirement where they need to know what contract they're executing in. The as_contract fn only works in tests.

vast flame
#

ah, neat, didn't know we already have this

glossy zenith