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

Merge pull request #2756 from taokayan/slim_newapi

add unitest cases for new api feature
......@@ -142,6 +142,8 @@ extern "C" {
WASM_TEST_HANDLER(test_transaction, send_cf_action_fail);
WASM_TEST_HANDLER(test_transaction, stateful_api);
WASM_TEST_HANDLER(test_transaction, context_free_api);
WASM_TEST_HANDLER(test_transaction, new_feature);
WASM_TEST_HANDLER(test_transaction, active_new_feature);
//test chain
WASM_TEST_HANDLER(test_chain, test_activeprods);
......
......@@ -172,6 +172,8 @@ struct test_transaction {
static void send_cf_action_fail();
static void stateful_api();
static void context_free_api();
static void new_feature();
static void active_new_feature();
};
struct test_chain {
......
......@@ -297,3 +297,12 @@ void test_transaction::context_free_api() {
char buf[128] = {0};
get_context_free_data(0, buf, sizeof(buf));
}
extern "C" { int is_feature_active(int64_t); }
void test_transaction::new_feature() {
eosio_assert(false == is_feature_active(N(newfeature)), "we should not have new features unless hardfork");
}
void test_transaction::active_new_feature() {
activate_feature(N(newfeature));
}
......@@ -1652,4 +1652,57 @@ BOOST_FIXTURE_TEST_CASE(datastream_tests, TESTER) { try {
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW() }
/*************************************************************************************
* new api feature test
*************************************************************************************/
BOOST_FIXTURE_TEST_CASE(new_api_feature_tests, TESTER) { try {
produce_blocks(1);
create_account(N(testapi) );
produce_blocks(1);
set_code(N(testapi), test_api_wast);
produce_blocks(1);
BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( *this, "test_transaction", "new_feature", {} ),
assert_exception,
[](const fc::exception& e) {
return expect_assert_message(e, "context.privileged: testapi does not have permission to call this API");
});
BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( *this, "test_transaction", "active_new_feature", {} ),
assert_exception,
[](const fc::exception& e) {
return expect_assert_message(e, "context.privileged: testapi does not have permission to call this API");
});
// change privilege
{
chainbase::database &db = control->db();
const account_object &account = db.get<account_object, by_name>(N(testapi));
db.modify(account, [&](account_object &v) {
v.privileged = true;
});
}
#ifndef NON_VALIDATING_TEST
{
chainbase::database &db = validating_node->db();
const account_object &account = db.get<account_object, by_name>(N(testapi));
db.modify(account, [&](account_object &v) {
v.privileged = true;
});
}
#endif
CALL_TEST_FUNCTION( *this, "test_transaction", "new_feature", {} );
BOOST_CHECK_EXCEPTION( CALL_TEST_FUNCTION( *this, "test_transaction", "active_new_feature", {} ),
assert_exception,
[](const fc::exception& e) {
return expect_assert_message(e, "Unsupported Hardfork Detected");
});
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册