Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_extraction.cpp File Reference
#include <boost/test/included/unit_test.hpp>
#include <sysio/chain/types.hpp>
#include <sysio/chain/contract_types.hpp>
#include <sysio/chain/trace.hpp>
#include <sysio/chain/transaction.hpp>
#include <sysio/chain/block.hpp>
#include <sysio/chain/block_state.hpp>
#include <sysio/trace_api/test_common.hpp>
#include <sysio/trace_api/chain_extraction.hpp>
#include <fc/bitutil.hpp>
Include dependency graph for test_extraction.cpp:

Go to the source code of this file.

Classes

struct  extraction_test_fixture
 
struct  extraction_test_fixture::mock_logfile_provider_type
 

Macros

#define BOOST_TEST_MODULE   trace_data_extraction
 

Functions

 BOOST_FIXTURE_TEST_CASE (basic_single_transaction_block, extraction_test_fixture)
 
 BOOST_FIXTURE_TEST_CASE (basic_multi_transaction_block, extraction_test_fixture)
 
 BOOST_FIXTURE_TEST_CASE (onerror_transaction_block, extraction_test_fixture)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   trace_data_extraction

Definition at line 1 of file test_extraction.cpp.

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/3]

BOOST_FIXTURE_TEST_CASE ( basic_multi_transaction_block ,
extraction_test_fixture  )

Definition at line 239 of file test_extraction.cpp.

239 {
240 auto act1 = make_transfer_action( "alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!" );
241 auto act2 = make_transfer_action( "bob"_n, "alice"_n, "0.0001 SYS"_t, "Memo!" );
242 auto act3 = make_transfer_action( "fred"_n, "bob"_n, "0.0001 SYS"_t, "Memo!" );
243 auto actt1 = make_action_trace( 0, act1, "sysio.token"_n );
244 auto actt2 = make_action_trace( 1, act2, "bob"_n );
245 auto actt3 = make_action_trace( 2, act3, "fred"_n );
246 auto ptrx1 = make_packed_trx( { act1 } );
247 auto ptrx2 = make_packed_trx( { act2 } );
248 auto ptrx3 = make_packed_trx( { act3 } );
249
250 signal_applied_transaction(
251 make_transaction_trace( ptrx1.id(), 1, 1, chain::transaction_receipt_header::executed,
252 { actt1 } ),
253 std::make_shared<packed_transaction>( ptrx1 ) );
254 signal_applied_transaction(
255 make_transaction_trace( ptrx2.id(), 1, 1, chain::transaction_receipt_header::executed,
256 { actt2 } ),
257 std::make_shared<packed_transaction>( ptrx2 ) );
258 signal_applied_transaction(
259 make_transaction_trace( ptrx3.id(), 1, 1, chain::transaction_receipt_header::executed,
260 { actt3 } ),
261 std::make_shared<packed_transaction>( ptrx3 ) );
262
263 // accept the block with three transaction
264 auto bsp1 = make_block_state( chain::block_id_type(), 1, 1, "bp.one"_n,
265 { chain::packed_transaction(ptrx1), chain::packed_transaction(ptrx2), chain::packed_transaction(ptrx3) } );
266 signal_accepted_block( bsp1 );
267
268 const std::vector<action_trace_v1> expected_action_trace1 {
269 {
270 {
271 0,
272 "sysio.token"_n, "sysio.token"_n, "transfer"_n,
273 {{"alice"_n, "active"_n}},
274 make_transfer_data("alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!")
275 },
276 {}
277 }
278 };
279
280 const std::vector<action_trace_v1> expected_action_trace2 {
281 {
282 {
283 1,
284 "bob"_n, "sysio.token"_n, "transfer"_n,
285 {{ "bob"_n, "active"_n }},
286 make_transfer_data( "bob"_n, "alice"_n, "0.0001 SYS"_t, "Memo!" )
287 },
288 {}
289 }
290 };
291
292 const std::vector<action_trace_v1> expected_action_trace3 {
293 {
294 {
295 2,
296 "fred"_n, "sysio.token"_n, "transfer"_n,
297 {{ "fred"_n, "active"_n }},
298 make_transfer_data( "fred"_n, "bob"_n, "0.0001 SYS"_t, "Memo!" )
299 },
300 {}
301 }
302 };
303
304 const std::vector<transaction_trace_v3> expected_transaction_traces {
305 {
306 {
307 ptrx1.id(),
308 expected_action_trace1,
310 bsp1->block->transactions[0].cpu_usage_us,
311 bsp1->block->transactions[0].net_usage_words,
312 ptrx1.get_signatures(),
313 make_trx_header(ptrx1.get_transaction())
314 }
315 },
316 {
317 {
318 ptrx2.id(),
319 expected_action_trace2,
321 bsp1->block->transactions[1].cpu_usage_us,
322 bsp1->block->transactions[1].net_usage_words,
323 ptrx2.get_signatures(),
324 make_trx_header(ptrx2.get_transaction())
325 }
326 },
327 {
328 {
329 ptrx3.id(),
330 expected_action_trace3,
332 bsp1->block->transactions[2].cpu_usage_us,
333 bsp1->block->transactions[2].net_usage_words,
334 ptrx3.get_signatures(),
335 make_trx_header(ptrx3.get_transaction())
336 }
337 }
338 };
339
340 const block_trace_v2 expected_block_trace {
341 bsp1->id,
342 1,
343 bsp1->prev(),
344 chain::block_timestamp_type(1),
345 "bp.one"_n,
346 bsp1->block->transaction_mroot,
347 bsp1->block->action_mroot,
348 bsp1->block->schedule_version,
349 expected_transaction_traces
350 };
351
352 BOOST_REQUIRE_EQUAL(max_lib, 0);
353 BOOST_REQUIRE(data_log.size() == 1);
354 BOOST_REQUIRE(std::holds_alternative<block_trace_v2>(data_log.at(0)));
355 BOOST_REQUIRE_EQUAL(std::get<block_trace_v2>(data_log.at(0)), expected_block_trace);
356 }
auto make_block_state(chain::block_id_type previous, uint32_t height, uint32_t slot, chain::name producer, std::vector< chain::packed_transaction > trxs)
chain::bytes make_transfer_data(chain::name from, chain::name to, chain::asset quantity, std::string &&memo)
@ executed
succeed, no error handler executed
Definition block.hpp:14
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [2/3]

BOOST_FIXTURE_TEST_CASE ( basic_single_transaction_block ,
extraction_test_fixture  )

Definition at line 155 of file test_extraction.cpp.

156 {
157 auto act1 = make_transfer_action( "alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!" );
158 auto act2 = make_transfer_action( "alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!" );
159 auto act3 = make_transfer_action( "alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!" );
160 auto actt1 = make_action_trace( 0, act1, "sysio.token"_n );
161 auto actt2 = make_action_trace( 1, act2, "alice"_n );
162 auto actt3 = make_action_trace( 2, act3, "bob"_n );
163 auto ptrx1 = make_packed_trx( { act1, act2, act3 } );
164
165 // apply a basic transfer
166 signal_applied_transaction(
167 make_transaction_trace( ptrx1.id(), 1, 1, chain::transaction_receipt_header::executed,
168 { actt1, actt2, actt3 } ),
169 std::make_shared<packed_transaction>(ptrx1) );
170
171 // accept the block with one transaction
172 auto bsp1 = make_block_state( chain::block_id_type(), 1, 1, "bp.one"_n,
173 { chain::packed_transaction(ptrx1) } );
174 signal_accepted_block( bsp1 );
175
176 const std::vector<action_trace_v1> expected_action_traces {
177 {
178 {
179 0,
180 "sysio.token"_n, "sysio.token"_n, "transfer"_n,
181 {{"alice"_n, "active"_n}},
182 make_transfer_data("alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!")
183 },
184 {}
185 },
186 {
187 {
188 1,
189 "alice"_n, "sysio.token"_n, "transfer"_n,
190 {{"alice"_n, "active"_n}},
191 make_transfer_data("alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!")
192 },
193 {}
194 },
195 {
196 {
197 2,
198 "bob"_n, "sysio.token"_n, "transfer"_n,
199 {{"alice"_n, "active"_n}},
200 make_transfer_data("alice"_n, "bob"_n, "0.0001 SYS"_t, "Memo!")
201 },
202 {}
203 }
204 };
205
206 const transaction_trace_v3 expected_transaction_trace {
207 {
208 ptrx1.id(),
209 expected_action_traces,
211 bsp1->block->transactions[0].cpu_usage_us,
212 bsp1->block->transactions[0].net_usage_words,
213 ptrx1.get_signatures(),
214 make_trx_header(ptrx1.get_transaction())
215 }
216 };
217
218 const block_trace_v2 expected_block_trace {
219 bsp1->id,
220 1,
221 bsp1->prev(),
222 chain::block_timestamp_type(1),
223 "bp.one"_n,
224 bsp1->block->transaction_mroot,
225 bsp1->block->action_mroot,
226 bsp1->block->schedule_version,
227 std::vector<transaction_trace_v3> {
228 expected_transaction_trace
229 }
230 };
231
232 BOOST_REQUIRE_EQUAL(max_lib, 0);
233 BOOST_REQUIRE(data_log.size() == 1);
234 BOOST_REQUIRE(std::holds_alternative<block_trace_v2>(data_log.at(0)));
235 BOOST_REQUIRE_EQUAL(std::get<block_trace_v2>(data_log.at(0)), expected_block_trace);
236 BOOST_REQUIRE_EQUAL(id_log.at(bsp1->block_num).size(), bsp1->block->transactions.size());
237 }
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE() [3/3]

BOOST_FIXTURE_TEST_CASE ( onerror_transaction_block ,
extraction_test_fixture  )

Definition at line 358 of file test_extraction.cpp.

359 {
360 auto onerror_act = make_onerror_action( "alice"_n, 1 );
361 auto actt1 = make_action_trace( 0, onerror_act, "sysio.token"_n );
362 auto ptrx1 = make_packed_trx( { onerror_act } );
363
364 auto act2 = make_transfer_action( "bob"_n, "alice"_n, "0.0001 SYS"_t, "Memo!" );
365 auto actt2 = make_action_trace( 1, act2, "bob"_n );
366 auto transfer_trx = make_packed_trx( { act2 } );
367
368 auto onerror_trace = make_transaction_trace( ptrx1.id(), 1, 1, chain::transaction_receipt_header::executed,
369 { actt1 } );
370 auto transfer_trace = make_transaction_trace( transfer_trx.id(), 1, 1, chain::transaction_receipt_header::soft_fail,
371 { actt2 } );
372 onerror_trace->failed_dtrx_trace = transfer_trace;
373
374 signal_applied_transaction( onerror_trace, std::make_shared<packed_transaction>( transfer_trx ) );
375
376 auto bsp1 = make_block_state( chain::block_id_type(), 1, 1, "bp.one"_n,
377 { chain::packed_transaction(transfer_trx) } );
378 signal_accepted_block( bsp1 );
379
380 const std::vector<action_trace_v1> expected_action_trace {
381 {
382 {
383 0,
384 "sysio.token"_n, "sysio"_n, "onerror"_n,
385 {{ "alice"_n, "active"_n }},
386 make_onerror_data( chain::onerror{ 1, "test ", 4 } )
387 },
388 {}
389 }
390 };
391
392 const std::vector<transaction_trace_v3> expected_transaction_traces {
393 {
394 {
395 transfer_trx.id(), // transfer_trx.id() because that is the trx id known to the user
396 expected_action_trace,
398 bsp1->block->transactions[0].cpu_usage_us,
399 bsp1->block->transactions[0].net_usage_words,
400 transfer_trx.get_signatures(),
401 make_trx_header(transfer_trx.get_transaction())
402 }
403 }
404 };
405
406 const block_trace_v2 expected_block_trace {
407 bsp1->id,
408 1,
409 bsp1->prev(),
410 chain::block_timestamp_type(1),
411 "bp.one"_n,
412 bsp1->block->transaction_mroot,
413 bsp1->block->action_mroot,
414 bsp1->block->schedule_version,
415 expected_transaction_traces
416 };
417
418 BOOST_REQUIRE_EQUAL(max_lib, 0);
419 BOOST_REQUIRE(data_log.size() == 1);
420 BOOST_REQUIRE(std::holds_alternative<block_trace_v2>(data_log.at(0)));
421 BOOST_REQUIRE_EQUAL(std::get<block_trace_v2>(data_log.at(0)), expected_block_trace);
422 }
@ soft_fail
objectively failed (not executed), error handler executed
Definition block.hpp:15
Here is the call graph for this function: