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

chore: add portal-spec-tests repo as submodule #1131

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ commands:
key: sccache-cache-stable-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ epoch }}
paths:
- "~/.cache/sccache"
checkout-submodules:
steps:
- run:
name: Checkout submodules
command: |
git submodule sync
git submodule update --init
install-depends:
steps:
- run:
Expand Down Expand Up @@ -210,6 +217,7 @@ jobs:
RUST_LOG: "debug"
steps:
- checkout
- checkout-submodules
- install-depends
- setup-and-restore-sccache-cache
- run:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "portal-spec-tests"]
path = portal-spec-tests
url = https://github.com/ethereum/portal-spec-tests
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Trin currently only runs on Unix-based platforms (Linux, macOS). We plan to even

Check out the [Trin book](https://ethereum.github.io/trin) to quickly get up and running with Trin.

> **NOTE**: This project uses [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). If you just cloned the project, be sure to run: `git submodule update --init`. See our dedicated [page](https://ethereum.github.io/trin/developers/contributing/git/submodules.html) for more info.

## Experimental Status

Trin is a prototype Portal Network client. This implementation and the Portal Network specifications will continue to co-evolve.
Expand Down
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- [Style](developers/contributing/rust/style.md)
- [Git](developers/contributing/git/README.md)
- [Commits](developers/contributing/git/commits.md)
- [Submodules](developers/contributing/git/submodules.md)
- [Rebasing](developers/contributing/git/rebasing.md)
- [Release notes](developers/contributing/git/release_notes.md)
- [Pull requests](developers/contributing/git/pull_requests.md)
Expand Down
34 changes: 34 additions & 0 deletions book/src/developers/contributing/git/submodules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Submodules

This project uses [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). If you
just cloned the project, be sure to run:

```console
$ git submodule update --init
```

This page provides short overview of most common use cases.

## Pulling in Upstream Changes from the Submodule Remote

You want to do this when the remote version of submodule is updated. The simplest way to resolve
this is to run:

```console
$ git submodule update --remote --rebase
```

> If you modified your local submodule, you might want to use different flags.

If you run `git status`, you should see that submodule is updated. Commit and push the changes so
others can use the same version.

## Pulling Upstream Changes from the Project Remote

If somebody else updated the submodule and you pulled the changes, you have to update your local
clone as well. The message `"Submodules changed but not updated"` will show when running
`git status`. To update local submodule, run:

```console
$ git submodule update --init
```
2 changes: 2 additions & 0 deletions ethportal-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mod dashboard;
pub mod discv5;
mod eth;
mod history;
#[cfg(test)]
mod test_utils;
pub mod types;
pub mod utils;
mod web3;
Expand Down
1 change: 1 addition & 0 deletions ethportal-api/src/test_utils/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const PORTAL_SPEC_TESTS_SUBMODULE_PATH: &str = "../portal-spec-tests";
13 changes: 13 additions & 0 deletions ethportal-api/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use std::{
fs, io,
path::{Path, PathBuf},
};

use self::constants::PORTAL_SPEC_TESTS_SUBMODULE_PATH;

pub mod constants;

/// Reads a file from a "portal-spec-tests" submodule.
pub fn read_file_from_tests_submodule<P: AsRef<Path>>(path: P) -> io::Result<String> {
fs::read_to_string(PathBuf::from(PORTAL_SPEC_TESTS_SUBMODULE_PATH).join(path))
}
42 changes: 17 additions & 25 deletions ethportal-api/src/types/content_value/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,21 @@ pub struct ContractBytecodeWithProof {

#[cfg(test)]
mod test {
use std::{fs, str::FromStr};
use std::{path::PathBuf, str::FromStr};

use anyhow::Result;
use rstest::rstest;
use serde_yaml::Value;

use crate::utils::bytes::hex_decode;
use crate::{test_utils::read_file_from_tests_submodule, utils::bytes::hex_decode};

use super::*;

const TEST_DATA_DIRECTORY: &str = "tests/mainnet/state/serialization";

#[test]
fn trie_node() -> Result<()> {
let file = fs::read_to_string("../test_assets/portalnet/content/state/trie_node.yaml")?;
let value: Value = serde_yaml::from_str(&file)?;
let value = read_yaml_file("trie_node.yaml")?;
let value = value.as_mapping().unwrap();

let expected_content_value = StateContentValue::TrieNode(TrieNode {
Expand All @@ -187,10 +188,7 @@ mod test {

#[test]
fn account_trie_node_with_proof() -> Result<()> {
let file = fs::read_to_string(
"../test_assets/portalnet/content/state/account_trie_node_with_proof.yaml",
)?;
let value: Value = serde_yaml::from_str(&file)?;
let value = read_yaml_file("account_trie_node_with_proof.yaml")?;
let value = value.as_mapping().unwrap();

let expected_content_value =
Expand All @@ -206,10 +204,7 @@ mod test {

#[test]
fn contract_storage_trie_node_with_proof() -> Result<()> {
let file = fs::read_to_string(
"../test_assets/portalnet/content/state/contract_storage_trie_node_with_proof.yaml",
)?;
let value: Value = serde_yaml::from_str(&file)?;
let value = read_yaml_file("contract_storage_trie_node_with_proof.yaml")?;
let value = value.as_mapping().unwrap();

let expected_content_value =
Expand All @@ -226,9 +221,7 @@ mod test {

#[test]
fn contract_bytecode() -> Result<()> {
let file =
fs::read_to_string("../test_assets/portalnet/content/state/contract_bytecode.yaml")?;
let value: Value = serde_yaml::from_str(&file)?;
let value = read_yaml_file("contract_bytecode.yaml")?;
let value = value.as_mapping().unwrap();

let expected_content_value = StateContentValue::ContractBytecode(ContractBytecode {
Expand All @@ -242,10 +235,7 @@ mod test {

#[test]
fn contract_bytecode_with_proof() -> Result<()> {
let file = fs::read_to_string(
"../test_assets/portalnet/content/state/contract_bytecode_with_proof.yaml",
)?;
let value: Value = serde_yaml::from_str(&file)?;
let value = read_yaml_file("contract_bytecode_with_proof.yaml")?;
let value = value.as_mapping().unwrap();

let expected_content_value =
Expand All @@ -267,9 +257,7 @@ mod test {
#[case::contract_bytecode("contract_bytecode.yaml")]
#[case::contract_bytecode_with_proof("contract_bytecode_with_proof.yaml")]
fn encode_decode(#[case] filename: &str) -> Result<()> {
let file =
fs::read_to_string(format!("../test_assets/portalnet/content/state/{filename}"))?;
let value: Value = serde_yaml::from_str(&file)?;
let value = read_yaml_file(filename)?;
let value = value.as_mapping().unwrap();

let content_value_bytes = yaml_as_hex(&value["content_value"]);
Expand All @@ -288,9 +276,7 @@ mod test {
#[case::contract_bytecode("contract_bytecode.yaml")]
#[case::contract_bytecode_with_proof("contract_bytecode_with_proof.yaml")]
fn serde(#[case] filename: &str) -> Result<()> {
let file =
fs::read_to_string(format!("../test_assets/portalnet/content/state/{filename}"))?;
let value: Value = serde_yaml::from_str(&file)?;
let value = read_yaml_file(filename)?;
let value = value.as_mapping().unwrap();

let content_value = StateContentValue::deserialize(&value["content_value"])?;
Expand All @@ -303,6 +289,12 @@ mod test {
Ok(())
}

fn read_yaml_file(filename: &str) -> Result<Value> {
let path = PathBuf::from(TEST_DATA_DIRECTORY).join(filename);
let file = read_file_from_tests_submodule(path)?;
Ok(serde_yaml::from_str(&file)?)
}

fn yaml_as_h256(value: &Value) -> H256 {
H256::from_str(value.as_str().unwrap()).unwrap()
}
Expand Down
1 change: 1 addition & 0 deletions portal-spec-tests
Submodule portal-spec-tests added at 5e472a
17 changes: 0 additions & 17 deletions test_assets/portalnet/content/state/account_trie_node_key.yaml

This file was deleted.

Loading
Loading