Open ltfschoen opened 4 years ago
Help from Jam on Substrate Builders Program:
you don't have access to std::env in wasm, so you probably need to additionally put those tests behind a feature flag - or otherwise find alternatives to do what you do in your env module.
This issue isn't necessary to resolve, I'm just trying to get something to work as part of my integration test in this branch "luke/DHX-114/unable-mock-unique-id".
The test calls the
create
extrinsic function of the roaming-agreement-policy runtime module in order to create a roaming agreement policy. The extrinsic function assigns a random value to theRoamingAgreementPolicy
struct by using therandom_value
function and returns that struct or an error, as shown here: https://github.com/DataHighway-com/node/compare/luke/DHX-114/unable-mock-unique-id?expand=1#diff-f700a0b0e1a64f5c0bce4eade50947b2R247In the test, I don't care if it's a random value, I just want to know that it was created, which I could do by checking that the count of roaming agreement policies increased from 0 to 1 (as done here https://github.com/DataHighway-com/node/compare/luke/DHX-114/unable-mock-unique-id?expand=1#diff-f700a0b0e1a64f5c0bce4eade50947b2R257)
But I would also like to know how to conditionally run something different in the extrinsic function (i.e. assign a non-unique value instead of a random value), but only when i'm running tests, which I've tried to do here
To find out whether the extrinsic function is being called by a test, I'm using my custom env package to check the value of the
RUST_ENV
variable. If I callenv::config::get_env()
it will return"TEST"
if the function has been called when usingcargo test
.But when I try to run the tests with the changes in this branch, I get the following error:
Someone else encountered a similar error message on their Substrate-based codebase here https://github.com/paritytech/substrate/issues/2971, but I'm not sure if it's related.
To replicate the issue, clone this branch, then update Rust, and build and just test the integration tests as follows: