use solana_transaction::versioned::VersionedTransaction;
use crate::{ClusterSpecId, Svm, host::Host};
pub trait SvmTypesHost: Sized + 'static {
type SpecId: Copy + Into<ClusterSpecId>;
type Tx;
type SvmExt;
type MessageExt;
type MessageResultExt;
type TxEnvExt;
type TxResultExt;
type BlockEnvExt: Clone + Copy + std::fmt::Debug + Default + Send + Sync;
type Host<'a>: Host<Self> + ?Sized;
}
pub trait SvmTypes: for<'a> SvmTypesHost<Host<'a> = Svm<'a, Self>> {}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct BaseSvmTypes;
impl SvmTypesHost for BaseSvmTypes {
type SpecId = ClusterSpecId;
type Tx = VersionedTransaction;
type SvmExt = ();
type MessageExt = ();
type MessageResultExt = ();
type TxEnvExt = ();
type TxResultExt = ();
type BlockEnvExt = ();
type Host<'a> = Svm<'a, Self>;
}
impl SvmTypes for BaseSvmTypes {}
#[cfg(test)]
mod tests {
use std::mem::size_of;
use solana_transaction::versioned::VersionedTransaction;
use super::*;
#[test]
fn base_svm_types_extension_slots_are_zero_sized() {
use crate::ClusterSpecId;
assert_eq!(size_of::<BaseSvmTypes>(), 0);
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::SpecId>(), size_of::<ClusterSpecId>());
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::SpecId>(), 4);
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::SvmExt>(), 0);
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::MessageExt>(), 0);
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::MessageResultExt>(), 0);
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::TxEnvExt>(), 0);
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::TxResultExt>(), 0);
assert_eq!(size_of::<<BaseSvmTypes as SvmTypesHost>::BlockEnvExt>(), 0);
}
#[test]
fn base_svm_types_selects_the_versioned_transaction_envelope() {
let envelope: Option<<BaseSvmTypes as SvmTypesHost>::Tx> = None::<VersionedTransaction>;
assert!(envelope.is_none());
}
#[test]
fn base_svm_types_satisfies_the_blanket_marker() {
fn assert_marker<T: SvmTypes>() {}
assert_marker::<BaseSvmTypes>();
}
#[test]
fn the_base_host_is_the_compatibility_alias() {
fn same_host(host: Svm<'static, BaseSvmTypes>) -> crate::Hpsvm {
host
}
let aliased: crate::Hpsvm = same_host(Svm::<BaseSvmTypes>::new());
assert_eq!(aliased.latest_blockhash(), crate::Hpsvm::new().latest_blockhash());
}
}