From f2e197d23a3b157cb082cfd46da2981028cdacec Mon Sep 17 00:00:00 2001 From: Nikolai Golub Date: Mon, 14 Aug 2023 14:06:50 +0200 Subject: [PATCH] Update tests --- examples/demo-stf/src/tests/mod.rs | 1 - .../demo-stf/src/tests/tx_revert_tests.rs | 7 +++- .../src/chain_state/helpers.rs | 5 ++- .../tests/hooks_test.rs | 40 +++++++++++-------- rollup-interface/src/state_machine/mocks.rs | 8 ++-- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/examples/demo-stf/src/tests/mod.rs b/examples/demo-stf/src/tests/mod.rs index 88061c065c..0bb81faf76 100644 --- a/examples/demo-stf/src/tests/mod.rs +++ b/examples/demo-stf/src/tests/mod.rs @@ -23,7 +23,6 @@ pub fn create_new_demo( sov_rollup_interface::mocks::MockZkvm, Runtime, TestBlob, - Address, > { let runtime = Runtime::default(); let storage = ProverStorage::with_path(path).unwrap(); diff --git a/examples/demo-stf/src/tests/tx_revert_tests.rs b/examples/demo-stf/src/tests/tx_revert_tests.rs index 7c60fa3164..1d1085a02a 100644 --- a/examples/demo-stf/src/tests/tx_revert_tests.rs +++ b/examples/demo-stf/src/tests/tx_revert_tests.rs @@ -7,6 +7,7 @@ use sov_modules_api::default_signature::private_key::DefaultPrivateKey; use sov_modules_api::transaction::Transaction; use sov_modules_api::{EncodeCall, PrivateKey, PublicKey}; use sov_modules_stf_template::{Batch, RawTx, SequencerOutcome, SlashingReason}; +use sov_rollup_interface::da::BlobReaderTrait; use sov_rollup_interface::mocks::{MockZkvm, TestBlock}; use sov_rollup_interface::stf::StateTransitionFunction; use sov_state::{ProverStorage, WorkingSet}; @@ -231,6 +232,7 @@ fn test_tx_bad_sig() { let txs = simulate_da_with_bad_sig(election_admin_private_key); let blob = new_test_blob_from_batch(Batch { txs }, &DEMO_SEQUENCER_DA_ADDRESS, [0; 32]); + let blob_sender = blob.sender(); let mut blobs = [blob]; let data = TestBlock::default(); @@ -247,7 +249,7 @@ fn test_tx_bad_sig() { assert_eq!( SequencerOutcome::Slashed{ reason:SlashingReason::StatelessVerificationFailed, - sequencer_da_address: DEMO_SEQUENCER_DA_ADDRESS.to_vec(), + sequencer_da_address: blob_sender, }, apply_blob_outcome.inner, "Unexpected outcome: Stateless verification should have failed due to invalid signature" @@ -315,6 +317,7 @@ fn test_tx_bad_serialization() { let txs = simulate_da_with_bad_serialization(election_admin_private_key); let blob = new_test_blob_from_batch(Batch { txs }, &DEMO_SEQUENCER_DA_ADDRESS, [0; 32]); + let blob_sender = blob.sender(); let mut blobs = [blob]; let data = TestBlock::default(); @@ -331,7 +334,7 @@ fn test_tx_bad_serialization() { assert_eq!( SequencerOutcome::Slashed { reason: SlashingReason::InvalidTransactionEncoding , - sequencer_da_address: DEMO_SEQUENCER_DA_ADDRESS.to_vec(), + sequencer_da_address: blob_sender, }, apply_blob_outcome.inner, "Unexpected outcome: Stateless verification should have failed due to invalid signature" diff --git a/module-system/module-implementations/integration-tests/src/chain_state/helpers.rs b/module-system/module-implementations/integration-tests/src/chain_state/helpers.rs index c16e5aeb3d..3aa857e55d 100644 --- a/module-system/module-implementations/integration-tests/src/chain_state/helpers.rs +++ b/module-system/module-implementations/integration-tests/src/chain_state/helpers.rs @@ -75,7 +75,10 @@ impl SlotHooks for TestRuntime::Storage>) {} } -impl Runtime for TestRuntime {} +impl Runtime + for TestRuntime +{ +} pub(crate) fn create_demo_genesis_config( admin: ::Address, diff --git a/module-system/module-implementations/sov-sequencer-registry/tests/hooks_test.rs b/module-system/module-implementations/sov-sequencer-registry/tests/hooks_test.rs index ec9dc469df..5c7e60a8ab 100644 --- a/module-system/module-implementations/sov-sequencer-registry/tests/hooks_test.rs +++ b/module-system/module-implementations/sov-sequencer-registry/tests/hooks_test.rs @@ -86,10 +86,12 @@ fn end_blob_hook_success() { .begin_blob_hook(&mut test_blob, working_set) .unwrap(); - test_sequencer - .registry - .end_blob_hook(SequencerOutcome::Completed, working_set) - .unwrap(); + as ApplyBlobHooks>>::end_blob_hook( + &test_sequencer.registry, + SequencerOutcome::Completed, + working_set, + ) + .unwrap(); let resp = test_sequencer.query_balance_via_bank(working_set).unwrap(); assert_eq!(balance_after_genesis, resp.amount.unwrap()); let resp = test_sequencer @@ -125,10 +127,12 @@ fn end_blob_hook_slash() { let result = SequencerOutcome::Slashed { sequencer: GENESIS_SEQUENCER_DA_ADDRESS.to_vec(), }; - test_sequencer - .registry - .end_blob_hook(result, working_set) - .unwrap(); + as ApplyBlobHooks>>::end_blob_hook( + &test_sequencer.registry, + result, + working_set, + ) + .unwrap(); let resp = test_sequencer.query_balance_via_bank(working_set).unwrap(); assert_eq!(balance_after_genesis, resp.amount.unwrap()); @@ -184,10 +188,12 @@ fn end_blob_hook_slash_preferred_sequencer() { let result = SequencerOutcome::Slashed { sequencer: GENESIS_SEQUENCER_DA_ADDRESS.to_vec(), }; - test_sequencer - .registry - .end_blob_hook(result, working_set) - .unwrap(); + as ApplyBlobHooks>>::end_blob_hook( + &test_sequencer.registry, + result, + working_set, + ) + .unwrap(); let resp = test_sequencer.query_balance_via_bank(working_set).unwrap(); assert_eq!(balance_after_genesis, resp.amount.unwrap()); @@ -230,10 +236,12 @@ fn end_blob_hook_slash_unknown_sequencer() { let result = SequencerOutcome::Slashed { sequencer: UNKNOWN_SEQUENCER_DA_ADDRESS.to_vec(), }; - test_sequencer - .registry - .end_blob_hook(result, working_set) - .unwrap(); + as ApplyBlobHooks>>::end_blob_hook( + &test_sequencer.registry, + result, + working_set, + ) + .unwrap(); let resp = test_sequencer .registry diff --git a/rollup-interface/src/state_machine/mocks.rs b/rollup-interface/src/state_machine/mocks.rs index ebdbf79268..42bfc24b79 100644 --- a/rollup-interface/src/state_machine/mocks.rs +++ b/rollup-interface/src/state_machine/mocks.rs @@ -249,10 +249,6 @@ impl BlobReaderTrait for TestBlob
{ self.address.clone() } - fn hash(&self) -> [u8; 32] { - self.hash - } - fn data_mut(&mut self) -> &mut CountedBufReader { &mut self.data } @@ -260,6 +256,10 @@ impl BlobReaderTrait for TestBlob
{ fn data(&self) -> &CountedBufReader { &self.data } + + fn hash(&self) -> [u8; 32] { + self.hash + } } impl TestBlob
{