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

Block number inconsistency between bench tests and runs #383

Open
ggwpez opened this issue Oct 24, 2022 · 1 comment
Open

Block number inconsistency between bench tests and runs #383

ggwpez opened this issue Oct 24, 2022 · 1 comment
Labels
I4-refactor Code needs refactoring.

Comments

@ggwpez
Copy link
Member

ggwpez commented Oct 24, 2022

In benchmark-tests and runs the block number is set implicitly to 1 after the setup if it was 0.
This is confusing since normally the user must set it manually in the TestExternalties.
Could be changed to either:

  • Never touch the block-number and let the user deal with it - same as in tests
  • Always set the block-number to one before the setup

Two benchmark tests to demonstrate the current behaviour:

block_jumps_to_one {
        // Starts at block 0.
	assert_eq!(frame_system::Pallet::<T>::block_number(), 0u32.into());
}: {
        // Why does it jump to one?
	assert_eq!(frame_system::Pallet::<T>::block_number(), 1u32.into());
}

block_does_not_jump_back {
        // Jump to block 2.
	frame_system::Pallet::<T>::set_block_number(2u32.into());
}: {
        // Why does it NOT jump back to one?
	assert_eq!(frame_system::Pallet::<T>::block_number(), 2u32.into());
}

Came up again here https://substrate.stackexchange.com/questions/5516

@juangirini juangirini transferred this issue from paritytech/substrate Aug 24, 2023
@the-right-joyce the-right-joyce added I4-refactor Code needs refactoring. and removed I7-refactor labels Aug 25, 2023
@bragov4ik
Copy link

+1, I was surprised when exactly the same code behave differently in benchmarks and tests 😢

serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
jonathanudd pushed a commit to jonathanudd/polkadot-sdk that referenced this issue Apr 10, 2024
* split payloads (inbound/outbound/opaque/dispatch) + fees (inbound/outbound)

* added tests

Co-authored-by: Hernando Castano <castano.ha@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I4-refactor Code needs refactoring.
Projects
Development

No branches or pull requests

3 participants