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

Added test for genesis hash #7909

Merged
merged 8 commits into from Oct 27, 2022
Merged

Added test for genesis hash #7909

merged 8 commits into from Oct 27, 2022

Conversation

mm-near
Copy link
Contributor

@mm-near mm-near commented Oct 24, 2022

Added a test to verify that genesis hash doesn't change.

@mm-near mm-near requested a review from a team as a code owner October 24, 2022 11:58
@@ -3199,4 +3201,27 @@ mod test {
let view_state_value = view_state.get(&key).unwrap().unwrap();
assert_eq!(state_value, view_state_value);
}

/// Check that mainnet genesis hash still matches.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe expand this a bit? This assumes that the reader understands why we want that, might make sense to spent a sentence explaining that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment on lines 3210 to 3211
let (tempdir, opener) = near_store::NodeStorage::test_opener();
let store = opener.open().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use in-memory store? Feels like this test shouldn't write to disk.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don’t even need full NodeStorage. near_store::test_utils::create_test_store will give you Store you can pass to runtime constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - done.

let block = Chain::make_genesis_block(&*runtime, &chain_genesis).unwrap();
assert_eq!(
block.header().hash(),
&CryptoHash::from_str("EPnLgE7iEq9s7yTkos96M3cWymH5avBAPm3qx3NXqR8H").unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&CryptoHash::from_str("EPnLgE7iEq9s7yTkos96M3cWymH5avBAPm3qx3NXqR8H").unwrap()
&"EPnLgE7iEq9s7yTkos96M3cWymH5avBAPm3qx3NXqR8H".parse::<CryptoHash>().unwrap()

more idiomatic form, and avoids the import (which I think will trip unused warning in the current code on CI)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, block.header().hash().to_string() and compare with encoded hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

@mina86 mina86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for duplication of the resource file.

@@ -0,0 +1,823 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils/mainnet-res/res/mainnet_genesis.json is what you’re looking for. Available through near_mainnet_res::mainnet_genesis function.

Comment on lines 3210 to 3211
let (tempdir, opener) = near_store::NodeStorage::test_opener();
let store = opener.open().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don’t even need full NodeStorage. near_store::test_utils::create_test_store will give you Store you can pass to runtime constructor.

let block = Chain::make_genesis_block(&*runtime, &chain_genesis).unwrap();
assert_eq!(
block.header().hash(),
&CryptoHash::from_str("EPnLgE7iEq9s7yTkos96M3cWymH5avBAPm3qx3NXqR8H").unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, block.header().hash().to_string() and compare with encoded hash.

@near-bulldozer near-bulldozer bot merged commit 8ebd32d into master Oct 27, 2022
@near-bulldozer near-bulldozer bot deleted the 10_24_genesis_test branch October 27, 2022 11:54
nikurt pushed a commit that referenced this pull request Nov 7, 2022
Added a test to verify that genesis hash doesn't change.
nikurt pushed a commit that referenced this pull request Nov 9, 2022
Added a test to verify that genesis hash doesn't change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants