未验证 提交 0d5bd399 编写于 作者: K Kevin Heifner 提交者: GitHub

Merge pull request #2704 from taokayan/slim_cfa

fix #2626(CFA) with additional unittests
......@@ -41,7 +41,8 @@ extern "C" {
}
WASM_TEST_HANDLER(test_action, assert_true_cf);
require_auth(code);
if (action != WASM_TEST_ACTION("test_transaction", "stateful_api") && action != WASM_TEST_ACTION("test_transaction", "context_free_api"))
require_auth(code);
//test_types
WASM_TEST_HANDLER(test_types, types_size);
......@@ -139,6 +140,8 @@ extern "C" {
WASM_TEST_HANDLER(test_transaction, cancel_deferred_transaction);
WASM_TEST_HANDLER(test_transaction, send_cf_action);
WASM_TEST_HANDLER(test_transaction, send_cf_action_fail);
WASM_TEST_HANDLER(test_transaction, stateful_api);
WASM_TEST_HANDLER(test_transaction, context_free_api);
//test chain
WASM_TEST_HANDLER(test_chain, test_activeprods);
......
......@@ -170,6 +170,8 @@ struct test_transaction {
static void cancel_deferred_transaction();
static void send_cf_action();
static void send_cf_action_fail();
static void stateful_api();
static void context_free_api();
};
struct test_chain {
......
......@@ -287,3 +287,13 @@ void test_transaction::send_cf_action_fail() {
act.send_context_free();
eosio_assert(false, "send_cfa_action_fail() should've thrown an error");
}
void test_transaction::stateful_api() {
char buf[4] = {1};
db_store_i64(N(test_transaction), N(table), N(test_transaction), 0, buf, 4);
}
void test_transaction::context_free_api() {
char buf[128] = {0};
get_context_free_data(0, buf, sizeof(buf));
}
......@@ -518,6 +518,113 @@ BOOST_FIXTURE_TEST_CASE(cfa_tx_signature, TESTER) try {
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(cfa_stateful_api, TESTER) try {
create_account( N(testapi) );
produce_blocks(1);
set_code( N(testapi), test_api_wast );
account_name a = N(testapi2);
account_name creator = N(eosio);
signed_transaction trx;
trx.actions.emplace_back( vector<permission_level>{{creator,config::active_name}},
newaccount{
.creator = creator,
.name = a,
.owner = authority( get_public_key( a, "owner" ) ),
.active = authority( get_public_key( a, "active" ) ),
.recovery = authority( get_public_key( a, "recovery" ) ),
});
action act({}, test_api_action<TEST_METHOD("test_transaction", "stateful_api")>{});
trx.context_free_actions.push_back(act);
set_transaction_headers(trx);
trx.sign( get_private_key( creator, "active" ), chain_id_type() );
BOOST_CHECK_EXCEPTION(push_transaction( trx ), fc::exception,
[&](const fc::exception &e) {
return expect_assert_message(e, "only context free api's can be used in this context");
});
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(deferred_cfa_failed, TESTER) try {
create_account( N(testapi) );
produce_blocks(1);
set_code( N(testapi), test_api_wast );
account_name a = N(testapi2);
account_name creator = N(eosio);
signed_transaction trx;
trx.actions.emplace_back( vector<permission_level>{{creator,config::active_name}},
newaccount{
.creator = creator,
.name = a,
.owner = authority( get_public_key( a, "owner" ) ),
.active = authority( get_public_key( a, "active" ) ),
.recovery = authority( get_public_key( a, "recovery" ) ),
});
action act({}, test_api_action<TEST_METHOD("test_transaction", "stateful_api")>{});
trx.context_free_actions.push_back(act);
set_transaction_headers(trx, 10, 2);
trx.sign( get_private_key( creator, "active" ), chain_id_type() );
BOOST_CHECK_EXCEPTION(push_transaction( trx ), fc::exception,
[&](const fc::exception &e) {
return expect_assert_message(e, "only context free api's can be used in this context");
});
produce_blocks(10);
// CFA failed, testapi2 not created
create_account( N(testapi2) );
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(deferred_cfa_success, TESTER) try {
create_account( N(testapi) );
produce_blocks(1);
set_code( N(testapi), test_api_wast );
account_name a = N(testapi2);
account_name creator = N(eosio);
signed_transaction trx;
trx.actions.emplace_back( vector<permission_level>{{creator,config::active_name}},
newaccount{
.creator = creator,
.name = a,
.owner = authority( get_public_key( a, "owner" ) ),
.active = authority( get_public_key( a, "active" ) ),
.recovery = authority( get_public_key( a, "recovery" ) ),
});
action act({}, test_api_action<TEST_METHOD("test_transaction", "context_free_api")>{});
trx.context_free_actions.push_back(act);
set_transaction_headers(trx, 10, 2);
trx.sign( get_private_key( creator, "active" ), chain_id_type() );
auto trace = push_transaction( trx );
BOOST_REQUIRE(trace != nullptr);
if (trace) {
BOOST_REQUIRE_EQUAL(transaction_receipt_header::status_enum::delayed, trace->receipt.status);
BOOST_REQUIRE_EQUAL(1, trace->action_traces.size());
}
produce_blocks(10);
// CFA success, testapi2 created
BOOST_CHECK_EXCEPTION(create_account( N(testapi2) ), fc::exception,
[&](const fc::exception &e) {
return expect_assert_message(e, "Cannot create account named testapi2, as that name is already taken");
});
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW()
/*************************************************************************************
* checktime_tests test case
*************************************************************************************/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册