DataHighway-DHX / node

DataHighway Node. A blockchain being built with Substrate to become a parachain on the Polkadot network. Planned features include a decentralized LPWAN roaming hub for LoRaWAN IoT devices and network operator roaming agreements, participative mining, an inter-chain data market, and DAO governance. http://www.datahighway.com
http://www.datahighway.com
GNU General Public License v3.0
51 stars 10 forks source link

Duplicate lang item errors upon importing custom env module into custom runtime module #1

Open ltfschoen opened 4 years ago

ltfschoen commented 4 years ago

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 the RoamingAgreementPolicy struct by using the random_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-f700a0b0e1a64f5c0bce4eade50947b2R247

In 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 call env::config::get_env() it will return "TEST" if the function has been called when using cargo test.

But when I try to run the tests with the changes in this branch, I get the following error:

error: duplicate lang item in crate `std` (which `env` depends on): `panic_impl`.
  |
  = note: first defined in crate `sr_io` (which `roaming_agreement_policies` depends on)

error: duplicate lang item in crate `std` (which `env` depends on): `oom`.
  |
  = note: first defined in crate `sr_io` (which `roaming_agreement_policies` depends on)

error: aborting due to 2 previous errors

error: could not compile `roaming-agreement-policies`.

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:

git clone https://github.com/DataHighway-com/node && \
cd node && \
curl https://getsubstrate.io -sSf | bash -s -- --fast && \
./scripts/init.sh && \
cargo build --release && \
cargo test -p node-runtime
ltfschoen commented 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.