Validate eth1 chain id (#1877)

## Issue Addressed

Resolves #1815 

## Proposed Changes

Adds extra validation for eth1 chain id apart from the existing check for eth1 network id.
This commit is contained in:
Pawan Dhananjay
2020-11-16 23:10:42 +00:00
parent 4d732a1f1d
commit 280334b1b0
5 changed files with 71 additions and 29 deletions

View File

@@ -15,6 +15,7 @@ use web3::{
const GANACHE_STARTUP_TIMEOUT_MILLIS: u64 = 10_000;
const NETWORK_ID: u64 = 42;
const CHAIN_ID: u64 = 42;
/// Provides a dedicated `ganachi-cli` instance with a connected `Web3` instance.
///
@@ -46,6 +47,8 @@ impl GanacheInstance {
.arg("\"vast thought differ pull jewel broom cook wrist tribe word before omit\"")
.arg("--networkId")
.arg(format!("{}", NETWORK_ID))
.arg("--chainId")
.arg(format!("{}", CHAIN_ID))
.spawn()
.map_err(|e| {
format!(
@@ -106,6 +109,11 @@ impl GanacheInstance {
NETWORK_ID
}
/// Returns the chain id of the ganache instance
pub fn chain_id(&self) -> u64 {
CHAIN_ID
}
/// Increase the timestamp on future blocks by `increase_by` seconds.
pub async fn increase_time(&self, increase_by: u64) -> Result<(), String> {
self.web3

View File

@@ -1,6 +1,6 @@
use crate::{checks, LocalNetwork, E};
use clap::ArgMatches;
use eth1::http::Eth1NetworkId;
use eth1::http::Eth1Id;
use eth1_test_rig::GanacheEth1Instance;
use futures::prelude::*;
use node_test_rig::{
@@ -76,6 +76,7 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
let ganache_eth1_instance = GanacheEth1Instance::new().await?;
let deposit_contract = ganache_eth1_instance.deposit_contract;
let network_id = ganache_eth1_instance.ganache.network_id();
let chain_id = ganache_eth1_instance.ganache.chain_id();
let ganache = ganache_eth1_instance.ganache;
let eth1_endpoint = ganache.endpoint();
let deposit_contract_address = deposit_contract.address();
@@ -108,7 +109,8 @@ pub fn run_eth1_sim(matches: &ArgMatches) -> Result<(), String> {
beacon_config.eth1.follow_distance = 1;
beacon_config.dummy_eth1_backend = false;
beacon_config.sync_eth1_chain = true;
beacon_config.eth1.network_id = Eth1NetworkId::Custom(network_id);
beacon_config.eth1.network_id = Eth1Id::Custom(network_id);
beacon_config.eth1.chain_id = Eth1Id::Custom(chain_id);
beacon_config.network.enr_address = Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));