Skip to content

Commit e73cbbd

Browse files
authored
chore: add portal-spec-tests repo as submodule (ethereum#1131)
1 parent fa45915 commit e73cbbd

18 files changed

+82
-141
lines changed

.circleci/config.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ commands:
2929
key: sccache-cache-stable-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ epoch }}
3030
paths:
3131
- "~/.cache/sccache"
32+
checkout-submodules:
33+
steps:
34+
- run:
35+
name: Checkout submodules
36+
command: |
37+
git submodule sync
38+
git submodule update --init
3239
install-depends:
3340
steps:
3441
- run:
@@ -210,6 +217,7 @@ jobs:
210217
RUST_LOG: "debug"
211218
steps:
212219
- checkout
220+
- checkout-submodules
213221
- install-depends
214222
- setup-and-restore-sccache-cache
215223
- run:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "portal-spec-tests"]
2+
path = portal-spec-tests
3+
url = https://github.com/ethereum/portal-spec-tests

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Trin currently only runs on Unix-based platforms (Linux, macOS). We plan to even
1414

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

17+
> **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.
18+
1719
## Experimental Status
1820

1921
Trin is a prototype Portal Network client. This implementation and the Portal Network specifications will continue to co-evolve.

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
- [Style](developers/contributing/rust/style.md)
4040
- [Git](developers/contributing/git/README.md)
4141
- [Commits](developers/contributing/git/commits.md)
42+
- [Submodules](developers/contributing/git/submodules.md)
4243
- [Rebasing](developers/contributing/git/rebasing.md)
4344
- [Release notes](developers/contributing/git/release_notes.md)
4445
- [Pull requests](developers/contributing/git/pull_requests.md)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Submodules
2+
3+
This project uses [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules). If you
4+
just cloned the project, be sure to run:
5+
6+
```console
7+
$ git submodule update --init
8+
```
9+
10+
This page provides short overview of most common use cases.
11+
12+
## Pulling in Upstream Changes from the Submodule Remote
13+
14+
You want to do this when the remote version of submodule is updated. The simplest way to resolve
15+
this is to run:
16+
17+
```console
18+
$ git submodule update --remote --rebase
19+
```
20+
21+
> If you modified your local submodule, you might want to use different flags.
22+
23+
If you run `git status`, you should see that submodule is updated. Commit and push the changes so
24+
others can use the same version.
25+
26+
## Pulling Upstream Changes from the Project Remote
27+
28+
If somebody else updated the submodule and you pulled the changes, you have to update your local
29+
clone as well. The message `"Submodules changed but not updated"` will show when running
30+
`git status`. To update local submodule, run:
31+
32+
```console
33+
$ git submodule update --init
34+
```

ethportal-api/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ mod dashboard;
1212
pub mod discv5;
1313
mod eth;
1414
mod history;
15+
#[cfg(test)]
16+
mod test_utils;
1517
pub mod types;
1618
pub mod utils;
1719
mod web3;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const PORTAL_SPEC_TESTS_SUBMODULE_PATH: &str = "../portal-spec-tests";

ethportal-api/src/test_utils/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::{
2+
fs, io,
3+
path::{Path, PathBuf},
4+
};
5+
6+
use self::constants::PORTAL_SPEC_TESTS_SUBMODULE_PATH;
7+
8+
pub mod constants;
9+
10+
/// Reads a file from a "portal-spec-tests" submodule.
11+
pub fn read_file_from_tests_submodule<P: AsRef<Path>>(path: P) -> io::Result<String> {
12+
fs::read_to_string(PathBuf::from(PORTAL_SPEC_TESTS_SUBMODULE_PATH).join(path))
13+
}

ethportal-api/src/types/content_value/state.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,21 @@ pub struct ContractBytecodeWithProof {
160160

161161
#[cfg(test)]
162162
mod test {
163-
use std::{fs, str::FromStr};
163+
use std::{path::PathBuf, str::FromStr};
164164

165165
use anyhow::Result;
166166
use rstest::rstest;
167167
use serde_yaml::Value;
168168

169-
use crate::utils::bytes::hex_decode;
169+
use crate::{test_utils::read_file_from_tests_submodule, utils::bytes::hex_decode};
170170

171171
use super::*;
172172

173+
const TEST_DATA_DIRECTORY: &str = "tests/mainnet/state/serialization";
174+
173175
#[test]
174176
fn trie_node() -> Result<()> {
175-
let file = fs::read_to_string("../test_assets/portalnet/content/state/trie_node.yaml")?;
176-
let value: Value = serde_yaml::from_str(&file)?;
177+
let value = read_yaml_file("trie_node.yaml")?;
177178
let value = value.as_mapping().unwrap();
178179

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

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

196194
let expected_content_value =
@@ -206,10 +204,7 @@ mod test {
206204

207205
#[test]
208206
fn contract_storage_trie_node_with_proof() -> Result<()> {
209-
let file = fs::read_to_string(
210-
"../test_assets/portalnet/content/state/contract_storage_trie_node_with_proof.yaml",
211-
)?;
212-
let value: Value = serde_yaml::from_str(&file)?;
207+
let value = read_yaml_file("contract_storage_trie_node_with_proof.yaml")?;
213208
let value = value.as_mapping().unwrap();
214209

215210
let expected_content_value =
@@ -226,9 +221,7 @@ mod test {
226221

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

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

243236
#[test]
244237
fn contract_bytecode_with_proof() -> Result<()> {
245-
let file = fs::read_to_string(
246-
"../test_assets/portalnet/content/state/contract_bytecode_with_proof.yaml",
247-
)?;
248-
let value: Value = serde_yaml::from_str(&file)?;
238+
let value = read_yaml_file("contract_bytecode_with_proof.yaml")?;
249239
let value = value.as_mapping().unwrap();
250240

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

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

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

292+
fn read_yaml_file(filename: &str) -> Result<Value> {
293+
let path = PathBuf::from(TEST_DATA_DIRECTORY).join(filename);
294+
let file = read_file_from_tests_submodule(path)?;
295+
Ok(serde_yaml::from_str(&file)?)
296+
}
297+
306298
fn yaml_as_h256(value: &Value) -> H256 {
307299
H256::from_str(value.as_str().unwrap()).unwrap()
308300
}

portal-spec-tests

Submodule portal-spec-tests added at 5e472ac

test_assets/portalnet/content/state/account_trie_node_key.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)