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
Conversation
nearcore/src/runtime/mod.rs
Outdated
@@ -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. |
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 expand this a bit? This assumes that the reader understands why we want that, might make sense to spent a sentence explaining that.
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.
done.
nearcore/src/runtime/mod.rs
Outdated
let (tempdir, opener) = near_store::NodeStorage::test_opener(); | ||
let store = opener.open().unwrap(); |
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.
Can we use in-memory store? Feels like this test shouldn't write to disk.
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.
You don’t even need full NodeStorage. near_store::test_utils::create_test_store
will give you Store you can pass to runtime constructor.
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.
thanks - done.
nearcore/src/runtime/mod.rs
Outdated
let block = Chain::make_genesis_block(&*runtime, &chain_genesis).unwrap(); | ||
assert_eq!( | ||
block.header().hash(), | ||
&CryptoHash::from_str("EPnLgE7iEq9s7yTkos96M3cWymH5avBAPm3qx3NXqR8H").unwrap() |
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.
&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)
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.
Alternatively, block.header().hash().to_string()
and compare with encoded hash.
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.
done.
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.
LGTM except for duplication of the resource file.
nearcore/res/mainnet_genesis.json
Outdated
@@ -0,0 +1,823 @@ | |||
{ |
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.
utils/mainnet-res/res/mainnet_genesis.json
is what you’re looking for. Available through near_mainnet_res::mainnet_genesis
function.
nearcore/src/runtime/mod.rs
Outdated
let (tempdir, opener) = near_store::NodeStorage::test_opener(); | ||
let store = opener.open().unwrap(); |
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.
You don’t even need full NodeStorage. near_store::test_utils::create_test_store
will give you Store you can pass to runtime constructor.
nearcore/src/runtime/mod.rs
Outdated
let block = Chain::make_genesis_block(&*runtime, &chain_genesis).unwrap(); | ||
assert_eq!( | ||
block.header().hash(), | ||
&CryptoHash::from_str("EPnLgE7iEq9s7yTkos96M3cWymH5avBAPm3qx3NXqR8H").unwrap() |
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.
Alternatively, block.header().hash().to_string()
and compare with encoded hash.
Added a test to verify that genesis hash doesn't change.
Added a test to verify that genesis hash doesn't change.
Added a test to verify that genesis hash doesn't change.