Skip to content

Commit

Permalink
Copy reference test changes from #1792
Browse files Browse the repository at this point in the history
  • Loading branch information
tbro committed Jul 30, 2024
1 parent 08e79cc commit d4af112
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 40 deletions.
7 changes: 7 additions & 0 deletions data/genesis/demo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ base_fee = '1 wei'
max_block_size = '1mb'
fee_recipient = '0x0000000000000000000000000000000000000000'
fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468'

[[upgrade]]
version = "0.4"
start_proposing_view = 5
stop_proposing_view = 15

[upgrade.marketplace]
Binary file modified data/messages.bin
Binary file not shown.
56 changes: 32 additions & 24 deletions data/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,41 @@
"_pd": null,
"data": {
"block_header": {
"block_merkle_tree_root": "MERKLE_COMM~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAQA",
"builder_commitment": "BUILDER_COMMITMENT~tEvs0rxqOiMCvfe2R0omNNaphSlUiEDrb2q0IZpRcgA_",
"builder_signature": null,
"chain_config": {
"fields": {
"block_merkle_tree_root": "MERKLE_COMM~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAQA",
"builder_commitment": "BUILDER_COMMITMENT~tEvs0rxqOiMCvfe2R0omNNaphSlUiEDrb2q0IZpRcgA_",
"builder_signature": null,
"chain_config": {
"Left": {
"base_fee": "0",
"chain_id": "35353",
"fee_contract": null,
"fee_recipient": "0x0000000000000000000000000000000000000000",
"max_block_size": "30720"
"chain_config": {
"Left": {
"base_fee": "0",
"chain_id": "35353",
"fee_contract": null,
"fee_recipient": "0x0000000000000000000000000000000000000000",
"max_block_size": "30720"
}
}
}
},
"fee_info": {
"account": "0x0000000000000000000000000000000000000000",
"amount": "0"
},
"fee_merkle_tree_root": "MERKLE_COMM~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAKA",
"height": 0,
"l1_finalized": null,
"l1_head": 0,
"ns_table": {
"bytes": "AAAAAA=="
},
"fee_info": {
"account": "0x0000000000000000000000000000000000000000",
"amount": "0"
},
"fee_merkle_tree_root": "MERKLE_COMM~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAKA",
"height": 0,
"l1_finalized": null,
"l1_head": 0,
"ns_table": {
"bytes": "AAAAAA=="
},
"payload_commitment": "HASH~AazstQer_ho1SqgGT0r10_Gs0BnjfbPBHJdSO3HHbp29",
"timestamp": 0
},
"payload_commitment": "HASH~AazstQer_ho1SqgGT0r10_Gs0BnjfbPBHJdSO3HHbp29",
"timestamp": 0
"version": {
"Version": {
"major": 0,
"minor": 2
}
}
},
"justify_qc": {
"_pd": null,
Expand Down
Binary file modified data/v2/header.bin
Binary file not shown.
Binary file added data/v3/chain_config.bin
Binary file not shown.
8 changes: 8 additions & 0 deletions data/v3/chain_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"base_fee": "0",
"bid_recipient": "0x0000000000000000000000000000000000000000",
"chain_id": "35353",
"fee_contract": "0x0000000000000000000000000000000000000000",
"fee_recipient": "0x0000000000000000000000000000000000000000",
"max_block_size": "10240"
}
Binary file modified data/v3/header.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion data/v3/header.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"chain_config": {
"Left": {
"base_fee": "0",
"bid_recipient": null,
"bid_recipient": "0x0000000000000000000000000000000000000000",
"chain_id": "35353",
"fee_contract": "0x0000000000000000000000000000000000000000",
"fee_recipient": "0x0000000000000000000000000000000000000000",
Expand Down
62 changes: 47 additions & 15 deletions types/src/reference_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use std::{fmt::Debug, path::Path, str::FromStr};

use committable::Committable;
use es_version::SequencerVersion;
use hotshot_query_service::availability::QueryablePayload;
use hotshot_types::traits::{
block_contents::vid_commitment, signature_key::BuilderSignatureKey, BlockPayload, EncodeBytes,
Expand All @@ -42,11 +41,13 @@ use vbs::{
};

use crate::{
v0_3::ChainConfig, FeeAccount, FeeInfo, Header, L1BlockInfo, NamespaceId, NsTable, Payload,
SeqTypes, Transaction, ValidatedState,
v0_1, FeeAccount, FeeInfo, Header, L1BlockInfo, NamespaceId, NsTable, Payload, SeqTypes,
Transaction, ValidatedState,
};

type Serializer = vbs::Serializer<SequencerVersion>;
type V1Serializer = vbs::Serializer<StaticVersion<0, 1>>;
type V2Serializer = vbs::Serializer<StaticVersion<0, 2>>;
type V3Serializer = vbs::Serializer<StaticVersion<0, 3>>;

async fn reference_payload() -> Payload {
const NUM_NS_IDS: usize = 3;
Expand Down Expand Up @@ -91,20 +92,23 @@ fn reference_l1_block() -> L1BlockInfo {

const REFERENCE_L1_BLOCK_COMMITMENT: &str = "L1BLOCK~4HpzluLK2Isz3RdPNvNrDAyQcWOF2c9JeLZzVNLmfpQ9";

fn reference_chain_config() -> ChainConfig {
ChainConfig {
fn reference_chain_config() -> crate::v0_3::ChainConfig {
crate::v0_3::ChainConfig {
chain_id: 0x8a19.into(),
max_block_size: 10240.into(),
base_fee: 0.into(),
fee_contract: Some(Default::default()),
fee_recipient: Default::default(),
bid_recipient: None,
bid_recipient: Some(Default::default()),
}
}

const REFERENCE_CHAIN_CONFIG_COMMITMENT: &str =
const REFERENCE_V1_CHAIN_CONFIG_COMMITMENT: &str =
"CHAIN_CONFIG~L6HmMktJbvnEGgpmRrsiYvQmIBstSj9UtDM7eNFFqYFO";

const REFERENCE_V3_CHAIN_CONFIG_COMMITMENT: &str =
"CHAIN_CONFIG~1mJTBiaJ0Nyuu4Ir5IZTamyI8CjexbktPkRr6R1rtnGh";

fn reference_fee_info() -> FeeInfo {
FeeInfo::new(
FeeAccount::from_str("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266").unwrap(),
Expand Down Expand Up @@ -150,7 +154,7 @@ async fn reference_header(version: Version) -> Header {

const REFERENCE_V1_HEADER_COMMITMENT: &str = "BLOCK~dh1KpdvvxSvnnPpOi2yI3DOg8h6ltr2Kv13iRzbQvtN2";
const REFERENCE_V2_HEADER_COMMITMENT: &str = "BLOCK~V0GJjL19nCrlm9n1zZ6gaOKEekSMCT6uR5P-h7Gi6UJR";
const REFERENCE_V3_HEADER_COMMITMENT: &str = "BLOCK~pD6_in2J8VzT6SshvvFUkNyMbx_h_gTtlU3WTmC6WedD";
const REFERENCE_V3_HEADER_COMMITMENT: &str = "BLOCK~oqbUzqJdG4JfWCDpCQWsLDjb47Rx_OH6KVsKQFOl4S2n";

fn reference_transaction<R>(ns_id: NamespaceId, rng: &mut R) -> Transaction
where
Expand Down Expand Up @@ -223,7 +227,13 @@ change in the serialization of this data structure.

// Check that the reference object matches the expected binary form.
let expected = std::fs::read(data_dir.join(format!("{name}.bin"))).unwrap();
let actual = Serializer::serialize(&reference).unwrap();
// todo (ab) : cleanup
let actual = match version {
"v1" => V1Serializer::serialize(&reference).unwrap(),
"v2" => V2Serializer::serialize(&reference).unwrap(),
"v3" => V3Serializer::serialize(&reference).unwrap(),
_ => panic!("invalid version"),
};
if actual != expected {
// Write the actual output to a file to make it easier to compare with/replace the expected
// file if the serialization change was actually intended.
Expand All @@ -246,7 +256,14 @@ change in the serialization of this data structure.
}

// Check that we can deserialize from the reference binary object.
let parsed: T = Serializer::deserialize(&expected).unwrap();
// todo: (ab) cleanup
let parsed: T = match version {
"v1" => V1Serializer::deserialize(&expected).unwrap(),
"v2" => V2Serializer::deserialize(&expected).unwrap(),
"v3" => V3Serializer::deserialize(&expected).unwrap(),
_ => panic!("invalid version"),
};

assert_eq!(
*reference, parsed,
"Reference object commitment does not match commitment of parsed binary object. This is
Expand Down Expand Up @@ -320,12 +337,22 @@ fn test_reference_l1_block() {
}

#[test]
fn test_reference_chain_config() {
fn test_reference_v1_chain_config() {
reference_test(
"v1",
"chain_config",
v0_1::ChainConfig::from(reference_chain_config()),
REFERENCE_V1_CHAIN_CONFIG_COMMITMENT,
);
}

#[test]
fn test_reference_v3_chain_config() {
reference_test(
"v3",
"chain_config",
reference_chain_config(),
REFERENCE_CHAIN_CONFIG_COMMITMENT,
REFERENCE_V3_CHAIN_CONFIG_COMMITMENT,
);
}

Expand All @@ -340,29 +367,34 @@ fn test_reference_fee_info() {
}

#[async_std::test]
async fn test_reference_header() {
async fn test_reference_header_v1() {
reference_test(
"v1",
"header",
reference_header(StaticVersion::<0, 1>::version()).await,
REFERENCE_V1_HEADER_COMMITMENT,
);
}

#[async_std::test]
async fn test_reference_header_v2() {
reference_test(
"v2",
"header",
reference_header(StaticVersion::<0, 2>::version()).await,
REFERENCE_V2_HEADER_COMMITMENT,
);
}

#[async_std::test]
async fn test_reference_header_v3() {
reference_test(
"v3",
"header",
reference_header(StaticVersion::<0, 3>::version()).await,
REFERENCE_V3_HEADER_COMMITMENT,
);
}

#[test]
fn test_reference_transaction() {
reference_test(
Expand Down

0 comments on commit d4af112

Please sign in to comment.