Questions tagged [unit-tests]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
15 views

Creation of account ids

A brief context: I want to deliver the test. The exact context: Creation of account_id's (first point in an outline). Question: Do I correctly create account_id in the context of my task. Should I ...
Tomasz Waszczyk's user avatar
0 votes
1 answer
17 views

Writing Test in ink! smart contract

I have two contract nft_contract and staking_contract. I want to write test for staking_contract but while staking I need to mint nft and approve, then only I can use it to stake. How can this be done?...
Ganesh11's user avatar
  • 1,208
2 votes
1 answer
206 views

Writing Unit Tests

I have two ink! contracts, one being a simple staking contract, and the other being an ERC20. Now, I can write unit tests for ERC20 simply in the contract file itself but to write unit tests for my ...
ProgrammerForFun's user avatar
0 votes
0 answers
14 views

Unit testing an extrinsic submitted by an Offchain Worker?

As far as I could understand so far there is no a "normal" way to test extrinsics submitted by an Offchain Worker, rather a substitute transaction pool is involved. However it is possible to ...
Yury Yukhananov's user avatar
3 votes
0 answers
70 views

sending an http request in unit tests?

I'm trying to arrange some unit tests for a local http server connectivity my node communicates with. While the node has no troubles while sending requests, I face difficulties trying to build basic ...
Yury Yukhananov's user avatar
4 votes
1 answer
43 views

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

In an ink! contract I need to use Self.env().block_number() to get the current block number to compare it with a block_number_guessed value that I provide when instantiating the contract and check ...
Luke Schoen's user avatar
  • 2,292
5 votes
1 answer
55 views

No callee has been set

I write some test for ink! smart contract, my code has these three lines: // Set the contract as callee and Bob as caller. let _contract = ink_env::account_id::<ink_env::DefaultEnvironment&...
Tomasz Waszczyk's user avatar
5 votes
1 answer
30 views

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

I want to write tests and found the question that potentially soles my problem, but made exactly all what is recommended but still have the same issue. I have added on top of my module with tests ...
Tomasz Waszczyk's user avatar
3 votes
1 answer
41 views

No caller has been set

I write tests for my smart contract and got this error: no caller has been set The error comes from: ink_engine-4.2.0/src/ext.rs:325:14. In function that I want to write tests I have following line: ...
Tomasz Waszczyk's user avatar
1 vote
1 answer
629 views

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

For my pallet I have defined a StorageMap in the storage that stores a tuple. #[pallet::storage] pub(super) type NameOf<T: Config> = StorageMap<_, Twox64Concat, T::AccountId, (Nickname<...
Alex Bean's user avatar
  • 5,364
1 vote
1 answer
70 views

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

Currently, in the ink test environment (ink_env::test), the default block time is 6 (see https://github.com/paritytech/ink/blame/50b32f4e49d4072f3d28009eb517475b68bec56b/crates/engine/src/ext.rs#L147) ...
Cromm's user avatar
  • 321
0 votes
1 answer
64 views

How do I create Hash in tests?

I have a function that creates hash from AccountId's. #[pallet::call_index(2)] #[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())] pub fn connection_request(origin: OriginFor<T>, ...
Burak's user avatar
  • 893
0 votes
1 answer
32 views

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

I would like to avoid the most pallet config initialisation and just want to use the actual runtime configuration for the (unit) tests. This would simplify my mock process a lot. The only thing that ...
Chralt's user avatar
  • 503
2 votes
2 answers
112 views

Polkadot - tests fail out-of-the-box

How can I make the tests pass? Steps to reproduce: git clone https://github.com/paritytech/polkadot cd polkadot cargo build cargo test $ cargo test ⚡ Found 3 strongly connected components which ...
amab8901's user avatar
1 vote
1 answer
33 views

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

I have added the vesting schedule/config to the and passed it to config of vesting pallet in chainspec.rs Can we test the vesting schedule/configs by unit test cases? if yes can you provide any sample
Pankaj's user avatar
  • 1,896
0 votes
1 answer
146 views

Best way to provide mock data for cross-contract calls

This question is more about best practices, and if there is a better method for providing mock data for off-chain ink! tests. The goal is to use mock data for off-chain unit testing for ink! contracts....
Peter White's user avatar
2 votes
1 answer
100 views

How to write unit tests for offchain workers?

Pallets can have unit tests with a mock runtime where extrinsics are tested against multiple cases. However it's not obvious how to do the same for offchain workers. How can I write unit tests for ...
Bernardo Rodrigues's user avatar
1 vote
1 answer
48 views

Error facing while mocking runtime for unit testing

Here is the error I am seeing: type mismatch resolving <sp_core::sr25519::Public as IdentifyAccount>::AccountId == u64 --> pallets/src/mock.rs:76:2 | 76 | type Public = <Signature as ...
Immanuel John's user avatar
3 votes
1 answer
100 views

Mocking Polkadot requests in Jest

I'm building out some local unit tests and am trying to figure out how to mock Polkadot requests/responses. I'm trying to get mock-socket working, wondering if there is any documentation on using this ...
Michael Ramuta's user avatar
6 votes
1 answer
347 views

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

From what I understand from the docs, every contract gets its own AccountId. But in the contract-transfer tests, I'm getting the same AccountId from both accounts.alice and contract_id(). I modified ...
Kanishka's user avatar
  • 465
2 votes
1 answer
85 views

How to use pallet_timestamp on tests with function run_to_block?

I'm trying to use pallet_timestamp on function run_to_block when testing PalletA. Here is my code pub fn run_to_block(n: u64) { while System::block_number() < n { if System::...
Stefan Muto's user avatar
2 votes
1 answer
59 views

How do you test offchain_index::set?

I have code that writes to offchain_index: offchain_index::set(&my_key, &my_data.encode()); However, my unit tests are unable to retrieve the data via: let my_offchain_data = StorageValueRef::...
Jeremy Frank's user avatar