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

sov-modules: Ensure that the internal structure of modules implementation is private. #541

Merged
merged 11 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions examples/demo-nft-module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ simplicity, each token represents only an ID and won't hold any metadata.
### Structure and dependencies

The Sovereign SDK provides a [module-template](../../module-system/module-implementations/module-template/README.md),
which is boilerplate that can be customised to easily build modules.
which is boilerplate that can be customized to easily build modules.

```

Expand Down Expand Up @@ -377,8 +377,8 @@ sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branc
Here is some boilerplate for NFT module integration tests:

```rust
use demo_nft_module::call::CallMessage;
use demo_nft_module::query::OwnerResponse;
use demo_nft_module::CallMessage;
use demo_nft_module::OwnerResponse;
use demo_nft_module::{NonFungibleToken, NonFungibleTokenConfig};
use serde::de::DeserializeOwned;
use sov_modules_api::default_context::DefaultContext;
Expand Down
8 changes: 7 additions & 1 deletion examples/demo-prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 15 additions & 18 deletions examples/demo-rollup/src/rng_xfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use borsh::ser::BorshSerialize;
use const_rollup_config::SEQUENCER_DA_ADDRESS;
use demo_stf::runtime::Runtime;
use jupiter::verifier::address::CelestiaAddress;
use sov_bank::call::CallMessage;
use sov_bank::Coins;
use sov_bank::{CallMessage, Coins};
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::transaction::Transaction;
Expand All @@ -31,14 +30,13 @@ fn generate_transfers(n: usize, start_nonce: u64) -> Vec<u8> {
let priv_key = DefaultPrivateKey::generate();
let address: <DefaultContext as Spec>::Address = priv_key.pub_key().to_address();
let pk = DefaultPrivateKey::from_hex("236e80cb222c4ed0431b093b3ac53e6aa7a2273fe1f4351cd354989a823432a27b758bf2e7670fafaf6bf0015ce0ff5aa802306fc7e3f45762853ffc37180fe6").unwrap();
let msg: sov_bank::call::CallMessage<DefaultContext> =
CallMessage::<DefaultContext>::Transfer {
to: address,
coins: Coins {
amount: 1,
token_address: token_address.clone(),
},
};
let msg: sov_bank::CallMessage<DefaultContext> = CallMessage::<DefaultContext>::Transfer {
to: address,
coins: Coins {
amount: 1,
token_address: token_address.clone(),
},
};
let enc_msg = Runtime::<DefaultContext>::encode_bank_call(msg);
let tx =
Transaction::<DefaultContext>::new_signed_tx(&pk, enc_msg, start_nonce + (i as u64));
Expand All @@ -58,14 +56,13 @@ fn generate_create(start_nonce: u64) -> Vec<u8> {
AddressBech32::try_from(sender_address)
.unwrap_or_else(|_e| panic!("Failed generating token create transaction")),
);
let msg: sov_bank::call::CallMessage<DefaultContext> =
CallMessage::<DefaultContext>::CreateToken {
salt: 11,
token_name: "sov-test-token".to_string(),
initial_balance: 100000000,
minter_address: minter_address.clone(),
authorized_minters: vec![minter_address],
};
let msg: sov_bank::CallMessage<DefaultContext> = CallMessage::<DefaultContext>::CreateToken {
salt: 11,
token_name: "sov-test-token".to_string(),
initial_balance: 100000000,
minter_address: minter_address.clone(),
authorized_minters: vec![minter_address],
};
let enc_msg = Runtime::<DefaultContext>::encode_bank_call(msg);
let tx = Transaction::<DefaultContext>::new_signed_tx(&pk, enc_msg, start_nonce);
let ser_tx = tx.try_to_vec().unwrap();
Expand Down
3 changes: 1 addition & 2 deletions examples/demo-stf/src/batch_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ mod tests {
use sov_modules_macros::{DefaultRuntime, DispatchCall, Genesis, MessageCodec};
use sov_rollup_interface::services::batch_builder::BatchBuilder;
use sov_state::{DefaultStorageSpec, ProverStorage, Storage};
use sov_value_setter::call::CallMessage;
use sov_value_setter::ValueSetterConfig;
use sov_value_setter::{CallMessage, ValueSetterConfig};
use tempfile::TempDir;

use super::*;
Expand Down
10 changes: 5 additions & 5 deletions examples/demo-stf/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(feature = "native")]
use sov_accounts::query::{AccountsRpcImpl, AccountsRpcServer};
use sov_accounts::{AccountsRpcImpl, AccountsRpcServer};
#[cfg(feature = "native")]
use sov_bank::query::{BankRpcImpl, BankRpcServer};
use sov_bank::{BankRpcImpl, BankRpcServer};
#[cfg(feature = "native")]
use sov_election::query::{ElectionRpcImpl, ElectionRpcServer};
use sov_election::{ElectionRpcImpl, ElectionRpcServer};
#[cfg(feature = "native")]
#[cfg(feature = "experimental")]
use sov_evm::query::{EvmRpcImpl, EvmRpcServer};
Expand All @@ -14,9 +14,9 @@ use sov_modules_api::Context;
use sov_modules_macros::{cli_parser, expose_rpc};
use sov_modules_macros::{DefaultRuntime, DispatchCall, Genesis, MessageCodec};
#[cfg(feature = "native")]
use sov_sequencer_registry::query::{SequencerRegistryRpcImpl, SequencerRegistryRpcServer};
use sov_sequencer_registry::{SequencerRegistryRpcImpl, SequencerRegistryRpcServer};
#[cfg(feature = "native")]
use sov_value_setter::query::{ValueSetterRpcImpl, ValueSetterRpcServer};
use sov_value_setter::{ValueSetterRpcImpl, ValueSetterRpcServer};

/// The Rollup entrypoint.
///
Expand Down
26 changes: 13 additions & 13 deletions examples/demo-stf/src/tests/data_generation/election_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ impl CallGenerator {
&mut self,
) -> Vec<(
Rc<DefaultPrivateKey>,
sov_election::call::CallMessage<DefaultContext>,
sov_election::CallMessage<DefaultContext>,
u64,
)> {
let mut messages = Vec::default();

let set_candidates_message = sov_election::call::CallMessage::SetCandidates {
let set_candidates_message = sov_election::CallMessage::SetCandidates {
names: vec!["candidate_1".to_owned(), "candidate_2".to_owned()],
};

Expand All @@ -50,15 +50,15 @@ impl CallGenerator {

for voter in self.voters.clone() {
let add_voter_message =
sov_election::call::CallMessage::AddVoter(voter.pub_key().to_address());
sov_election::CallMessage::AddVoter(voter.pub_key().to_address());

messages.push((
self.election_admin.clone(),
add_voter_message,
self.election_admin_nonce,
));

let vote_message = sov_election::call::CallMessage::Vote(1);
let vote_message = sov_election::CallMessage::Vote(1);
messages.push((voter, vote_message, 0));
self.inc_nonce();
}
Expand All @@ -70,12 +70,12 @@ impl CallGenerator {
&mut self,
) -> Vec<(
Rc<DefaultPrivateKey>,
sov_election::call::CallMessage<DefaultContext>,
sov_election::CallMessage<DefaultContext>,
u64,
)> {
let mut messages = Vec::default();

let freeze_message = sov_election::call::CallMessage::FreezeElection;
let freeze_message = sov_election::CallMessage::FreezeElection;
messages.push((
self.election_admin.clone(),
freeze_message,
Expand All @@ -90,7 +90,7 @@ impl CallGenerator {
&mut self,
) -> Vec<(
Rc<DefaultPrivateKey>,
sov_election::call::CallMessage<DefaultContext>,
sov_election::CallMessage<DefaultContext>,
u64,
)> {
let mut messages = Vec::default();
Expand All @@ -114,7 +114,7 @@ impl ElectionCallMessages {
}

impl MessageGenerator for ElectionCallMessages {
type Call = sov_election::call::CallMessage<DefaultContext>;
type Call = sov_election::CallMessage<DefaultContext>;

fn create_messages(&self) -> Vec<(Rc<DefaultPrivateKey>, Self::Call, u64)> {
let call_generator = &mut CallGenerator::new(self.election_admin.clone());
Expand Down Expand Up @@ -146,7 +146,7 @@ impl InvalidElectionCallMessages {
}

impl MessageGenerator for InvalidElectionCallMessages {
type Call = sov_election::call::CallMessage<DefaultContext>;
type Call = sov_election::CallMessage<DefaultContext>;

fn create_messages(&self) -> Vec<(Rc<DefaultPrivateKey>, Self::Call, u64)> {
let call_generator = &mut CallGenerator::new(self.election_admin.clone());
Expand All @@ -158,7 +158,7 @@ impl MessageGenerator for InvalidElectionCallMessages {
// Additional invalid message: This voter already voted.
{
let voter = call_generator.voters[0].clone();
let vote_message = sov_election::call::CallMessage::Vote(1);
let vote_message = sov_election::CallMessage::Vote(1);
messages.push((voter, vote_message, 1));
}

Expand Down Expand Up @@ -191,7 +191,7 @@ impl BadSigElectionCallMessages {
}

impl MessageGenerator for BadSigElectionCallMessages {
type Call = sov_election::call::CallMessage<DefaultContext>;
type Call = sov_election::CallMessage<DefaultContext>;

fn create_messages(&self) -> Vec<(Rc<DefaultPrivateKey>, Self::Call, u64)> {
let call_generator = &mut CallGenerator::new(self.election_admin.clone());
Expand Down Expand Up @@ -234,7 +234,7 @@ impl BadNonceElectionCallMessages {
}

impl MessageGenerator for BadNonceElectionCallMessages {
type Call = sov_election::call::CallMessage<DefaultContext>;
type Call = sov_election::CallMessage<DefaultContext>;

fn create_messages(&self) -> Vec<(Rc<DefaultPrivateKey>, Self::Call, u64)> {
let call_generator = &mut CallGenerator::new(self.election_admin.clone());
Expand Down Expand Up @@ -268,7 +268,7 @@ impl BadSerializationElectionCallMessages {
}

impl MessageGenerator for BadSerializationElectionCallMessages {
type Call = sov_election::call::CallMessage<DefaultContext>;
type Call = sov_election::CallMessage<DefaultContext>;

fn create_messages(&self) -> Vec<(Rc<DefaultPrivateKey>, Self::Call, u64)> {
let call_generator = &mut CallGenerator::new(self.election_admin.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl ValueSetterMessages {
}

impl MessageGenerator for ValueSetterMessages {
type Call = sov_value_setter::call::CallMessage;
type Call = sov_value_setter::CallMessage;

fn create_messages(&self) -> Vec<(Rc<DefaultPrivateKey>, Self::Call, u64)> {
let admin = self.admin.clone();
Expand All @@ -25,11 +25,11 @@ impl MessageGenerator for ValueSetterMessages {

let new_value = 99;

let set_value_msg_1: sov_value_setter::call::CallMessage =
sov_value_setter::call::CallMessage::SetValue(new_value);
let set_value_msg_1: sov_value_setter::CallMessage =
sov_value_setter::CallMessage::SetValue(new_value);

let new_value = 33;
let set_value_msg_2 = sov_value_setter::call::CallMessage::SetValue(new_value);
let set_value_msg_2 = sov_value_setter::CallMessage::SetValue(new_value);

messages.push((admin.clone(), set_value_msg_1, value_setter_admin_nonce));

Expand Down
12 changes: 6 additions & 6 deletions examples/demo-stf/src/tests/stf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ pub mod test {

assert_eq!(
resp,
sov_election::query::GetResultResponse::Result(Some(sov_election::Candidate {
sov_election::GetResultResponse::Result(Some(sov_election::Candidate {
name: "candidate_2".to_owned(),
count: 3
}))
);
let resp = runtime.value_setter.query_value(&mut working_set);

assert_eq!(resp, sov_value_setter::query::Response { value: Some(33) });
assert_eq!(resp, sov_value_setter::Response { value: Some(33) });
}
}

Expand Down Expand Up @@ -116,15 +116,15 @@ pub mod test {

assert_eq!(
resp,
sov_election::query::GetResultResponse::Result(Some(sov_election::Candidate {
sov_election::GetResultResponse::Result(Some(sov_election::Candidate {
name: "candidate_2".to_owned(),
count: 3
}))
);

let resp = runtime.value_setter.query_value(&mut working_set);

assert_eq!(resp, sov_value_setter::query::Response { value: Some(33) });
assert_eq!(resp, sov_value_setter::Response { value: Some(33) });
}

#[test]
Expand Down Expand Up @@ -174,12 +174,12 @@ pub mod test {

assert_eq!(
resp,
sov_election::query::GetResultResponse::Err("Election is not frozen".to_owned())
sov_election::GetResultResponse::Err("Election is not frozen".to_owned())
);

let resp = runtime.value_setter.query_value(&mut working_set);

assert_eq!(resp, sov_value_setter::query::Response { value: None });
assert_eq!(resp, sov_value_setter::Response { value: None });
}
}

Expand Down
Loading