Skip to main content
9 votes

How to test cross-contract Ink! contracts

I'm posting a link to the discussion on GitHub: https://github.com/paritytech/ink/issues/1125. AFAIK there is currently only the the possibility to do this with the redspot tool mentioned in the issue....
cmichi's user avatar
  • 2,800
7 votes

Writing a test to call staking.chill() so as to remove Charlie as a Validator

No, the issue here is not related to invulnerables. Invulnerables are only immune to getting slashed when an offence occurs. Instead, the issue here is probably that you need to wait a full session ...
Shawn Tabrizi's user avatar
  • 16.2k
5 votes

How to integration-test a parachain

polkadot-launch is being deprecated in favor of zombienet. You can find some examples on polkadot and cumulus, although some might be depending on Parity internal infrastructure and you won't ...
Bernardo Rodrigues's user avatar
5 votes

How can I configure genesis state for my pallet's tests without hardcoding it?

You can configure the new_test_ext function however you like. In this case, you can make it take the parameters you'll want to use to modify your genesis state and then just pass values into your ...
Sacha Lansky's user avatar
  • 2,650
5 votes
Accepted

Potential storage issue with try-runtime tool

There is no magic involved here. The key of the storage location is Twox128(Prefix::pallet_prefix()) ++ Twox128(Prefix::STORAGE_PREFIX) (explained here) In your case the old storage hash and the new ...
Oliver Tale-Yazdi's user avatar
5 votes
Accepted

construct_runtime_integrity_test failing

Good question! The reason for this is the recent introduction of a new component in the Weight struct; the proof size. This makes it mandatory to slightly adjust your definition of BlockWeights to ...
Oliver Tale-Yazdi's user avatar
5 votes
Accepted

Why is the AccountId of a contract always 1 when unit testing?

Off-chain environment used in the unit testing is just a mock environment so there aren't any dedicated mapping created b/w addresses & contracts. Latter is just an object with some associated ...
Nimish Agrawal's user avatar
4 votes
Accepted

Problem running assert_last_event in tests.rs

I believe the problem here is small and easy to miss. Substrate chains do not emit events when the block number is 0. This is to avoid hundreds or even thousands of events being generated in the ...
Shawn Tabrizi's user avatar
  • 16.2k
4 votes

testing pallet with ensure_root

If this is for tests, have you tried using: RuntimeOrigin::root() Example here: assert_ok!(Balances::set_balance(RuntimeOrigin::root(), 1, 1_000, 0)); https://github.com/paritytech/substrate/blob/...
Bruno's user avatar
  • 8,335
3 votes
Accepted

Testing transaction fee movements

Thanks to @kianenigma and @shawn-tabrizi pointing me in the right direction, I realized that to do what I'm looking for I just need to call pre_dispatch and post_dispatch manually on the call. In ...
K. Lane's user avatar
  • 61
3 votes
Accepted

How can I use `Balances::deposit_creating` in pallet tests?

First of all, deposit_creating is not a function exposed by Balance, but a function from the Currency trait. So, to use it, first thing to do is to use the Balance pallet as the Currency trait in your ...
Nathan's user avatar
  • 454
3 votes
Accepted

How can I access custom pallet Event data in a test?

Here is a working example of a test using the pallet-template from the substrate-node-template: #[test] fn stackexchange_question() { new_test_ext().execute_with(|| { // To emit events, we ...
Shawn Tabrizi's user avatar
  • 16.2k
3 votes

How can I test a parachain against a production relay chain's live state and configuration?

Fork off Relay Chain This script allows bootstrapping a new substrate chain with the current state of a live chain. Using this, you can create a fork of Polkadot, Kusama and other substrate chain for ...
Nuke's user avatar
  • 1,852
3 votes

Stress test a substrated based blockchain

There is sTPS repo contains some functions to spin up a multi-node network and stress-test it. Unfortunately there are some non-deterministic bugs with how we are using Zombienet which does not allow ...
Oliver Tale-Yazdi's user avatar
3 votes
Accepted

Testing Custom RPC with a Mock Runtime API

tldr: used the sp_api::mock_impl_runtime_apis! macro to mock the implementation. Example is in this PR along with a lot of other changes: https://github.com/LibertyDSNP/frequency/pull/490 See pallets/...
Wil W's user avatar
  • 433
3 votes
Accepted

How to use the follow-chain subcommand in try-runtime?

Clone repo: git clone https://github.com/paritytech/substrate cd substrate Run a dev chain locally. This is the chain that I want to "follow": cargo b -r cp target/release/node-template . ./...
Bruno's user avatar
  • 8,335
3 votes
Accepted

How we can do the integration testing of a substrate project?

There are few tool which might be useful, subxt - a library to submit extrinsics to a substrate node via RPC. (from its readme) XCM emulator to test XCM configurations - original location, fork in ...
muharem's user avatar
  • 444
3 votes
Accepted

How to stub ink! contract environment to produce fake values for use in tests?

There is advance_block function in the ink::env::test and you can do something like this: fn advance_n_blocks(n: u32) { for _ in 0..n { advance_block(); } } fn advance_block() { ...
Maario's user avatar
  • 659
3 votes

Testing benchmarks with V2

You can simply use the impl_benchmark_test_suite macro which generates those tests for your benchmarks (detailed explanation).
Daan van der Plas's user avatar
2 votes
Accepted

Client testing - Runtime trait implementation approach

I think you are missing a bound C: ProvideRuntimeApi<B> on your start_module_gadget function.
André's user avatar
  • 2,465
2 votes
Accepted

How to assert deposited event in pallet call?

The FRAME System pallet has two helper functions for this: /// Assert the given `event` exists. #[cfg(any(feature = "std", feature = "runtime-benchmarks", test))] pub fn ...
Shawn Tabrizi's user avatar
  • 16.2k
2 votes
Accepted

What is integrity_test?

The integrity test function is some logic that you can place in your pallet, that will then be executed in the construct_runtime! in your final runtime configuration. Note that this function does not ...
Shawn Tabrizi's user avatar
  • 16.2k
2 votes

Stress test a substrated based blockchain

I have come across this https://socket.dev/npm/package/artillery-engine-substrate but I have not used it yet unfortunately.
Lana I's user avatar
  • 369
2 votes
Accepted

Configure chain parameters (epoch/era/bondig/etc) for dev node?

cargo build --release --features fast-runtime
Ron's user avatar
  • 618
2 votes
Accepted

Transactional macro deprecated but still required

I believe that this is is just an artifact of the original implementation detail of the storage layer, which shows up in tests. This PR: https://github.com/paritytech/substrate/pull/11927 Should solve ...
Shawn Tabrizi's user avatar
  • 16.2k
2 votes
Accepted

Best way to provide mock data for cross-contract calls

Testing cross-contract calls is the biggest missing piece for developer experience in ink! 3.0 right now. There are ways to do it currently, but none of them is ideal. The concept of using feature ...
cmichi's user avatar
  • 2,800
2 votes
Accepted

How to test a pallet that depends on the staking pallet?

You will need to add the Staking Pallet into your mock construct_runtime!: From frame/session/benchmarking/src/mock.rs: frame_support::construct_runtime!( pub enum Test where Block = Block,...
Shawn Tabrizi's user avatar
  • 16.2k
2 votes
Accepted

Stress test a substrated based blockchain

You can benchmark your chain: https://docs.substrate.io/test/benchmark/#benchmarking-tools Take a look at these transfer benchmarks: https://github.com/paritytech/substrate/blob/...
Bruno's user avatar
  • 8,335
2 votes
Accepted

Constructor not found when testing smart contract

A solution to the problem was to not have the tests in a seperate test module. #![cfg_attr(not(feature = "std"), no_std)] #![feature(min_specialization)] #[openbrush::contract] pub mod name ...
rajohs's user avatar
  • 491
2 votes
Accepted

Test hooks weights using dbWeights

You are very close, but the sp_weights is not needed. I think in your case the Rust compiler is just being annoying. You can write it more explicit like this to help the type-interference understand ...
Oliver Tale-Yazdi's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible