• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EspressoSystems / marketplace-builder-core / 11961978007

21 Nov 2024 09:29PM UTC coverage: 68.045% (-21.7%) from 89.696%
11961978007

Pull #239

github

web-flow
Merge ef39de3b0 into 178a48f80
Pull Request #239: [WIP] [Refactor] 3: Switch legacy to coordinator

146 of 504 new or added lines in 13 files covered. (28.97%)

52 existing lines in 4 files now uncovered.

1761 of 2588 relevant lines covered (68.04%)

2189.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/crates/legacy/src/testing/integration.rs
1
//! This module implements interfaces necessary to run legacy builder
2
//! in HotShot testing harness.
3

4
use std::{collections::HashMap, fmt::Display, marker::PhantomData, sync::Arc, time::Duration};
5

6
use async_trait::async_trait;
7
use hotshot::types::SignatureKey;
8
use hotshot_testing::{
9
    block_builder::{BuilderTask, TestBuilderImplementation},
10
    test_builder::BuilderChange,
11
};
12
use hotshot_types::{
13
    data::ViewNumber,
14
    traits::{node_implementation::NodeType, signature_key::BuilderSignatureKey},
15
};
16
use marketplace_builder_shared::testing::constants::{
17
    TEST_API_TIMEOUT, TEST_BASE_FEE, TEST_CHANNEL_BUFFER_SIZE, TEST_INCLUDED_TX_GC_PERIOD,
18
    TEST_MAXIMIZE_TX_CAPTURE_TIMEOUT,
19
};
20
use tagged_base64::TaggedBase64;
21
use tokio::spawn;
22
use url::Url;
23
use vbs::version::StaticVersion;
24

25
use crate::service::GlobalState;
26

27
/// Testing configuration for legacy builder
28
struct TestLegacyBuilderConfig<Types>
29
where
30
    Types: NodeType,
31
{
32
    _marker: PhantomData<Types>,
33
}
34

35
impl<Types> Default for TestLegacyBuilderConfig<Types>
36
where
37
    Types: NodeType,
38
{
NEW
39
    fn default() -> Self {
×
NEW
40
        Self {
×
NEW
41
            _marker: PhantomData,
×
NEW
42
        }
×
NEW
43
    }
×
44
}
45

46
/// [`TestBuilderImplementation`] for legacy builder.
47
/// Passed as a generic parameter to [`TestRunner::run_test`], it is be used
48
/// to instantiate builder API and builder task.
49
struct LegacyBuilderImpl {}
50

51
#[async_trait]
52
impl<Types> TestBuilderImplementation<Types> for LegacyBuilderImpl
53
where
54
    Types: NodeType<View = ViewNumber>,
55
    Types::InstanceState: Default,
56
    for<'a> <<Types::SignatureKey as SignatureKey>::PureAssembledSignatureType as TryFrom<
57
        &'a TaggedBase64,
58
    >>::Error: Display,
59
    for<'a> <Types::SignatureKey as TryFrom<&'a TaggedBase64>>::Error: Display,
60
{
61
    type Config = TestLegacyBuilderConfig<Types>;
62

63
    /// This is mostly boilerplate to instantiate and start [`ProxyGlobalState`] APIs and initial [`BuilderState`]'s event loop.
64
    /// [`BuilderTask`] it returns will be injected into consensus runtime by HotShot testing harness and
65
    /// will forward transactions from hotshot event stream to the builder.
66
    async fn start(
67
        num_nodes: usize,
68
        url: Url,
69
        _config: <Self as TestBuilderImplementation<Types>>::Config,
70
        _changes: HashMap<u64, BuilderChange>,
NEW
71
    ) -> Box<dyn BuilderTask<Types>> {
×
NEW
72
        let builder_key_pair = Types::BuilderSignatureKey::generated_from_seed_indexed([0; 32], 0);
×
NEW
73
        // Create the global state
×
NEW
74
        let service = GlobalState::new(
×
NEW
75
            builder_key_pair,
×
NEW
76
            TEST_API_TIMEOUT,
×
NEW
77
            Duration::from_secs(100),
×
NEW
78
            8192000,
×
NEW
79
            TEST_MAXIMIZE_TX_CAPTURE_TIMEOUT,
×
NEW
80
            num_nodes,
×
NEW
81
            Types::InstanceState::default(),
×
NEW
82
            TEST_INCLUDED_TX_GC_PERIOD,
×
NEW
83
            TEST_CHANNEL_BUFFER_SIZE,
×
NEW
84
            TEST_BASE_FEE,
×
NEW
85
        );
×
NEW
86

×
NEW
87
        // Create tide-disco app based on global state
×
NEW
88
        let app = Arc::clone(&service)
×
NEW
89
            .into_app()
×
NEW
90
            .expect("Failed to create builder tide-disco app");
×
NEW
91

×
NEW
92
        let url_clone = url.clone();
×
NEW
93

×
NEW
94
        spawn(app.serve(url_clone, StaticVersion::<0, 1> {}));
×
NEW
95

×
NEW
96
        // Return the global state as a task that will be later started
×
NEW
97
        // by the test harness with event stream from one of HS nodes
×
NEW
98
        Box::new(LegacyBuilderTask { service })
×
NEW
99
    }
×
100
}
101

102
/// Legacy builder task. Stores all the necessary information to run builder service
103
struct LegacyBuilderTask<Types>
104
where
105
    Types: NodeType,
106
{
107
    service: Arc<GlobalState<Types>>,
108
}
109

110
impl<Types> BuilderTask<Types> for LegacyBuilderTask<Types>
111
where
112
    Types: NodeType<View = ViewNumber>,
113
    for<'a> <<Types::SignatureKey as SignatureKey>::PureAssembledSignatureType as TryFrom<
114
        &'a TaggedBase64,
115
    >>::Error: Display,
116
    for<'a> <Types::SignatureKey as TryFrom<&'a TaggedBase64>>::Error: Display,
117
{
NEW
118
    fn start(
×
NEW
119
        self: Box<Self>,
×
NEW
120
        stream: Box<
×
NEW
121
            dyn futures::prelude::Stream<Item = hotshot::types::Event<Types>>
×
NEW
122
                + std::marker::Unpin
×
NEW
123
                + Send
×
NEW
124
                + 'static,
×
NEW
125
        >,
×
NEW
126
    ) {
×
NEW
127
        self.service.start_event_loop(stream);
×
NEW
128
    }
×
129
}
130

131
#[cfg(test)]
132
mod tests {
133
    use std::time::Duration;
134

135
    use crate::testing::integration::LegacyBuilderImpl;
136
    use marketplace_builder_shared::testing::{
137
        generation::{self, TransactionGenerationConfig},
138
        run_test,
139
        validation::BuilderValidationConfig,
140
    };
141

142
    use hotshot_example_types::node_types::TestVersions;
143
    use hotshot_example_types::node_types::{MemoryImpl, TestTypes};
144
    use hotshot_macros::cross_tests;
145
    use hotshot_testing::{
146
        completion_task::{CompletionTaskDescription, TimeBasedCompletionTaskDescription},
147
        overall_safety_task::OverallSafetyPropertiesDescription,
148
        test_builder::TestDescription,
149
    };
150

151
    #[tokio::test(flavor = "multi_thread")]
NEW
152
    #[tracing::instrument]
×
153
    #[ignore = "slow"]
NEW
154
    async fn example_test() {
×
NEW
155
        let num_successful_views = 45;
×
NEW
156
        let min_txns_per_view = 5;
×
NEW
157

×
NEW
158
        run_test::<TestVersions, LegacyBuilderImpl>(
×
NEW
159
            TestDescription {
×
NEW
160
                txn_description: hotshot_testing::txn_task::TxnTaskDescription::RoundRobinTimeBased(
×
NEW
161
                    Duration::MAX,
×
NEW
162
                ),
×
NEW
163
                completion_task_description:
×
NEW
164
                    CompletionTaskDescription::TimeBasedCompletionTaskBuilder(
×
NEW
165
                        TimeBasedCompletionTaskDescription {
×
NEW
166
                            duration: Duration::from_secs(60),
×
NEW
167
                        },
×
NEW
168
                    ),
×
NEW
169
                overall_safety_properties: OverallSafetyPropertiesDescription {
×
NEW
170
                    num_successful_views,
×
NEW
171
                    num_failed_views: 5,
×
NEW
172
                    ..Default::default()
×
NEW
173
                },
×
NEW
174
                ..TestDescription::default()
×
NEW
175
            },
×
NEW
176
            BuilderValidationConfig {
×
NEW
177
                expected_txn_num: num_successful_views * min_txns_per_view,
×
NEW
178
            },
×
NEW
179
            TransactionGenerationConfig {
×
NEW
180
                strategy: generation::GenerationStrategy::Random {
×
NEW
181
                    min_per_view: min_txns_per_view,
×
NEW
182
                    max_per_view: 10,
×
NEW
183
                    min_tx_size: 128,
×
NEW
184
                    max_tx_size: 1280,
×
NEW
185
                },
×
NEW
186
                endpoints: vec![],
×
NEW
187
            },
×
NEW
188
        )
×
NEW
189
        .await;
×
190
    }
191

NEW
192
    cross_tests!(
×
193
        TestName: example_cross_test,
194
        Impls: [MemoryImpl],
195
        BuilderImpls: [LegacyBuilderImpl],
196
        Types: [TestTypes],
197
        Versions: [TestVersions],
198
        Ignore: true,
199
        Metadata: {
200
            TestDescription {
201
                validate_transactions : hotshot_testing::test_builder::nonempty_block_threshold((90,100)),
202
                txn_description : hotshot_testing::txn_task::TxnTaskDescription::RoundRobinTimeBased(Duration::from_millis(10)),
203
                completion_task_description : CompletionTaskDescription::TimeBasedCompletionTaskBuilder(
204
                            TimeBasedCompletionTaskDescription {
205
                                duration: Duration::from_secs(120),
206
                            },
207
                ),
208
                overall_safety_properties: OverallSafetyPropertiesDescription {
209
                    num_successful_views: 50,
210
                    num_failed_views: 5,
211
                    ..Default::default()
212
                },
213
                ..Default::default()
214
            }
215
        },
NEW
216
    );
×
217
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc