Skip to main content
8 votes
Accepted

How to get an ink! contract's AccountId in unit tests?

The testing Engine is still limited in some capabilities: It is correct that a Smart Contract obtains its own AccountId, but I doubt that this is currently reflected by the testing Engine, since it ...
Achim's user avatar
  • 575
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
Accepted

Error in asset_eq! - binary operation `==` cannot be applied to type

The code will try to apply the PartialEq derive to the config trait T as well, which does not make sense. You can derive PartialEqNoBound instead.
Oliver Tale-Yazdi's user avatar
3 votes

How to use pallet_timestamp on tests with function run_to_block?

Found solution dealing with pallet_timestamp on unittest: pub fn run_to_block(n: u64) { while System::block_number() < n { if System::block_number() > 1 { PalletA::...
Stefan Muto's user avatar
3 votes
Accepted

Error facing while mocking runtime for unit testing

It seems you have a type mis-configuration here. As the compiler is hinting at you, in one place, you have said that the AccountId type should be u64, whereas somewhere else, you are using a more ...
Shawn Tabrizi's user avatar
  • 16.1k
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 write unit tests for offchain workers?

You need something like this to register the offchain ext. It's a really good example. Check the whole tests.rs.
AurevoirXavier's user avatar
  • 10.6k
2 votes

Polkadot - tests fail out-of-the-box

https://github.com/paritytech/polkadot/pull/6376 should fix this. Sorry for the inconvenience. In the meantime to make it pass you can use the same command that the CI uses: cargo test --workspace --...
Oliver Tale-Yazdi's user avatar
2 votes
Accepted

Is it possible to override ink_env::test default block time?

We just published ink! 4.1. It allows for this feature now. The feature was actually added by the very own original poster :-). So I hope he accepts this as a solution! let new_block_timestamp: u64 = ...
cmichi's user avatar
  • 2,800
2 votes
Accepted

Writing Unit Tests

The scenario you are described can not be covered by an unit test. Unit tests are intended for testing one piece (unit, class) of code, e.g. single smart contract. If you want to test interaction ...
Bobo K.'s user avatar
  • 386
2 votes
Accepted

The package `` depends on `ink_env`, with features: `ink-experimental-engine` but `ink_env` does not have these features

The experimental engine doesn't exist anymore. Its just part of ink now so you don't need to add this macro. This happened around March 2022.
forgetso's user avatar
  • 1,514
1 vote

Creation of account ids

Here are a few examples. You can find the examples here: https://github.com/darwinia-network/darwinia/blob/b2e1c5bb89a6ab9486fc3c42b0da4f7f064ec1e5/pallet/account-migration/src/tests.rs#L94 Regarding ...
AurevoirXavier's user avatar
  • 10.6k
1 vote
Accepted

No callee has been set

I think that this is not ideal solution, but working. let _accounts = ink_env::test::default_accounts::<ink_env::DefaultEnvironment>(); let contract_addr: AccountId = AccountId::from([0xFF as u8;...
Tomasz Waszczyk's user avatar
1 vote

How do I create Hash in tests?

Then length of an encoded AccountId seems to be shorter than a Hash. The decoding therefore fails, since "Not enough data to fill buffer" for that hash. What is the reason I get this error ...
Oliver Tale-Yazdi's user avatar
1 vote

How is it possible to avoid a mock runtime and use the actual runtime for testing?

It is important to have the mock.rs inside the runtime folder. Then you can just import all runtime parameters with use crate::*; inside the mock.rs. Just found out that I can just use Runtime instead ...
Chralt's user avatar
  • 543
1 vote
Accepted

How we can test the vesting config given to chainspec.rs by unit testing?

Actually, I think you are testing the Substrate framework. (maybe you want it more security) Otherwise, testing the data which was passed to the vesting genesis configuration is enough.
AurevoirXavier's user avatar
  • 10.6k
1 vote

Mocking Polkadot requests in Jest

There is not any documentation that I am aware of that specifically combines mock-socket and polkadot-js-api. Similar mocking of requests and responses has been implemented in a few other places: ...
Shawn Tabrizi's user avatar
  • 16.1k
1 vote
Accepted

How do you test offchain_index::set?

You can do it the following way: let mut ext = sp_io::TestExternalities::new_empty(); ext.execute_with(|| { sp_io::offchain_index::set(b"hello", b"world"); }); ...
bkchr's user avatar
  • 11.5k

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