Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen-stig committed Aug 14, 2023
1 parent cb24fc9 commit f2e197d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
1 change: 0 additions & 1 deletion examples/demo-stf/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub fn create_new_demo(
sov_rollup_interface::mocks::MockZkvm,
Runtime<DefaultContext>,
TestBlob,
Address,
> {
let runtime = Runtime::default();
let storage = ProverStorage::with_path(path).unwrap();
Expand Down
7 changes: 5 additions & 2 deletions examples/demo-stf/src/tests/tx_revert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand All @@ -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"
Expand Down Expand Up @@ -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();
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ impl<C: Context, Cond: ValidityCondition> SlotHooks<Cond> for TestRuntime<C, Con
fn end_slot_hook(&self, _working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>) {}
}

impl<C: Context, Cond: ValidityCondition> Runtime<C, Cond> for TestRuntime<C, Cond> {}
impl<C: Context, Cond: ValidityCondition, B: BlobReaderTrait> Runtime<C, Cond, B>
for TestRuntime<C, Cond>
{
}

pub(crate) fn create_demo_genesis_config<C: Context, Cond: ValidityCondition>(
admin: <C as Spec>::Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
<SequencerRegistry<C> as ApplyBlobHooks<TestBlob<Address>>>::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
Expand Down Expand Up @@ -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();
<SequencerRegistry<C> as ApplyBlobHooks<TestBlob<Address>>>::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());
Expand Down Expand Up @@ -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();
<SequencerRegistry<C> as ApplyBlobHooks<TestBlob<Address>>>::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());
Expand Down Expand Up @@ -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();
<SequencerRegistry<C> as ApplyBlobHooks<TestBlob<Address>>>::end_blob_hook(
&test_sequencer.registry,
result,
working_set,
)
.unwrap();

let resp = test_sequencer
.registry
Expand Down
8 changes: 4 additions & 4 deletions rollup-interface/src/state_machine/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,17 @@ impl<Address: AddressTrait> BlobReaderTrait for TestBlob<Address> {
self.address.clone()
}

fn hash(&self) -> [u8; 32] {
self.hash
}

fn data_mut(&mut self) -> &mut CountedBufReader<Self::Data> {
&mut self.data
}

fn data(&self) -> &CountedBufReader<Self::Data> {
&self.data
}

fn hash(&self) -> [u8; 32] {
self.hash
}
}

impl<Address: AddressTrait> TestBlob<Address> {
Expand Down

0 comments on commit f2e197d

Please sign in to comment.