feat: update portal-spec-tests and refactor reading from test files#1797
Conversation
KolbyML
left a comment
There was a problem hiding this comment.
Most of the PR looks good, I just have questions on the types we already have defined
| /// A common type used in test files. | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct ContentItem<K: OverlayContentKey> { | ||
| pub content_key: K, | ||
| #[serde(rename = "content_value")] | ||
| pub raw_content_value: RawContentValue, | ||
| } | ||
|
|
||
| impl<K: OverlayContentKey> ContentItem<K> { | ||
| pub fn content_value<V: ContentValue<TContentKey = K>>(&self) -> Result<V, ContentValueError> { | ||
| V::decode(&self.content_key, &self.raw_content_value) | ||
| } | ||
| } |
There was a problem hiding this comment.
Isn't this type already defined in crates/utils/src/testing.rs, shouldn't we only define it once?
|
|
||
| /// Reads json file from a "portal-spec-tests" submodule | ||
| pub fn read_json_portal_spec_tests_file<T>(path: impl AsRef<Path>) -> anyhow::Result<T> | ||
| where | ||
| T: DeserializeOwned, | ||
| { | ||
| let reader = BufReader::new(File::open(portal_spec_tests_path(path))?); | ||
| Ok(serde_json::from_reader(reader)?) | ||
| } | ||
|
|
||
| /// Reads yaml file from a "portal-spec-tests" submodule | ||
| pub fn read_yaml_portal_spec_tests_file<T>(path: impl AsRef<Path>) -> anyhow::Result<T> | ||
| where | ||
| T: DeserializeOwned, | ||
| { | ||
| let reader = BufReader::new(File::open(portal_spec_tests_path(path))?); | ||
| Ok(serde_yaml::from_reader(reader)?) | ||
| } | ||
|
|
||
| /// Reads ssz file from a "portal-spec-tests" submodule | ||
| pub fn read_ssz_portal_spec_tests_file<T: Decode>(path: impl AsRef<Path>) -> anyhow::Result<T> { | ||
| let bytes = read_binary_portal_spec_tests_file(&path)?; | ||
| T::from_ssz_bytes(&bytes).map_err(|err| { | ||
| anyhow!( | ||
| "Error decoding ssz file: {}. Error: {err:?}", | ||
| path.as_ref().display() | ||
| ) | ||
| }) |
There was a problem hiding this comment.
Isn't this code already defined in crates/utils/src/submodules.rs shouldn't we only define it once?
KolbyML
left a comment
There was a problem hiding this comment.
looks good. Milos messaged me on discord for context
For context for others, these files and logic is duplicated because we don't want to put it in
|
What was wrong?
We were missing test vectors around fork boundaries. These were added to portal-spec-tests in ethereum/portal-spec-tests#49
How was it fixed?
Updated portal-spec-tests submodule, and simplified/refactored some tests in ehtportal-api crate.
To-Do