pub struct Simulacrum<R = OsRng, Store: SimulatorStore = InMemoryStore> { /* private fields */ }Expand description
A Simulacrum of Sui.
This type represents a simulated instantiation of a Sui blockchain that needs to be driven manually, that is time doesn’t advance and checkpoints are not formed unless explicitly requested.
See module level documentation for more details.
Implementations§
Source§impl Simulacrum
impl Simulacrum
Source§impl<R> Simulacrum<R>
impl<R> Simulacrum<R>
Sourcepub fn new_with_rng(rng: R) -> Self
pub fn new_with_rng(rng: R) -> Self
Create a new Simulacrum instance using the provided rng.
This allows you to create a fully deterministic initial chainstate when a seeded rng is used.
use simulacrum::Simulacrum;
use rand::{SeedableRng, rngs::StdRng};
let mut rng = StdRng::seed_from_u64(1);
let simulacrum = Simulacrum::new_with_rng(rng);Sourcepub fn new_with_protocol_version(
rng: R,
protocol_version: ProtocolVersion,
) -> Self
pub fn new_with_protocol_version( rng: R, protocol_version: ProtocolVersion, ) -> Self
Create a new Simulacrum instance with a specific protocol version.
pub fn new_with_protocol_version_and_accounts( rng: R, chain_start_timestamp_ms: u64, protocol_version: ProtocolVersion, account_configs: Vec<AccountConfig>, ) -> Self
Source§impl<R, S: SimulatorStore> Simulacrum<R, S>
impl<R, S: SimulatorStore> Simulacrum<R, S>
pub fn new_with_network_config_store( config: &NetworkConfig, rng: R, store: S, ) -> Self
Sourcepub fn execute_transaction(
&mut self,
transaction: Transaction,
) -> Result<(TransactionEffects, Option<ExecutionError>)>
pub fn execute_transaction( &mut self, transaction: Transaction, ) -> Result<(TransactionEffects, Option<ExecutionError>)>
Attempts to execute the provided Transaction.
The provided Transaction undergoes the same types of checks that a Validator does prior to signing and executing in the production system. Some of these checks are as follows:
- User signature is valid
- Sender owns all OwnedObject inputs
- etc
If the above checks are successful then the transaction is immediately executed, enqueued
to be included in the next checkpoint (the next time create_checkpoint is called) and the
corresponding TransactionEffects are returned.
Sourcepub fn create_checkpoint(&mut self) -> VerifiedCheckpoint
pub fn create_checkpoint(&mut self) -> VerifiedCheckpoint
Creates the next Checkpoint using the Transactions enqueued since the last checkpoint was created.
Sourcepub fn advance_clock(&mut self, duration: Duration) -> TransactionEffects
pub fn advance_clock(&mut self, duration: Duration) -> TransactionEffects
Advances the clock by duration.
This creates and executes a ConsensusCommitPrologue transaction which advances the chain Clock by the provided duration.
Sourcepub fn advance_epoch(&mut self, config: AdvanceEpochConfig)
pub fn advance_epoch(&mut self, config: AdvanceEpochConfig)
Advances the epoch.
This creates and executes an EndOfEpoch transaction which advances the chain into the next epoch. Since it is required to be the final transaction in an epoch, the final checkpoint in the epoch is also created.
The config parameter controls which special end-of-epoch transactions are created
as part of this epoch change.
NOTE: This function does not currently support updating the protocol version
pub fn store(&self) -> &dyn SimulatorStore
pub fn keystore(&self) -> &KeyStore
pub fn epoch_start_state(&self) -> &EpochStartSystemState
Sourcepub fn rng(&mut self) -> &mut R
pub fn rng(&mut self) -> &mut R
Return a handle to the internally held RNG.
Returns a handle to the RNG used to create this Simulacrum for use as a source of randomness. Using a seeded RNG to build a Simulacrum and then utilizing the stored RNG as a source of randomness can lead to a fully deterministic chain evolution.
Sourcepub fn reference_gas_price(&self) -> u64
pub fn reference_gas_price(&self) -> u64
Return the reference gas price for the current epoch
Sourcepub fn funded_account(
&mut self,
amount: u64,
) -> Result<(SuiAddress, AccountKeyPair, ObjectRef)>
pub fn funded_account( &mut self, amount: u64, ) -> Result<(SuiAddress, AccountKeyPair, ObjectRef)>
Create a new account and credit it with amount gas units from a faucet account. Returns
the account, its keypair, and a reference to the gas object it was funded with.
use simulacrum::Simulacrum;
use sui_types::base_types::SuiAddress;
use sui_types::gas_coin::MIST_PER_SUI;
let mut simulacrum = Simulacrum::new();
let (account, kp, gas) = simulacrum.funded_account(MIST_PER_SUI).unwrap();
// `account` is a fresh SuiAddress that owns a Coin<SUI> object with single SUI in it,
// referred to by `gas`.
// ...Sourcepub fn request_gas(
&mut self,
address: SuiAddress,
amount: u64,
) -> Result<TransactionEffects>
pub fn request_gas( &mut self, address: SuiAddress, amount: u64, ) -> Result<TransactionEffects>
Request that amount Mist be sent to address from a faucet account.
use simulacrum::Simulacrum;
use sui_types::base_types::SuiAddress;
use sui_types::gas_coin::MIST_PER_SUI;
let mut simulacrum = Simulacrum::new();
let address = SuiAddress::generate(simulacrum.rng());
simulacrum.request_gas(address, MIST_PER_SUI).unwrap();
// `account` now has a Coin<SUI> object with single SUI in it.
// ...pub fn set_data_ingestion_path(&mut self, data_ingestion_path: PathBuf)
pub fn override_next_checkpoint_number( &mut self, number: CheckpointSequenceNumber, )
Source§impl Simulacrum
impl Simulacrum
Sourcepub fn transfer_txn(&mut self, recipient: SuiAddress) -> (Transaction, u64)
pub fn transfer_txn(&mut self, recipient: SuiAddress) -> (Transaction, u64)
Generate a random transfer transaction. TODO: This is here today to make it easier to write tests. But we should utilize all the existing code for generating transactions in sui-test-transaction-builder by defining a trait that both WalletContext and Simulacrum implement. Then we can remove this function.
Trait Implementations§
Source§impl<T, V: SimulatorStore> ObjectStore for Simulacrum<T, V>
impl<T, V: SimulatorStore> ObjectStore for Simulacrum<T, V>
fn get_object(&self, object_id: &ObjectID) -> Option<Object>
fn get_object_by_key( &self, object_id: &ObjectID, version: VersionNumber, ) -> Option<Object>
fn multi_get_objects(&self, object_ids: &[ObjectID]) -> Vec<Option<Object>>
fn multi_get_objects_by_key( &self, object_keys: &[ObjectKey], ) -> Vec<Option<Object>>
Source§impl<T, V: SimulatorStore> ReadStore for Simulacrum<T, V>
impl<T, V: SimulatorStore> ReadStore for Simulacrum<T, V>
fn get_committee(&self, _epoch: EpochId) -> Option<Arc<Committee>>
Source§fn get_latest_checkpoint(&self) -> Result<VerifiedCheckpoint>
fn get_latest_checkpoint(&self) -> Result<VerifiedCheckpoint>
Source§fn get_latest_epoch_id(&self) -> Result<EpochId>
fn get_latest_epoch_id(&self) -> Result<EpochId>
Source§fn get_highest_verified_checkpoint(&self) -> Result<VerifiedCheckpoint>
fn get_highest_verified_checkpoint(&self) -> Result<VerifiedCheckpoint>
Source§fn get_highest_synced_checkpoint(&self) -> Result<VerifiedCheckpoint>
fn get_highest_synced_checkpoint(&self) -> Result<VerifiedCheckpoint>
Source§fn get_lowest_available_checkpoint(&self) -> Result<CheckpointSequenceNumber>
fn get_lowest_available_checkpoint(&self) -> Result<CheckpointSequenceNumber>
fn get_checkpoint_by_digest( &self, digest: &CheckpointDigest, ) -> Option<VerifiedCheckpoint>
fn get_checkpoint_by_sequence_number( &self, sequence_number: CheckpointSequenceNumber, ) -> Option<VerifiedCheckpoint>
fn get_checkpoint_contents_by_digest( &self, digest: &CheckpointContentsDigest, ) -> Option<CheckpointContents>
fn get_checkpoint_contents_by_sequence_number( &self, _sequence_number: CheckpointSequenceNumber, ) -> Option<CheckpointContents>
fn get_transaction( &self, tx_digest: &TransactionDigest, ) -> Option<Arc<VerifiedTransaction>>
fn get_transaction_effects( &self, tx_digest: &TransactionDigest, ) -> Option<TransactionEffects>
fn get_events( &self, event_digest: &TransactionDigest, ) -> Option<TransactionEvents>
Source§fn get_full_checkpoint_contents(
&self,
_sequence_number: Option<CheckpointSequenceNumber>,
_digest: &CheckpointContentsDigest,
) -> Option<VersionedFullCheckpointContents>
fn get_full_checkpoint_contents( &self, _sequence_number: Option<CheckpointSequenceNumber>, _digest: &CheckpointContentsDigest, ) -> Option<VersionedFullCheckpointContents>
fn get_unchanged_loaded_runtime_objects( &self, _digest: &TransactionDigest, ) -> Option<Vec<ObjectKey>>
fn get_transaction_checkpoint( &self, _digest: &TransactionDigest, ) -> Option<CheckpointSequenceNumber>
Source§fn get_latest_checkpoint_sequence_number(&self) -> Result<u64, Error>
fn get_latest_checkpoint_sequence_number(&self) -> Result<u64, Error>
fn multi_get_transactions( &self, tx_digests: &[TransactionDigest], ) -> Vec<Option<Arc<VerifiedEnvelope<SenderSignedData, EmptySignInfo>>>>
fn multi_get_transaction_effects( &self, tx_digests: &[TransactionDigest], ) -> Vec<Option<TransactionEffects>>
fn multi_get_events( &self, event_digests: &[TransactionDigest], ) -> Vec<Option<TransactionEvents>>
fn get_checkpoint_data( &self, checkpoint: VerifiedEnvelope<CheckpointSummary, AuthorityQuorumSignInfo<true>>, checkpoint_contents: CheckpointContents, ) -> Result<Checkpoint, Error>
Source§impl<T: Send + Sync, V: SimulatorStore + Send + Sync> RpcStateReader for Simulacrum<T, V>
impl<T: Send + Sync, V: SimulatorStore + Send + Sync> RpcStateReader for Simulacrum<T, V>
Source§fn get_lowest_available_checkpoint_objects(
&self,
) -> Result<CheckpointSequenceNumber>
fn get_lowest_available_checkpoint_objects( &self, ) -> Result<CheckpointSequenceNumber>
fn get_chain_identifier(&self) -> Result<ChainIdentifier>
fn indexes(&self) -> Option<&dyn RpcIndexes>
fn get_struct_layout(&self, _: &StructTag) -> Result<Option<MoveTypeLayout>>
fn get_type_layout( &self, type_tag: &TypeTag, ) -> Result<Option<MoveTypeLayout>, Error>
Auto Trait Implementations§
impl<R = OsRng, Store = InMemoryStore> !Freeze for Simulacrum<R, Store>
impl<R = OsRng, Store = InMemoryStore> !RefUnwindSafe for Simulacrum<R, Store>
impl<R, Store> Send for Simulacrum<R, Store>
impl<R, Store> Sync for Simulacrum<R, Store>
impl<R, Store> Unpin for Simulacrum<R, Store>
impl<R = OsRng, Store = InMemoryStore> !UnwindSafe for Simulacrum<R, Store>
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a Request§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.