@@ -67,49 +67,82 @@ struct variant_snapshot_suite {
67
67
using writer_t = variant_snapshot_writer;
68
68
using reader_t = variant_snapshot_reader;
69
69
using write_storage_t = fc::mutable_variant_object;
70
- using read_storage_t = fc::variant;
70
+ using snapshot_t = fc::variant;
71
+
72
+ struct writer : public writer_t {
73
+ writer ( const std::shared_ptr<write_storage_t >& storage )
74
+ :writer_t (*storage)
75
+ ,storage(storage)
76
+ {
77
+
78
+ }
79
+
80
+ std::shared_ptr<write_storage_t > storage;
81
+ };
82
+
83
+ struct reader : public reader_t {
84
+ explicit reader (const snapshot_t & storage)
85
+ :reader_t(storage)
86
+ {}
87
+ };
88
+
89
+
90
+ static auto get_writer () {
91
+ return std::make_shared<writer>(std::make_shared<write_storage_t >());
92
+ }
93
+
94
+ static auto finalize (const std::shared_ptr<writer>& w) {
95
+ w->finalize ();
96
+ return snapshot_t (*w->storage );
97
+ }
98
+
99
+ static auto get_reader ( const snapshot_t & buffer) {
100
+ return std::make_shared<reader>(buffer);
101
+ }
102
+
71
103
};
72
104
73
105
struct buffered_snapshot_suite {
74
106
using writer_t = ostream_snapshot_writer;
75
107
using reader_t = istream_snapshot_reader;
76
- using write_storage_t = std::stringstream;
77
- using read_storage_t = write_storage_t ;
78
-
79
- };
108
+ using write_storage_t = std::ostringstream;
109
+ using snapshot_t = std::string;
110
+ using read_storage_t = std::istringstream;
80
111
81
- template <typename SUITE>
82
- struct suite_funcs {
83
- struct writer : public SUITE ::writer_t {
84
- writer ( const std::shared_ptr<typename SUITE::write_storage_t >& storage )
85
- :SUITE::writer_t (*storage)
112
+ struct writer : public writer_t {
113
+ writer ( const std::shared_ptr<write_storage_t >& storage )
114
+ :writer_t (*storage)
86
115
,storage(storage)
87
116
{
88
117
89
118
}
90
119
91
- std::shared_ptr<typename SUITE:: write_storage_t > storage;
120
+ std::shared_ptr<write_storage_t > storage;
92
121
};
93
122
94
- struct reader : public SUITE ::reader_t {
95
- explicit reader (typename SUITE::read_storage_t & buffer)
96
- :SUITE::reader_t(buffer)
123
+ struct reader : public reader_t {
124
+ explicit reader (const std::shared_ptr<read_storage_t >& storage)
125
+ :reader_t(*storage)
126
+ ,storage(storage)
97
127
{}
98
128
129
+ std::shared_ptr<read_storage_t > storage;
99
130
};
100
131
132
+
101
133
static auto get_writer () {
102
- return std::make_shared<writer>(std::make_shared<typename SUITE:: write_storage_t >());
134
+ return std::make_shared<writer>(std::make_shared<write_storage_t >());
103
135
}
104
136
105
137
static auto finalize (const std::shared_ptr<writer>& w) {
106
138
w->finalize ();
107
- return typename SUITE::read_storage_t ( std::move (* w->storage ) );
139
+ return w->storage -> str ( );
108
140
}
109
141
110
- static auto get_reader ( typename SUITE:: read_storage_t & buffer) {
111
- return std::make_shared<reader>(buffer);
142
+ static auto get_reader ( const snapshot_t & buffer) {
143
+ return std::make_shared<reader>(std::make_shared< read_storage_t >( buffer) );
112
144
}
145
+
113
146
};
114
147
115
148
BOOST_AUTO_TEST_SUITE (snapshot_tests)
@@ -132,12 +165,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_exhaustive_snapshot, SNAPSHOT_SUITE, snapshot
132
165
133
166
for (int generation = 0 ; generation < generation_count; generation++) {
134
167
// create a new snapshot child
135
- auto writer = suite_funcs< SNAPSHOT_SUITE> ::get_writer ();
168
+ auto writer = SNAPSHOT_SUITE::get_writer ();
136
169
chain.control ->write_snapshot (writer);
137
- auto snapshot = suite_funcs< SNAPSHOT_SUITE> ::finalize (writer);
170
+ auto snapshot = SNAPSHOT_SUITE::finalize (writer);
138
171
139
172
// create a new child at this snapshot
140
- sub_testers.emplace_back (chain.get_config (), suite_funcs< SNAPSHOT_SUITE> ::get_reader (snapshot), generation);
173
+ sub_testers.emplace_back (chain.get_config (), SNAPSHOT_SUITE::get_reader (snapshot), generation);
141
174
142
175
// increment the test contract
143
176
chain.push_action (N (snapshot), N (increment), N (snapshot), mutable_variant_object ()
@@ -188,12 +221,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_replay_over_snapshot, SNAPSHOT_SUITE, snapsho
188
221
auto expected_pre_integrity_hash = chain.control ->calculate_integrity_hash ();
189
222
190
223
// create a new snapshot child
191
- auto writer = suite_funcs< SNAPSHOT_SUITE> ::get_writer ();
224
+ auto writer = SNAPSHOT_SUITE::get_writer ();
192
225
chain.control ->write_snapshot (writer);
193
- auto snapshot = suite_funcs< SNAPSHOT_SUITE> ::finalize (writer);
226
+ auto snapshot = SNAPSHOT_SUITE::finalize (writer);
194
227
195
228
// create a new child at this snapshot
196
- snapshotted_tester snap_chain (chain.get_config (), suite_funcs< SNAPSHOT_SUITE> ::get_reader (snapshot), 1 );
229
+ snapshotted_tester snap_chain (chain.get_config (), SNAPSHOT_SUITE::get_reader (snapshot), 1 );
197
230
BOOST_REQUIRE_EQUAL (expected_pre_integrity_hash.str (), snap_chain.control ->calculate_integrity_hash ().str ());
198
231
199
232
// push more blocks to build up a block log
@@ -213,7 +246,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_replay_over_snapshot, SNAPSHOT_SUITE, snapsho
213
246
BOOST_REQUIRE_EQUAL (expected_post_integrity_hash.str (), snap_chain.control ->calculate_integrity_hash ().str ());
214
247
215
248
// replay the block log from the snapshot child, from the snapshot
216
- snapshotted_tester replay_chain (chain.get_config (), suite_funcs< SNAPSHOT_SUITE> ::get_reader (snapshot), 2 , 1 );
249
+ snapshotted_tester replay_chain (chain.get_config (), SNAPSHOT_SUITE::get_reader (snapshot), 2 , 1 );
217
250
BOOST_REQUIRE_EQUAL (expected_post_integrity_hash.str (), snap_chain.control ->calculate_integrity_hash ().str ());
218
251
}
219
252
0 commit comments