diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index 8141dfa..fa0371c 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -45,8 +45,98 @@ impl Context { impl AsRef for Context { fn as_ref(&self) -> &WorkingDirectoryConfiguration { match self { - Context::ExecuteTests(execution_context) => &execution_context.working_directory, - Context::ExportJsonSchema => unreachable!(), + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &SolcConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &ResolcConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &GethConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &KitchensinkConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &ReviveDevNodeConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &EthRpcConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &GenesisConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &WalletConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &ConcurrencyConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), + } + } +} + +impl AsRef for Context { + fn as_ref(&self) -> &CompilationConfiguration { + match self { + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), } } } @@ -54,8 +144,8 @@ impl AsRef for Context { impl AsRef for Context { fn as_ref(&self) -> &ReportConfiguration { match self { - Context::ExecuteTests(execution_context) => &execution_context.report_configuration, - Context::ExportJsonSchema => unreachable!(), + Self::ExecuteTests(context) => context.as_ref().as_ref(), + Self::ExportJsonSchema => unreachable!(), } } } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 8bdb91b..8c58d4c 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -92,34 +92,20 @@ pub trait DynPlatform { /// initializing it, spawning it, and waiting for it to start up. fn new_node( &self, - context: impl AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + Send - + Sync - + Clone - + 'static, + context: Context, ) -> anyhow::Result>>>; /// Creates a new compiler for the provided platform - fn new_compiler<'a>( + fn new_compiler( &self, - context: impl AsRef - + AsRef - + AsRef - + 'a, - version: impl Into> + 'a, - ) -> Pin>> + 'a>>; + context: Context, + version: Option, + ) -> Pin>>>>; } -pub struct GethEvmPlatform; +pub struct GethEvmSolcPlatform; -impl DynPlatform for GethEvmPlatform { +impl DynPlatform for GethEvmSolcPlatform { fn platform_identifier(&self) -> PlatformIdentifier { PlatformIdentifier::GethEvmSolc } @@ -138,18 +124,7 @@ impl DynPlatform for GethEvmPlatform { fn new_node( &self, - context: impl AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + Send - + Sync - + Clone - + 'static, + context: Context, ) -> anyhow::Result>>> { let genesis_configuration = AsRef::::as_ref(&context); let genesis = genesis_configuration.genesis()?.clone(); @@ -160,14 +135,11 @@ impl DynPlatform for GethEvmPlatform { })) } - fn new_compiler<'a>( + fn new_compiler( &self, - context: impl AsRef - + AsRef - + AsRef - + 'a, - version: impl Into> + 'a, - ) -> Pin>> + 'a>> { + context: Context, + version: Option, + ) -> Pin>>>> { Box::pin(async move { let compiler = Solc::new(context, version).await; compiler.map(|compiler| Box::new(compiler) as Box) @@ -175,9 +147,9 @@ impl DynPlatform for GethEvmPlatform { } } -pub struct KitchensinkPolkavmResolc; +pub struct KitchensinkPolkavmResolcPlatform; -impl DynPlatform for KitchensinkPolkavmResolc { +impl DynPlatform for KitchensinkPolkavmResolcPlatform { fn platform_identifier(&self) -> PlatformIdentifier { PlatformIdentifier::KitchensinkPolkavmResolc } @@ -196,18 +168,7 @@ impl DynPlatform for KitchensinkPolkavmResolc { fn new_node( &self, - context: impl AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + Send - + Sync - + Clone - + 'static, + context: Context, ) -> anyhow::Result>>> { let genesis_configuration = AsRef::::as_ref(&context); let kitchensink_path = AsRef::::as_ref(&context) @@ -225,14 +186,11 @@ impl DynPlatform for KitchensinkPolkavmResolc { })) } - fn new_compiler<'a>( + fn new_compiler( &self, - context: impl AsRef - + AsRef - + AsRef - + 'a, - version: impl Into> + 'a, - ) -> Pin>> + 'a>> { + context: Context, + version: Option, + ) -> Pin>>>> { Box::pin(async move { let compiler = Resolc::new(context, version).await; compiler.map(|compiler| Box::new(compiler) as Box) @@ -240,9 +198,9 @@ impl DynPlatform for KitchensinkPolkavmResolc { } } -pub struct KitchensinkRevmSolc; +pub struct KitchensinkRevmSolcPlatform; -impl DynPlatform for KitchensinkRevmSolc { +impl DynPlatform for KitchensinkRevmSolcPlatform { fn platform_identifier(&self) -> PlatformIdentifier { PlatformIdentifier::KitchensinkRevmSolc } @@ -261,18 +219,7 @@ impl DynPlatform for KitchensinkRevmSolc { fn new_node( &self, - context: impl AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + Send - + Sync - + Clone - + 'static, + context: Context, ) -> anyhow::Result>>> { let genesis_configuration = AsRef::::as_ref(&context); let kitchensink_path = AsRef::::as_ref(&context) @@ -290,14 +237,11 @@ impl DynPlatform for KitchensinkRevmSolc { })) } - fn new_compiler<'a>( + fn new_compiler( &self, - context: impl AsRef - + AsRef - + AsRef - + 'a, - version: impl Into> + 'a, - ) -> Pin>> + 'a>> { + context: Context, + version: Option, + ) -> Pin>>>> { Box::pin(async move { let compiler = Solc::new(context, version).await; compiler.map(|compiler| Box::new(compiler) as Box) @@ -305,9 +249,9 @@ impl DynPlatform for KitchensinkRevmSolc { } } -pub struct ReviveDevNodePolkavmResolc; +pub struct ReviveDevNodePolkavmResolcPlatform; -impl DynPlatform for ReviveDevNodePolkavmResolc { +impl DynPlatform for ReviveDevNodePolkavmResolcPlatform { fn platform_identifier(&self) -> PlatformIdentifier { PlatformIdentifier::ReviveDevNodePolkavmResolc } @@ -326,18 +270,7 @@ impl DynPlatform for ReviveDevNodePolkavmResolc { fn new_node( &self, - context: impl AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + Send - + Sync - + Clone - + 'static, + context: Context, ) -> anyhow::Result>>> { let genesis_configuration = AsRef::::as_ref(&context); let revive_dev_node_path = AsRef::::as_ref(&context) @@ -355,14 +288,11 @@ impl DynPlatform for ReviveDevNodePolkavmResolc { })) } - fn new_compiler<'a>( + fn new_compiler( &self, - context: impl AsRef - + AsRef - + AsRef - + 'a, - version: impl Into> + 'a, - ) -> Pin>> + 'a>> { + context: Context, + version: Option, + ) -> Pin>>>> { Box::pin(async move { let compiler = Resolc::new(context, version).await; compiler.map(|compiler| Box::new(compiler) as Box) @@ -370,9 +300,9 @@ impl DynPlatform for ReviveDevNodePolkavmResolc { } } -pub struct ReviveDevNodeRevmSolc; +pub struct ReviveDevNodeRevmSolcPlatform; -impl DynPlatform for ReviveDevNodeRevmSolc { +impl DynPlatform for ReviveDevNodeRevmSolcPlatform { fn platform_identifier(&self) -> PlatformIdentifier { PlatformIdentifier::ReviveDevNodeRevmSolc } @@ -391,18 +321,7 @@ impl DynPlatform for ReviveDevNodeRevmSolc { fn new_node( &self, - context: impl AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + AsRef - + Send - + Sync - + Clone - + 'static, + context: Context, ) -> anyhow::Result>>> { let genesis_configuration = AsRef::::as_ref(&context); let revive_dev_node_path = AsRef::::as_ref(&context) @@ -420,14 +339,11 @@ impl DynPlatform for ReviveDevNodeRevmSolc { })) } - fn new_compiler<'a>( + fn new_compiler( &self, - context: impl AsRef - + AsRef - + AsRef - + 'a, - version: impl Into> + 'a, - ) -> Pin>> + 'a>> { + context: Context, + version: Option, + ) -> Pin>>>> { Box::pin(async move { let compiler = Solc::new(context, version).await; compiler.map(|compiler| Box::new(compiler) as Box) @@ -435,6 +351,26 @@ impl DynPlatform for ReviveDevNodeRevmSolc { } } +impl From for Box { + fn from(value: PlatformIdentifier) -> Self { + match value { + PlatformIdentifier::GethEvmSolc => Box::new(GethEvmSolcPlatform) as Box<_>, + PlatformIdentifier::KitchensinkPolkavmResolc => { + Box::new(KitchensinkPolkavmResolcPlatform) as Box<_> + } + PlatformIdentifier::KitchensinkRevmSolc => { + Box::new(KitchensinkRevmSolcPlatform) as Box<_> + } + PlatformIdentifier::ReviveDevNodePolkavmResolc => { + Box::new(ReviveDevNodePolkavmResolcPlatform) as Box<_> + } + PlatformIdentifier::ReviveDevNodeRevmSolc => { + Box::new(ReviveDevNodeRevmSolcPlatform) as Box<_> + } + } + } +} + fn spawn_node( mut node: T, genesis: Genesis,