Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust cache for cargo #439

Merged
merged 11 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ jobs:
RUSTC_WRAPPER: "sccache"
steps:
- uses: actions/checkout@v3
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
with:
version: "v0.4.0"
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- name: Run lint
run: |
if ! make lint ; then
Expand All @@ -45,10 +43,8 @@ jobs:
RUSTC_WRAPPER: "sccache"
steps:
- uses: actions/checkout@v3
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
with:
version: "v0.4.0"
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- name: Run cargo check
run: cd examples/demo-prover && cargo check
- name: Run cargo fmt check
Expand All @@ -69,8 +65,8 @@ jobs:
RUSTC_WRAPPER: "sccache"
steps:
- uses: actions/checkout@v3
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- name: cargo install cargo-hack
uses: taiki-e/install-action@cargo-hack
# intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4
Expand All @@ -83,10 +79,8 @@ jobs:
RUSTC_WRAPPER: "sccache"
steps:
- uses: actions/checkout@v3
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
with:
version: "v0.4.0"
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- name: Run cargo test
run: cargo test
coverage:
Expand All @@ -100,8 +94,8 @@ jobs:
submodules: true
- name: add llvm component
run: rustup component add llvm-tools-preview
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- uses: Swatinem/rust-cache@v2
- uses: mozilla-actions/[email protected]
- name: cargo install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: cargo generate-lockfile
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clean: ## Cleans compiled
@cargo clean

test: ## Runs test suite with output from tests printed
@cargo test -- --nocapture
@cargo test -- --nocapture -Zunstable-options --report-time

install-dev-tools: ## Installs all necessary cargo helpers
cargo install cargo-llvm-cov
Expand Down
26 changes: 15 additions & 11 deletions examples/demo-stf/src/tests/stf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ pub mod test {
None,
);

assert!(
matches!(apply_blob_outcome.inner, SequencerOutcome::Rewarded(0),),
assert_eq!(
SequencerOutcome::Rewarded(0),
apply_blob_outcome.inner,
"Sequencer execution should have succeeded but failed "
);

Expand Down Expand Up @@ -97,9 +98,10 @@ pub mod test {
None,
);

assert!(
matches!(apply_blob_outcome.inner, SequencerOutcome::Rewarded(0),),
"Sequencer execution should have succeeded but failed "
assert_eq!(
SequencerOutcome::Rewarded(0),
apply_blob_outcome.inner,
"Sequencer execution should have succeeded but failed"
);

assert!(has_tx_events(&apply_blob_outcome),);
Expand Down Expand Up @@ -151,9 +153,10 @@ pub mod test {
None,
)
.inner;
assert!(
matches!(apply_blob_outcome, SequencerOutcome::Rewarded(0),),
"Sequencer execution should have succeeded but failed "
assert_eq!(
SequencerOutcome::Rewarded(0),
apply_blob_outcome,
"Sequencer execution should have succeeded but failed",
);
}

Expand Down Expand Up @@ -197,15 +200,16 @@ pub mod test {

let txs = simulate_da(value_setter_admin_private_key, election_admin_private_key);

let some_sequencer: [u8; 32] = [101; 32];
let some_sequencer: [u8; 32] = [121; 32];
let apply_blob_outcome = StateTransitionFunction::<MockZkvm>::apply_blob(
&mut demo,
&mut new_test_blob(Batch { txs }, &some_sequencer),
None,
);

assert!(
matches!(apply_blob_outcome.inner, SequencerOutcome::Ignored),
assert_eq!(
SequencerOutcome::Ignored,
apply_blob_outcome.inner,
"Batch should have been skipped due to unknown sequencer"
);

Expand Down
4 changes: 2 additions & 2 deletions module-system/sov-modules-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ path = "tests/all_tests.rs"

[dev-dependencies]
trybuild = "1.0"
sov-modules-api = { path = "../sov-modules-api", version = "0.1" }
sov-modules-api = { path = "../sov-modules-api", version = "0.1", default-features = false }
jsonrpsee = { workspace = true, features = ["macros", "http-client", "server"] }
sov-state = { path = "../sov-state", version = "0.1" }
sov-state = { path = "../sov-state", version = "0.1", default-features = false }
tempfile = { workspace = true }

[dependencies]
Expand Down
29 changes: 15 additions & 14 deletions module-system/sov-modules-macros/tests/derive_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_context::ZkDefaultContext;
use sov_modules_api::Context;
use sov_modules_macros::rpc_gen;
use sov_modules_macros::ModuleInfo;
use sov_state::{ProverStorage, WorkingSet};
use sov_state::{WorkingSet, ZkStorage};

#[derive(ModuleInfo)]
pub struct TestStruct<C: ::sov_modules_api::Context> {
Expand Down Expand Up @@ -33,7 +33,7 @@ impl<C: sov_modules_api::Context> TestStruct<C> {
}
}

pub struct TestRuntime<C: sov_modules_api::Context> {
pub struct TestRuntime<C: Context> {
test_struct: TestStruct<C>,
}

Expand All @@ -43,53 +43,54 @@ struct RpcStorage<C: Context> {
pub storage: C::Storage,
}

impl TestStructRpcImpl<DefaultContext> for RpcStorage<DefaultContext> {
impl TestStructRpcImpl<ZkDefaultContext> for RpcStorage<ZkDefaultContext> {
fn get_working_set(
&self,
) -> ::sov_state::WorkingSet<<DefaultContext as ::sov_modules_api::Spec>::Storage> {
) -> ::sov_state::WorkingSet<<ZkDefaultContext as ::sov_modules_api::Spec>::Storage> {
::sov_state::WorkingSet::new(self.storage.clone())
}
}

fn main() {
let tmpdir = tempfile::tempdir().unwrap();
let native_storage = ProverStorage::with_path(tmpdir.path()).unwrap();
let r: RpcStorage<DefaultContext> = RpcStorage {
storage: native_storage.clone(),
let storage = ZkStorage::new([1u8; 32]);
let r: RpcStorage<ZkDefaultContext> = RpcStorage {
storage: storage.clone(),
};
{
let result =
<RpcStorage<DefaultContext> as TestStructRpcServer<DefaultContext>>::first_method(&r);
<RpcStorage<ZkDefaultContext> as TestStructRpcServer<ZkDefaultContext>>::first_method(
&r,
);
assert_eq!(result.unwrap(), 11);
}

{
let result =
<RpcStorage<DefaultContext> as TestStructRpcServer<DefaultContext>>::second_method(
<RpcStorage<ZkDefaultContext> as TestStructRpcServer<ZkDefaultContext>>::second_method(
&r, 22,
);
assert_eq!(result.unwrap(), 22);
}

{
let result =
<RpcStorage<DefaultContext> as TestStructRpcServer<DefaultContext>>::third_method(
<RpcStorage<ZkDefaultContext> as TestStructRpcServer<ZkDefaultContext>>::third_method(
&r, 33,
);
assert_eq!(result.unwrap(), 33);
}

{
let result =
<RpcStorage<DefaultContext> as TestStructRpcServer<DefaultContext>>::fourth_method(
<RpcStorage<ZkDefaultContext> as TestStructRpcServer<ZkDefaultContext>>::fourth_method(
&r, 44,
);
assert_eq!(result.unwrap(), 44);
}

{
let result =
<RpcStorage<DefaultContext> as TestStructRpcServer<DefaultContext>>::health(&r);
<RpcStorage<ZkDefaultContext> as TestStructRpcServer<ZkDefaultContext>>::health(&r);
assert_eq!(result.unwrap(), ());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ mod modules;
use modules::{first_test_module, second_test_module};
use sov_modules_api::Address;
use sov_modules_api::ModuleInfo;
use sov_modules_api::{default_context::DefaultContext, Context, Genesis};
use sov_modules_api::{default_context::ZkDefaultContext, Context, Genesis};
use sov_modules_macros::{DefaultRuntime, DispatchCall, Genesis, MessageCodec};
use sov_state::ProverStorage;
use sov_state::ZkStorage;

#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)]
#[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)]
Expand All @@ -15,15 +15,14 @@ struct Runtime<C: Context> {

fn main() {
use sov_modules_api::DispatchCall;
type RT = Runtime<DefaultContext>;
type RT = Runtime<ZkDefaultContext>;
let runtime = &mut RT::default();

let tmpdir = tempfile::tempdir().unwrap();
let storage = ProverStorage::with_path(tmpdir.path()).unwrap();
let storage = ZkStorage::new([1u8; 32]);
let mut working_set = &mut sov_state::WorkingSet::new(storage);
let config = GenesisConfig::new((), ());
runtime.genesis(&config, working_set).unwrap();
let context = DefaultContext::new(Address::try_from([0; 32].as_ref()).unwrap());
let context = ZkDefaultContext::new(Address::try_from([0; 32].as_ref()).unwrap());

let value = 11;
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod modules;

use modules::{first_test_module, second_test_module};
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_context::ZkDefaultContext;
use sov_modules_api::Context;
use sov_modules_macros::{DefaultRuntime, DispatchCall, Genesis, MessageCodec};
use sov_state::ProverStorage;
use sov_state::ZkStorage;

// Debugging hint: To expand the macro in tests run: `cargo expand --test tests`
#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)]
Expand All @@ -20,9 +20,8 @@ where
fn main() {
use sov_modules_api::Genesis;

type C = DefaultContext;
let tmpdir = tempfile::tempdir().unwrap();
let storage = ProverStorage::with_path(tmpdir.path()).unwrap();
type C = ZkDefaultContext;
let storage = ZkStorage::new([1u8; 32]);
let mut working_set = &mut sov_state::WorkingSet::new(storage);
let runtime = &mut Runtime::<C>::default();
let config = GenesisConfig::new((), ());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_context::ZkDefaultContext;
use sov_modules_api::Context;
use sov_modules_macros::ModuleInfo;
use sov_state::StateMap;
Expand Down Expand Up @@ -39,7 +39,7 @@ mod second_test_module {
}

fn main() {
type C = DefaultContext;
type C = ZkDefaultContext;
let second_test_struct =
<second_test_module::SecondTestStruct<C> as std::default::Default>::default();

Expand Down
4 changes: 2 additions & 2 deletions module-system/sov-modules-macros/tests/module_info/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_context::ZkDefaultContext;
use sov_modules_api::{Context, ModuleInfo};
use sov_modules_macros::ModuleInfo;
use sov_state::{StateMap, StateValue};
Expand All @@ -25,7 +25,7 @@ mod test_module {
}

fn main() {
type C = DefaultContext;
type C = ZkDefaultContext;
let test_struct = <test_module::TestStruct<C> as std::default::Default>::default();

let prefix1 = test_struct.test_state1.prefix();
Expand Down
1 change: 0 additions & 1 deletion module-system/sov-state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ readme = "README.md"
resolver = "2"

[dependencies]

anyhow = { workspace = true }
borsh = { workspace = true }
serde = { workspace = true }
Expand Down