-
Notifications
You must be signed in to change notification settings - Fork 346
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
rust runtime integration tests #339
Conversation
|
I see now, the runtime is imported from |
It might be useful to add a test similar to #337 at this level. That would help us know whether the block gas limit problem is in the runtime or RPC layer (I'm guessing runtime, but would be good to confirm). |
cc @JoshOrndorff I'm having trouble simulating the
I guess both problems reduce to figuring out how to call private runtime methods from this integration test context. |
Hmm, that's an interesting point. Here are a few thoughts on how we might proceed. I don't know which if any of them is right.
Although, I admit option #2 is pretty focused on the staking solution and not so much on the authoring...
Even if authoring can be made to work, it might not be the most rewarding place to start. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress towards security! Got a few comments
runtime/tests/integration_test.rs
Outdated
); | ||
} | ||
for x in 2..1201 { | ||
set_alice_as_author(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need to set alice as author if she is the only collator? Maybe set up a test with more than one collator and somehow count how many time each collator was selected as author and test that the balance reward is correct in a dynamic way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An author must be set every block or on_finalize
in author-inherent
panics.
Having multiple collators to test correct reward distribution is already done in parachain-staking
unit tests. I think it's reasonable to add the same test here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joelamouche This is a good chance to learn about Substrate inherents. When a collator authors a block, they have the opportunity to include inherent extrinsics. In moonbeam there are three of them (timestamp, validation_data, and author) and all three are required. It is behind-the-scenes from a user perspective, but every time a collator authors a moonbeam block, they insert these three inherents. Since Amar is mocking here, and there is no collator process to do any actual block authoring, we have to call these inherents manually. So setting the author to Alice here is mocking Alice authoring the block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe set up a test with more than one collator and somehow count how many time each collator was selected as author and test that the balance reward is correct in a dynamic way
I'd rather do this at the pallet level (and have done it there) where I can mock the set_author
command more easily.
I added Charlie, Dave, and Eve to the set of collators in this test and none of them were included in the set of valid block authors so it kept returning the following error:
---- reward_block_authors stdout ----
thread 'reward_block_authors' panicked at 'Expected Ok(_). Got Err(
DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: None,
pays_fee: Pays::Yes,
},
error: DispatchError::Module {
index: 17,
error: 1,
message: Some(
"CannotBeAuthor",
),
},
},
)', runtime/tests/integration_test.rs:337:17
Testing multiple block authors in a runtime integration test is worthwhile, but I'd prefer for it to be pursued in a follow up...
This feels ready to merge. I'll do it once someone approves :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me. Every time I read it, it inspires more ideas of tests to add. I think they should be added in followups though. This PR shows that the method works and adds 3 good tests already.
What does it do?
Adds integration tests for complete Moonbeam runtime.
This will be useful for testing #311 from the runtime context.
What important points reviewers should know?
Is there something left for follow-up PRs?
What alternative implementations were considered?
Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?
What value does it bring to the blockchain users?
Checklist