void test_action::test_publication_time() { uint64_t pub_time = 0; uint32_t total = read_action_data(&pub_time, sizeof(uint64_t)); eosio_assert( total == sizeof(uint64_t), "total == sizeof(uint64_t)"); eosio_assert( pub_time == publication_time(), "pub_time == publication_time()" ); }
void test_action::test_cf_action() { eosio::action act = eosio::get_action( 0, 0 ); cf_action cfa = act.data_as<cf_action>(); if ( cfa.payload == 100 ) { // verify read of get_context_free_data, also verifies system api access int size = get_context_free_data( cfa.cfd_idx, nullptr, 0 ); eosio_assert( size > 0, "size determination failed" ); eosio::bytes cfd( static_cast<size_t>(size) ); size = get_context_free_data( cfa.cfd_idx, &cfd[0], static_cast<size_t>(size) ); eosio_assert(static_cast<size_t>(size) == cfd.size(), "get_context_free_data failed" ); uint32_t v = eosio::unpack<uint32_t>( &cfd[0], cfd.size() ); eosio_assert( v == cfa.payload, "invalid value" ); // verify crypto api access checksum256 hash; char test[] = "test"; sha256( test, sizeof(test), &hash ); assert_sha256( test, sizeof(test), &hash ); // verify action api access action_data_size(); // verify console api access eosio::print("test\n"); // verify memory api access uint32_t i = 42; memccpy(&v, &i, sizeof(i), sizeof(i)); // verify transaction api access eosio_assert(transaction_size() > 0, "transaction_size failed"); // verify softfloat api access float f1 = 1.0f, f2 = 2.0f; float f3 = f1 + f2; eosio_assert( f3 > 2.0f, "Unable to add float."); // verify compiler builtin api access __int128 ret; __divti3(ret, 2, 2, 2, 2); // verify context_free_system_api eosio_assert( true, "verify eosio_assert can be called" ); } else if ( cfa.payload == 200 ) { // attempt to access non context free api, privileged_api is_privileged(act.name); eosio_assert( false, "privileged_api should not be allowed" ); } else if ( cfa.payload == 201 ) { // attempt to access non context free api, producer_api get_active_producers( nullptr, 0 ); eosio_assert( false, "producer_api should not be allowed" ); } else if ( cfa.payload == 202 ) { // attempt to access non context free api, db_api db_store_i64( N(testapi), N(testapi), N(testapi), 0, "test", 4 ); eosio_assert( false, "db_api should not be allowed" ); } else if ( cfa.payload == 203 ) { // attempt to access non context free api, db_api uint64_t i = 0; db_idx64_store( N(testapi), N(testapi), N(testapi), 0, &i ); eosio_assert( false, "db_api should not be allowed" ); } else if ( cfa.payload == 204 ) { db_find_i64( N(testapi), N(testapi), N(testapi), 1); eosio_assert( false, "db_api should not be allowed" ); } else if ( cfa.payload == 205 ) { // attempt to access non context free api, send action eosio::action dum_act; dum_act.send(); eosio_assert( false, "action send should not be allowed" ); } else if ( cfa.payload == 206 ) { eosio::require_auth(N(test)); eosio_assert( false, "authorization_api should not be allowed" ); } else if ( cfa.payload == 207 ) { now(); eosio_assert( false, "system_api should not be allowed" ); } else if ( cfa.payload == 208 ) { current_time(); eosio_assert( false, "system_api should not be allowed" ); } else if ( cfa.payload == 209 ) { publication_time(); eosio_assert( false, "system_api should not be allowed" ); } else if ( cfa.payload == 210 ) { send_inline( "hello", 6 ); eosio_assert( false, "transaction_api should not be allowed" ); } else if ( cfa.payload == 211 ) { send_deferred( N(testapi), N(testapi), "hello", 6 ); eosio_assert( false, "transaction_api should not be allowed" ); } }
void test_action::test_publication_time() { uint32_t pub_time = 0; read_action(&pub_time, sizeof(uint32_t)); eosio_assert( pub_time == publication_time(), "pub_time == publication_time()" ); }