Skip to main content

Questions tagged [unit-tests]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

Not able to get randomness on unit test

I'm building a pallet that requires some randomness to simulate the act of tossing a coin. That's why I'm following the same implementation as provided on the Lottery pallet. Particularly, the ...
nhussein11's user avatar
0 votes
1 answer
21 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
24 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?...
go11li's user avatar
  • 1,241
2 votes
1 answer
230 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
22 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
99 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
50 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,346
5 votes
1 answer
61 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
34 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
46 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
846 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,757
1 vote
1 answer
82 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
73 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
  • 903
0 votes
1 answer
42 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
  • 543
2 votes
2 answers
138 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
36 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
  • 2,021
0 votes
1 answer
153 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 - R0GUE's user avatar
2 votes
1 answer
117 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
54 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
110 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
435 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
106 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
63 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