Skip to content

Commit

Permalink
test: reference_tests use nontrivial payload, ns_table (#1557)
Browse files Browse the repository at this point in the history
reference_tests use nontrivial payload, ns_table
  • Loading branch information
ggutoski authored Jun 5, 2024
1 parent ae157c2 commit 00dfef7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
Binary file modified data/header.bin
Binary file not shown.
14 changes: 7 additions & 7 deletions data/header.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"block_merkle_tree_root": "MERKLE_COMM~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAQA",
"builder_commitment": "BUILDER_COMMITMENT~PfISPEAHYbCXqJ08RqlK74d9aSrtrZkKHdnoX7crymG5",
"builder_commitment": "BUILDER_COMMITMENT~upd4eFij7NNHTMYiVQoL-hDBw3bJiOMmCoNJxxgGwJ6h",
"builder_signature": {
"r": "0xca39647d5e159ebf62e0efd163ddb2b7946f437948e6c31accdb5360a9f2da17",
"s": "0x610e51dced89ede20e3dcc5e9e26fff580738e785371df53389f2f84dadbdb87",
"v": 28
"r": "0xc7b7c4062ada11d09530d759af4f2d9d84dd2d1ca6117299dee9b36e039642b6",
"s": "0x10cc3c7c0d0d69ba19348c720ee95cbb48470b9181cc32c9922af86b83fba9a2",
"v": 27
},
"chain_config": {
"chain_config": {
Expand All @@ -30,8 +30,8 @@
},
"l1_head": 124,
"ns_table": {
"bytes": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"bytes": "AQAAAO7/wAAIBAAA"
},
"payload_commitment": "HASH~AazstQer_ho1SqgGT0r10_Gs0BnjfbPBHJdSO3HHbp29",
"payload_commitment": "HASH~Ojg3e_G9UzTwOygEDDcbvgakaVCqMByIiFrlkLXT72qf",
"timestamp": 789
}
}
Binary file modified data/ns_table.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions data/ns_table.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"bytes": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
}
"bytes": "AQAAAO7/wAAIBAAA"
}
1 change: 1 addition & 0 deletions sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ required-features = ["testing"]
escargot = "0.5.10"
espresso-macros = { git = "https://github.com/EspressoSystems/espresso-macros.git", tag = "0.1.0" }
hotshot-query-service = { workspace = true, features = ["testing"] }
hotshot-testing = { workspace = true }
pretty_assertions = { workspace = true }
rand = "0.8.5"
reqwest = { workspace = true }
Expand Down
52 changes: 33 additions & 19 deletions sequencer/src/reference_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
use crate::{
block::tables::NameSpaceTable, state::FeeInfo, ChainConfig, FeeAccount, Header, L1BlockInfo,
Payload, SeqTypes, Transaction, TxTableEntryWord, ValidatedState,
Payload, Transaction, TxTableEntryWord, ValidatedState,
};
use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
use committable::Committable;
use es_version::SequencerVersion;
use hotshot_types::traits::{
block_contents::vid_commitment, block_contents::TestableBlock,
signature_key::BuilderSignatureKey, BlockPayload, EncodeBytes,
block_contents::vid_commitment, signature_key::BuilderSignatureKey, BlockPayload, EncodeBytes,
};
use jf_merkle_tree::MerkleTreeScheme;
use pretty_assertions::assert_eq;
Expand All @@ -42,11 +41,22 @@ use vbs::BinarySerializer;

type Serializer = vbs::Serializer<SequencerVersion>;

fn reference_ns_table() -> NameSpaceTable<TxTableEntryWord> {
NameSpaceTable::from_bytes([0; 48])
async fn reference_payload() -> Payload<TxTableEntryWord> {
Payload::from_transactions(
vec![reference_transaction()],
&Default::default(),
&Default::default(),
)
.await
.unwrap()
.0
}

async fn reference_ns_table() -> NameSpaceTable<TxTableEntryWord> {
reference_payload().await.get_ns_table().clone()
}

const REFERENCE_NS_TABLE_COMMITMENT: &str = "NSTABLE~GL-lEBAwNZDldxDpySRZQChNnmn9vNzdIAL8W9ENOuh_";
const REFERENCE_NS_TABLE_COMMITMENT: &str = "NSTABLE~jqBfNUW1lSijWpKpPNc9yxQs28YckB80gFJWnHIwOQMC";

fn reference_l1_block() -> L1BlockInfo {
L1BlockInfo {
Expand Down Expand Up @@ -82,17 +92,17 @@ fn reference_fee_info() -> FeeInfo {

const REFERENCE_FEE_INFO_COMMITMENT: &str = "FEE_INFO~xCCeTjJClBtwtOUrnAmT65LNTQGceuyjSJHUFfX6VRXR";

fn reference_header() -> Header {
async fn reference_header() -> Header {
let builder_key = FeeAccount::generated_from_seed_indexed(Default::default(), 0).1;
let fee_info = reference_fee_info();
let ns_table = reference_ns_table();
let payload = <Payload<_> as TestableBlock<SeqTypes>>::genesis();
let payload = reference_payload().await;
let ns_table = payload.get_ns_table();
let payload_commitment = vid_commitment(&payload.encode(), 1);
let builder_commitment = payload.builder_commitment(&ns_table);
let builder_commitment = payload.builder_commitment(ns_table);
let builder_signature = FeeAccount::sign_fee(
&builder_key,
fee_info.amount().as_u64().unwrap(),
&ns_table,
ns_table,
&payload_commitment,
)
.unwrap();
Expand All @@ -106,7 +116,7 @@ fn reference_header() -> Header {
l1_finalized: Some(reference_l1_block()),
payload_commitment,
builder_commitment,
ns_table,
ns_table: ns_table.clone(),
block_merkle_tree_root: state.block_merkle_tree.commitment(),
fee_merkle_tree_root: state.fee_merkle_tree.commitment(),
fee_info,
Expand All @@ -115,7 +125,7 @@ fn reference_header() -> Header {
}
}

const REFERENCE_HEADER_COMMITMENT: &str = "BLOCK~6Ol30XYkdKaNFXw0QAkcif18Lk8V8qkC4M81qTlwL707";
const REFERENCE_HEADER_COMMITMENT: &str = "BLOCK~mHlaknD1qKCz0UBtV2GpnqfO6gFqF5yN-9qkmLMRG3rp";

fn reference_transaction() -> Transaction {
let payload: [u8; 1024] = std::array::from_fn(|i| (i % (u8::MAX as usize)) as u8);
Expand Down Expand Up @@ -230,11 +240,11 @@ Actual: {actual}
);
}

#[test]
fn test_reference_ns_table() {
#[async_std::test]
async fn test_reference_ns_table() {
reference_test(
"ns_table",
reference_ns_table(),
reference_ns_table().await,
REFERENCE_NS_TABLE_COMMITMENT,
);
}
Expand Down Expand Up @@ -266,9 +276,13 @@ fn test_reference_fee_info() {
);
}

#[test]
fn test_reference_header() {
reference_test("header", reference_header(), REFERENCE_HEADER_COMMITMENT);
#[async_std::test]
async fn test_reference_header() {
reference_test(
"header",
reference_header().await,
REFERENCE_HEADER_COMMITMENT,
);
}

#[test]
Expand Down

0 comments on commit 00dfef7

Please sign in to comment.