Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease implementation of mock for pallets. #299

Open
gui1117 opened this issue Oct 30, 2021 · 5 comments
Open

Ease implementation of mock for pallets. #299

gui1117 opened this issue Oct 30, 2021 · 5 comments
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. C2-good-first-issue A task for a first time contributor to become familiar with the Polkadot-SDK. T1-FRAME This PR/Issue is related to core FRAME, the framework.

Comments

@gui1117
Copy link
Contributor

gui1117 commented Oct 30, 2021

Currently there is very few provided function for doing some mocking of pallets.

People almost always implement some function like:

fn run_to_block(n: u32) {
	assert!(System::block_number() < n);
	while System::block_number() < n {
		let block_number = System::block_number();
		AllPalletsWithSystem::on_finalize(block_number);
		System::set_block_number(block_number + 1);
		maybe_new_session(block_number + 1);
		AllPalletsWithSystem::on_initialize(block_number + 1);
	}
}

Those function are sometime incomplete implementation of state transition.

I think maybe we can make use of frame_executive::Executive in tests, or provide some helper to avoid having to implement those function everywhere.

@juangirini juangirini transferred this issue from paritytech/substrate Aug 24, 2023
@the-right-joyce the-right-joyce added T1-FRAME This PR/Issue is related to core FRAME, the framework. and removed T1-runtime labels Aug 25, 2023
helin6 pushed a commit to boolnetwork/polkadot-sdk that referenced this issue Feb 5, 2024
jonathanudd pushed a commit to jonathanudd/polkadot-sdk that referenced this issue Apr 10, 2024
* initial commit of DummyOrdered (aka message-lane) pallet

* API for relay

* cargo fmt --all

* some clippy + no_std

* more clippy + no_std

* inbound lane tests

* outbound lane tests

* cargo fmt --all

* prune old messages whenever outbound lane is updated

* do not care about MessageNonce overflow

* cargo fmt --all

* update crate docs

* MaxHeadersToPruneAtOnce -> MaxMessagesToPruneAtOnce

* MessageAction -> MessageResult

* cargo fmt --all

* fire MessageAccepted + MessagesDelivered

* confirm message processing

* cargo fmt --all

* clippy

* cargo fmt again

* Update modules/message-lane/src/lib.rs

Co-authored-by: Hernando Castano <[email protected]>

* Update modules/message-lane/src/lib.rs

Co-authored-by: Hernando Castano <[email protected]>

* use crate::*

* cargo fmt --all

* Storage -> S

* Update modules/message-lane/src/outbound_lane.rs

Co-authored-by: Hernando Castano <[email protected]>

* add method doc

* Update modules/message-lane/src/inbound_lane.rs

Co-authored-by: Hernando Castano <[email protected]>

* added detailed module docs

* Update modules/message-lane/src/lib.rs

Co-authored-by: Tomasz Drwięga <[email protected]>

* updated OnMessageReceived docs

* prune only when new message is sent

* removed #![warn(missing_docs)]

* fixed merge with overlapped PR

Co-authored-by: Hernando Castano <[email protected]>
Co-authored-by: Tomasz Drwięga <[email protected]>
@kianenigma kianenigma added C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. C2-good-first-issue A task for a first time contributor to become familiar with the Polkadot-SDK. labels Oct 18, 2024
@AurevoirXavier
Copy link
Contributor

AurevoirXavier commented Oct 30, 2024

Indeed, we need this. There are too many such duplicated code.

@kianenigma Could you draft a simple "task list"? Where could be the best entry point to "inject" such run_to_block logic?

I'd love to take this issue.

@kianenigma
Copy link
Contributor

Option1: we can alter construct_runtime and/or the new version #[runtime] to spit out this function for you.
Option2: Have this function in frame_system/frame_executive with a #[cfg(feature = "std")] and it takes in things like AllPalletsWithSystem as generic argument.

Second is much better as it does not involve magically generated code.

@Krayt78
Copy link
Contributor

Krayt78 commented Dec 8, 2024

@AurevoirXavier Are you working on it or can i try this one ? ^^

@AurevoirXavier
Copy link
Contributor

@AurevoirXavier Are you working on it or can i try this one ? ^^

Aha, too many GitHub notifications..
I forgot this one.

Thank you for bringing it up!
I did some work a month ago, could you try other issues? :)

@Krayt78
Copy link
Contributor

Krayt78 commented Dec 8, 2024

@AurevoirXavier Are you working on it or can i try this one ? ^^

Aha, too many GitHub notifications.. I forgot this one.

Thank you for bringing it up! I did some work a month ago, could you try other issues? :)

yeah no problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. C2-good-first-issue A task for a first time contributor to become familiar with the Polkadot-SDK. T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
Status: Backlog
Development

No branches or pull requests

6 participants