Skip to content

Commit

Permalink
GH-500: probably finished the deployment of Base, let's get the QA going
Browse files Browse the repository at this point in the history
  • Loading branch information
Bert authored and Bert committed Sep 14, 2024
1 parent 14e4b86 commit 38ba946
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 41 deletions.
36 changes: 35 additions & 1 deletion masq_lib/src/blockchains/blockchain_records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::blockchains::chains::Chain;
use crate::constants::{
BASE_MAINNET_CONTRACT_CREATION_BLOCK, BASE_MAINNET_FULL_IDENTIFIER,
BASE_SEPOLIA_CONTRACT_CREATION_BLOCK, BASE_SEPOLIA_FULL_IDENTIFIER, DEV_CHAIN_FULL_IDENTIFIER,
ETH_MAINNET_CONTRACT_CREATION_BLOCK, ETH_MAINNET_FULL_IDENTIFIER,
ETH_ROPSTEN_CONTRACT_CREATION_BLOCK, ETH_ROPSTEN_FULL_IDENTIFIER,
Expand All @@ -11,7 +12,7 @@ use crate::constants::{
};
use ethereum_types::{Address, H160};

pub const CHAINS: [BlockchainRecord; 6] = [
pub const CHAINS: [BlockchainRecord; 7] = [
BlockchainRecord {
self_id: Chain::PolyMainnet,
num_chain_id: 137,
Expand All @@ -26,6 +27,13 @@ pub const CHAINS: [BlockchainRecord; 6] = [
contract: ETH_MAINNET_CONTRACT_ADDRESS,
contract_creation_block: ETH_MAINNET_CONTRACT_CREATION_BLOCK,
},
BlockchainRecord {
self_id: Chain::BaseMainnet,
num_chain_id: 8453,
literal_identifier: BASE_MAINNET_FULL_IDENTIFIER,
contract: BASE_MAINNET_CONTRACT_ADDRESS,
contract_creation_block: BASE_MAINNET_CONTRACT_CREATION_BLOCK,
},
BlockchainRecord {
self_id: Chain::BaseSepolia,
num_chain_id: 84532,
Expand Down Expand Up @@ -87,6 +95,11 @@ const ETH_ROPSTEN_TESTNET_CONTRACT_ADDRESS: Address = H160([
0x68, 0xba, 0x24, 0xc3,
]);

const BASE_MAINNET_CONTRACT_ADDRESS: Address = H160([
0x45, 0xD9, 0xC1, 0x01, 0xa3, 0x87, 0x0C, 0xa5, 0x02, 0x45, 0x82, 0xfd, 0x78, 0x8F, 0x4E, 0x1e,
0x8F, 0x79, 0x71, 0xc3,
]);

const BASE_SEPOLIA_TESTNET_CONTRACT_ADDRESS: Address = H160([
0x89, 0x8e, 0x1c, 0xe7, 0x20, 0x08, 0x4A, 0x90, 0x2b, 0xc3, 0x7d, 0xd8, 0x22, 0xed, 0x6d, 0x6a,
0x5f, 0x02, 0x7e, 0x10,
Expand All @@ -101,6 +114,7 @@ const MULTINODE_TESTNET_CONTRACT_ADDRESS: Address = H160([
mod tests {
use super::*;
use crate::blockchains::chains::chain_from_chain_identifier_opt;
use crate::constants::BASE_MAINNET_CONTRACT_CREATION_BLOCK;
use std::collections::HashSet;
use std::iter::FromIterator;

Expand All @@ -111,6 +125,7 @@ mod tests {
assert_returns_correct_record(Chain::EthRopsten, 3),
assert_returns_correct_record(Chain::PolyMainnet, 137),
assert_returns_correct_record(Chain::PolyAmoy, 80002),
assert_returns_correct_record(Chain::BaseMainnet, 8453),
assert_returns_correct_record(Chain::BaseSepolia, 84532),
assert_returns_correct_record(Chain::Dev, 2),
];
Expand All @@ -129,6 +144,7 @@ mod tests {
assert_from_str(Chain::PolyAmoy),
assert_from_str(Chain::EthMainnet),
assert_from_str(Chain::EthRopsten),
assert_from_str(Chain::BaseMainnet),
assert_from_str(Chain::BaseSepolia),
assert_from_str(Chain::Dev),
];
Expand All @@ -151,6 +167,7 @@ mod tests {
let test_array = [
Chain::PolyMainnet,
Chain::EthMainnet,
Chain::BaseMainnet,
Chain::BaseSepolia,
Chain::PolyAmoy,
Chain::EthRopsten,
Expand Down Expand Up @@ -231,6 +248,22 @@ mod tests {
);
}

#[test]
fn base_mainnet_record_is_properly_declared() {
let examined_chain = Chain::BaseMainnet;
let chain_record = return_examined(examined_chain);
assert_eq!(
chain_record,
&BlockchainRecord {
num_chain_id: 8453,
self_id: examined_chain,
literal_identifier: "base-mainnet",
contract: BASE_MAINNET_CONTRACT_ADDRESS,
contract_creation_block: BASE_MAINNET_CONTRACT_CREATION_BLOCK,
}
);
}

#[test]
fn base_sepolia_record_is_properly_declared() {
let examined_chain = Chain::BaseSepolia;
Expand Down Expand Up @@ -274,6 +307,7 @@ mod tests {
assert_chain_from_chain_identifier_opt("eth-ropsten", Some(Chain::EthRopsten)),
assert_chain_from_chain_identifier_opt("polygon-mainnet", Some(Chain::PolyMainnet)),
assert_chain_from_chain_identifier_opt("polygon-amoy", Some(Chain::PolyAmoy)),
assert_chain_from_chain_identifier_opt("base-mainnet", Some(Chain::BaseMainnet)),
assert_chain_from_chain_identifier_opt("base-sepolia", Some(Chain::BaseSepolia)),
assert_chain_from_chain_identifier_opt("dev", Some(Chain::Dev)),
];
Expand Down
11 changes: 7 additions & 4 deletions masq_lib/src/blockchains/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use crate::blockchains::blockchain_records::{BlockchainRecord, CHAINS};
use crate::constants::{
BASE_SEPOLIA_FULL_IDENTIFIER, DEFAULT_CHAIN, DEV_CHAIN_FULL_IDENTIFIER,
ETH_MAINNET_FULL_IDENTIFIER, ETH_ROPSTEN_FULL_IDENTIFIER, POLYGON_AMOY_FULL_IDENTIFIER,
POLYGON_MAINNET_FULL_IDENTIFIER,
BASE_MAINNET_FULL_IDENTIFIER, BASE_SEPOLIA_FULL_IDENTIFIER, DEFAULT_CHAIN,
DEV_CHAIN_FULL_IDENTIFIER, ETH_MAINNET_FULL_IDENTIFIER, ETH_ROPSTEN_FULL_IDENTIFIER,
POLYGON_AMOY_FULL_IDENTIFIER, POLYGON_MAINNET_FULL_IDENTIFIER,
};
use serde_derive::{Deserialize, Serialize};

Expand All @@ -14,6 +14,7 @@ pub enum Chain {
EthRopsten,
PolyMainnet,
PolyAmoy,
BaseMainnet,
BaseSepolia,
Dev,
}
Expand All @@ -30,6 +31,8 @@ impl From<&str> for Chain {
Chain::PolyMainnet
} else if str == ETH_MAINNET_FULL_IDENTIFIER {
Chain::EthMainnet
} else if str == BASE_MAINNET_FULL_IDENTIFIER {
Chain::BaseMainnet
} else if str == BASE_SEPOLIA_FULL_IDENTIFIER {
Chain::BaseSepolia
} else if str == POLYGON_AMOY_FULL_IDENTIFIER {
Expand Down Expand Up @@ -60,7 +63,7 @@ impl Chain {
}

fn mainnets() -> &'static [Chain] {
&[Chain::PolyMainnet, Chain::EthMainnet]
&[Chain::PolyMainnet, Chain::BaseMainnet, Chain::EthMainnet]
}
}

Expand Down
3 changes: 3 additions & 0 deletions masq_lib/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub const ETH_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 11_170_708;
pub const ETH_ROPSTEN_CONTRACT_CREATION_BLOCK: u64 = 8_688_171;
pub const POLYGON_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 14_863_650;
pub const POLYGON_AMOY_CONTRACT_CREATION_BLOCK: u64 = 5_323_366;
pub const BASE_MAINNET_CONTRACT_CREATION_BLOCK: u64 = 19_711_235;
pub const BASE_SEPOLIA_CONTRACT_CREATION_BLOCK: u64 = 14_732_730;
pub const MULTINODE_TESTNET_CONTRACT_CREATION_BLOCK: u64 = 0;

Expand Down Expand Up @@ -97,6 +98,7 @@ pub const POLYGON_MAINNET_FULL_IDENTIFIER: &str = concatcp!(POLYGON_FAMILY, LINK
pub const POLYGON_AMOY_FULL_IDENTIFIER: &str = concatcp!(POLYGON_FAMILY, LINK, "amoy");
pub const ETH_MAINNET_FULL_IDENTIFIER: &str = concatcp!(ETH_FAMILY, LINK, MAINNET);
pub const ETH_ROPSTEN_FULL_IDENTIFIER: &str = concatcp!(ETH_FAMILY, LINK, "ropsten");
pub const BASE_MAINNET_FULL_IDENTIFIER: &str = concatcp!(BASE_FAMILY, LINK, MAINNET);
pub const BASE_SEPOLIA_FULL_IDENTIFIER: &str = concatcp!(BASE_FAMILY, LINK, "sepolia");
pub const DEV_CHAIN_FULL_IDENTIFIER: &str = "dev";

Expand Down Expand Up @@ -124,6 +126,7 @@ mod tests {
assert_eq!(ETH_ROPSTEN_CONTRACT_CREATION_BLOCK, 8_688_171);
assert_eq!(POLYGON_MAINNET_CONTRACT_CREATION_BLOCK, 14_863_650);
assert_eq!(POLYGON_AMOY_CONTRACT_CREATION_BLOCK, 5_323_366);
assert_eq!(BASE_MAINNET_CONTRACT_CREATION_BLOCK, 19_711_235);
assert_eq!(BASE_SEPOLIA_CONTRACT_CREATION_BLOCK, 14_732_730);
assert_eq!(MULTINODE_TESTNET_CONTRACT_CREATION_BLOCK, 0);
assert_eq!(CONFIGURATOR_PREFIX, 0x0001_0000_0000_0000);
Expand Down
17 changes: 12 additions & 5 deletions masq_lib/src/shared_schema.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.

use crate::constants::{
BASE_SEPOLIA_FULL_IDENTIFIER, DEFAULT_GAS_PRICE, DEFAULT_UI_PORT, DEV_CHAIN_FULL_IDENTIFIER,
ETH_MAINNET_FULL_IDENTIFIER, ETH_ROPSTEN_FULL_IDENTIFIER, HIGHEST_USABLE_PORT,
LOWEST_USABLE_INSECURE_PORT, POLYGON_AMOY_FULL_IDENTIFIER, POLYGON_MAINNET_FULL_IDENTIFIER,
BASE_MAINNET_FULL_IDENTIFIER, BASE_SEPOLIA_FULL_IDENTIFIER, DEFAULT_GAS_PRICE, DEFAULT_UI_PORT,
DEV_CHAIN_FULL_IDENTIFIER, ETH_MAINNET_FULL_IDENTIFIER, ETH_ROPSTEN_FULL_IDENTIFIER,
HIGHEST_USABLE_PORT, LOWEST_USABLE_INSECURE_PORT, POLYGON_AMOY_FULL_IDENTIFIER,
POLYGON_MAINNET_FULL_IDENTIFIER,
};
use crate::crash_point::CrashPoint;
use clap::{App, Arg};
Expand All @@ -13,6 +14,7 @@ pub const BLOCKCHAIN_SERVICE_HELP: &str =
"The Ethereum client you wish to use to provide Blockchain \
exit services from your MASQ Node (e.g. http://localhost:8545, \
https://ropsten.infura.io/v3/YOUR-PROJECT-ID, https://mainnet.infura.io/v3/YOUR-PROJECT-ID), \
https://base-mainnet.g.alchemy.com/v2/d66UL0lPrltmweEqVsv3opBSVI3wkL8I, \
https://polygon-mainnet.infura.io/v3/YOUR-PROJECT-ID";
pub const CHAIN_HELP: &str =
"The blockchain network MASQ Node will configure itself to use. You must ensure the \
Expand Down Expand Up @@ -64,8 +66,9 @@ pub const NEIGHBORS_HELP: &str = "One or more Node descriptors for running Nodes
on startup. A Node descriptor looks similar to one of these:\n\n\
masq://polygon-mainnet:[email protected]:9342\n\
masq://eth-mainnet:[email protected]:5542\n\
masq://base-mainnet:[email protected]:7878\n\
masq://polygon-amoy:[email protected]:10504\n\
masq://eth-ropsten:[email protected]:6642/4789/5254\n\n\
masq://base-sepolia:[email protected]:6642/4789/5254\n\n\
Notice each of the different chain identifiers in the masq protocol prefix - they determine a family of chains \
and also the network the descriptor belongs to (mainnet or a testnet). See also the last descriptor which shows \
a configuration with multiple clandestine ports.\n\n\
Expand Down Expand Up @@ -256,6 +259,7 @@ pub fn official_chain_names() -> &'static [&'static str] {
&[
POLYGON_MAINNET_FULL_IDENTIFIER,
ETH_MAINNET_FULL_IDENTIFIER,
BASE_MAINNET_FULL_IDENTIFIER,
BASE_SEPOLIA_FULL_IDENTIFIER,
POLYGON_AMOY_FULL_IDENTIFIER,
ETH_ROPSTEN_FULL_IDENTIFIER,
Expand Down Expand Up @@ -684,6 +688,7 @@ mod tests {
"The Ethereum client you wish to use to provide Blockchain \
exit services from your MASQ Node (e.g. http://localhost:8545, \
https://ropsten.infura.io/v3/YOUR-PROJECT-ID, https://mainnet.infura.io/v3/YOUR-PROJECT-ID), \
https://base-mainnet.g.alchemy.com/v2/d66UL0lPrltmweEqVsv3opBSVI3wkL8I, \
https://polygon-mainnet.infura.io/v3/YOUR-PROJECT-ID"
);
assert_eq!(
Expand Down Expand Up @@ -758,8 +763,9 @@ mod tests {
on startup. A Node descriptor looks similar to one of these:\n\n\
masq://polygon-mainnet:[email protected]:9342\n\
masq://eth-mainnet:[email protected]:5542\n\
masq://base-mainnet:[email protected]:7878\n\
masq://polygon-amoy:[email protected]:10504\n\
masq://eth-ropsten:[email protected]:6642/4789/5254\n\n\
masq://base-sepolia:[email protected]:6642/4789/5254\n\n\
Notice each of the different chain identifiers in the masq protocol prefix - they determine a family of chains \
and also the network the descriptor belongs to (mainnet or a testnet). See also the last descriptor which shows \
a configuration with multiple clandestine ports.\n\n\
Expand Down Expand Up @@ -1145,6 +1151,7 @@ mod tests {
let expected_supported_chains = [
Chain::PolyMainnet,
Chain::EthMainnet,
Chain::BaseMainnet,
Chain::BaseSepolia,
Chain::PolyAmoy,
Chain::EthRopsten,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@ where
fn web3_gas_limit_const_part(chain: Chain) -> u64 {
match chain {
Chain::EthMainnet | Chain::EthRopsten | Chain::Dev => 55_000,
Chain::PolyMainnet | Chain::PolyAmoy | Chain::BaseSepolia => 70_000,
Chain::PolyMainnet | Chain::PolyAmoy | Chain::BaseMainnet | Chain::BaseSepolia => {
70_000
}
}
}

Expand Down Expand Up @@ -676,6 +678,7 @@ mod tests {
BlockchainTransaction, RpcPayablesFailure,
};
use indoc::indoc;
use sodiumoxide::hex;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::time::SystemTime;
Expand Down Expand Up @@ -1846,7 +1849,9 @@ mod tests {
let gas_price = match chain {
Chain::EthMainnet | Chain::EthRopsten | Chain::Dev => 110,
Chain::PolyMainnet | Chain::PolyAmoy => 55,
Chain::BaseSepolia => todo!(),
// It performs on even cheaper fees, but we're
// limited by the units here
Chain::BaseMainnet | Chain::BaseSepolia => 1,
};
let payment_size_wei = 1_000_000_000_000;
let payable_account = make_payable_account_with_wallet_and_balance_and_timestamp_opt(
Expand All @@ -1866,7 +1871,14 @@ mod tests {
.unwrap();

let byte_set_to_compare = signed_transaction.raw_transaction.0;
assert_eq!(byte_set_to_compare.as_slice(), template)
eprintln!("signed {}", hex::encode(byte_set_to_compare.clone()));
assert_eq!(
byte_set_to_compare,
template,
"Actual signed transaction {} does not match {} as expected",
hex::encode(byte_set_to_compare.clone()),
hex::encode(template.to_vec())
)
}

// Transaction with this input was verified on the test network
Expand All @@ -1884,6 +1896,20 @@ mod tests {
assert_that_signed_transactions_agrees_with_template(chain, nonce, &in_bytes)
}

#[test]
fn web3_interface_signing_a_transaction_works_for_base_sepolia() {
let chain = Chain::BaseSepolia;
let nonce = 2;
let signed_transaction_data = "\
f8ac02843b9aca008301198094898e1ce720084a902bc37dd822ed6d6a5f027e1080b844a9059cbb00000000000\
00000000000007788df76bbd9a0c7c3e5bf0f77bb28c60a167a7b00000000000000000000000000000000000000\
0000000000000000e8d4a510008302948ca07b57223b566ade08ec817770c8b9ae94373edbefc13372c3463cf7b\
6ce542231a020991f2ff180a12cbc2745465a4e710da294b890901a3887519b191c3a69cd4f";
let in_bytes = decode_hex(signed_transaction_data).unwrap();

assert_that_signed_transactions_agrees_with_template(chain, nonce, &in_bytes)
}

// Transaction with this input was verified on the test network
#[test]
fn web3_interface_signing_a_transaction_works_for_eth_ropsten() {
Expand All @@ -1904,41 +1930,44 @@ mod tests {
fn web3_interface_signing_a_transaction_for_polygon_mainnet() {
let chain = Chain::PolyMainnet;
let nonce = 10;
// Generated locally
let signed_transaction_data = [
248, 172, 10, 133, 12, 206, 65, 102, 0, 131, 1, 25, 128, 148, 238, 154, 53, 47, 106,
172, 74, 241, 165, 185, 244, 103, 246, 169, 62, 15, 251, 233, 221, 53, 128, 184, 68,
169, 5, 156, 187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, 136, 223, 118, 187, 217,
160, 199, 195, 229, 191, 15, 119, 187, 40, 198, 10, 22, 122, 123, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 212, 165, 16, 0, 130,
1, 53, 160, 200, 159, 77, 202, 128, 195, 67, 122, 35, 204, 26, 65, 171, 89, 253, 82, 6,
176, 192, 225, 41, 61, 151, 82, 66, 232, 72, 44, 68, 131, 140, 117, 160, 117, 66, 154,
132, 183, 97, 219, 131, 214, 72, 220, 66, 152, 72, 15, 107, 44, 237, 193, 16, 193, 52,
6, 94, 216, 149, 94, 102, 199, 80, 68, 105,
];
let signed_transaction_data = "f8ac0a850cce4166008301198094ee9a352f6aac4af1a5b9f467f6a\
93e0ffbe9dd3580b844a9059cbb0000000000000000000000007788df76bbd9a0c7c3e5bf0f77bb28c60a167a7b\
000000000000000000000000000000000000000000000000000000e8d4a51000820135a0c89f4dca80c3437a23c\
c1a41ab59fd5206b0c0e1293d975242e8482c44838c75a075429a84b761db83d648dc4298480f6b2cedc110c134\
065ed8955e66c7504469";
let in_bytes = decode_hex(signed_transaction_data).unwrap();

assert_that_signed_transactions_agrees_with_template(chain, nonce, &signed_transaction_data)
assert_that_signed_transactions_agrees_with_template(chain, nonce, &in_bytes)
}

// Unconfirmed on the real network
#[test]
fn web3_interface_signing_a_transaction_for_eth_mainnet() {
let chain = Chain::EthMainnet;
let nonce = 10;
// Generated locally
let signed_transaction_data = [
248, 169, 10, 133, 25, 156, 130, 204, 0, 130, 222, 232, 148, 6, 243, 195, 35, 240, 35,
140, 114, 191, 53, 1, 16, 113, 242, 181, 183, 244, 58, 5, 76, 128, 184, 68, 169, 5,
156, 187, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 119, 136, 223, 118, 187, 217, 160, 199,
195, 229, 191, 15, 119, 187, 40, 198, 10, 22, 122, 123, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 212, 165, 16, 0, 38, 160, 199,
155, 76, 106, 39, 227, 3, 151, 90, 117, 245, 211, 86, 98, 187, 117, 120, 103, 165, 131,
99, 72, 36, 211, 10, 224, 252, 104, 51, 200, 230, 158, 160, 84, 18, 140, 248, 119, 22,
193, 14, 148, 253, 48, 59, 185, 11, 38, 152, 103, 150, 120, 60, 74, 56, 159, 206, 22,
15, 73, 173, 153, 11, 76, 74,
];
let signed_transaction_data = "f8a90a85199c82cc0082dee89406f3c323f0238c72bf35011071f2b\
5b7f43a054c80b844a9059cbb0000000000000000000000007788df76bbd9a0c7c3e5bf0f77bb28c60a167a7b00\
0000000000000000000000000000000000000000000000000000e8d4a5100026a0c79b4c6a27e303975a75f5d35\
662bb757867a583634824d30ae0fc6833c8e69ea054128cf87716c10e94fd303bb90b26986796783c4a389fce16\
0f49ad990b4c4a";
let in_bytes = decode_hex(signed_transaction_data).unwrap();

assert_that_signed_transactions_agrees_with_template(chain, nonce, &in_bytes)
}

// Unconfirmed on the real network
#[test]
fn web3_interface_signing_a_transaction_for_base_mainnet() {
let chain = Chain::BaseMainnet;
let nonce = 124;
let signed_transaction_data = "f8ab7c843b9aca00830119809445d9c101a3870ca5024582fd788f4\
e1e8f7971c380b844a9059cbb0000000000000000000000007788df76bbd9a0c7c3e5bf0f77bb28c60a167a7b00\
0000000000000000000000000000000000000000000000000000e8d4a5100082422da0587b5f8401225d5cf6267\
6f51f376f085805851e2e59c5253eb2834612295bdba05b6963872bac7eeafb38191079e8c8df919c193839022b\
d57b91ace5a8638034";
let in_bytes = decode_hex(signed_transaction_data).unwrap();

assert_that_signed_transactions_agrees_with_template(chain, nonce, &signed_transaction_data)
assert_that_signed_transactions_agrees_with_template(chain, nonce, &in_bytes)
}

// Adapted test from old times when we had our own signing method.
Expand Down
Loading

0 comments on commit 38ba946

Please sign in to comment.