move delete_auth from delay_tests.cpp to auth_tests.cpp

This commit is contained in:
Lin Huang
2023-09-25 08:34:04 -04:00
parent 0310c57001
commit 218f933fce
2 changed files with 136 additions and 135 deletions
+136
View File
@@ -9,6 +9,8 @@
#include <eosio/testing/tester_network.hpp>
#include <test_contracts.hpp>
using namespace eosio;
using namespace eosio::chain;
using namespace eosio::testing;
@@ -550,5 +552,139 @@ BOOST_AUTO_TEST_CASE( linkauth_special ) { try {
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(delete_auth) { try {
validating_tester chain;
const auto& tester_account = "tester"_n;
chain.produce_blocks();
chain.create_account("eosio.token"_n);
chain.produce_blocks(10);
chain.set_code("eosio.token"_n, test_contracts::eosio_token_wasm());
chain.set_abi("eosio.token"_n, test_contracts::eosio_token_abi());
chain.produce_blocks();
chain.create_account("tester"_n);
chain.create_account("tester2"_n);
chain.produce_blocks(10);
transaction_trace_ptr trace;
// can't delete auth because it doesn't exist
BOOST_REQUIRE_EXCEPTION(
trace = chain.push_action(config::system_account_name, deleteauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first")),
permission_query_exception,
[] (const permission_query_exception &e)->bool {
expect_assert_message(e, "permission_query_exception: Permission Query Exception\nFailed to retrieve permission");
return true;
});
// update auth
chain.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first")
("parent", "active")
("auth", authority(chain.get_public_key(tester_account, "first")))
);
// link auth
chain.push_action(config::system_account_name, linkauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("code", "eosio.token")
("type", "transfer")
("requirement", "first"));
// create CUR token
chain.produce_blocks();
chain.push_action("eosio.token"_n, "create"_n, "eosio.token"_n, mutable_variant_object()
("issuer", "eosio.token" )
("maximum_supply", "9000000.0000 CUR" )
);
// issue to account "eosio.token"
chain.push_action("eosio.token"_n, name("issue"), "eosio.token"_n, fc::mutable_variant_object()
("to", "eosio.token")
("quantity", "1000000.0000 CUR")
("memo", "for stuff")
);
// transfer from eosio.token to tester
trace = chain.push_action("eosio.token"_n, name("transfer"), "eosio.token"_n, fc::mutable_variant_object()
("from", "eosio.token")
("to", "tester")
("quantity", "100.0000 CUR")
("memo", "hi" )
);
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
chain.produce_blocks();
auto liquid_balance = chain.get_currency_balance("eosio.token"_n, symbol(SY(4,CUR)), "eosio.token"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("999900.0000 CUR"), liquid_balance);
liquid_balance = chain.get_currency_balance("eosio.token"_n, symbol(SY(4,CUR)), "tester"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("100.0000 CUR"), liquid_balance);
trace = chain.push_action("eosio.token"_n, name("transfer"), "tester"_n, fc::mutable_variant_object()
("from", "tester")
("to", "tester2")
("quantity", "1.0000 CUR")
("memo", "hi" )
);
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
liquid_balance = chain.get_currency_balance("eosio.token"_n, symbol(SY(4,CUR)), "eosio.token"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("999900.0000 CUR"), liquid_balance);
liquid_balance = chain.get_currency_balance("eosio.token"_n, symbol(SY(4,CUR)), "tester"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("99.0000 CUR"), liquid_balance);
liquid_balance = chain.get_currency_balance("eosio.token"_n, symbol(SY(4,CUR)), "tester2"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("1.0000 CUR"), liquid_balance);
// can't delete auth because it's linked
BOOST_REQUIRE_EXCEPTION(
trace = chain.push_action(config::system_account_name, deleteauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first")),
action_validate_exception,
[] (const action_validate_exception &e)->bool {
expect_assert_message(e, "action_validate_exception: message validation exception\nCannot delete a linked authority");
return true;
});
// unlink auth
trace = chain.push_action(config::system_account_name, unlinkauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("code", "eosio.token")
("type", "transfer"));
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
// delete auth
trace = chain.push_action(config::system_account_name, deleteauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first"));
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
chain.produce_blocks(1);;
trace = chain.push_action("eosio.token"_n, name("transfer"), "tester"_n, fc::mutable_variant_object()
("from", "tester")
("to", "tester2")
("quantity", "3.0000 CUR")
("memo", "hi" )
);
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
chain.produce_blocks();
liquid_balance = chain.get_currency_balance("eosio.token"_n, symbol(SY(4,CUR)), "tester"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("96.0000 CUR"), liquid_balance);
liquid_balance = chain.get_currency_balance("eosio.token"_n, symbol(SY(4,CUR)), "tester2"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("4.0000 CUR"), liquid_balance);
} FC_LOG_AND_RETHROW() }/// delete_auth
BOOST_AUTO_TEST_SUITE_END()
-135
View File
@@ -154,141 +154,6 @@ BOOST_AUTO_TEST_CASE( delayed_action ) { try {
});
} FC_LOG_AND_RETHROW() }/// schedule_test
BOOST_AUTO_TEST_CASE(delete_auth_test) { try {
validating_tester chain;
const auto& tester_account = "tester"_n;
chain.produce_blocks();
chain.create_account("eosio.token"_n);
chain.produce_blocks(10);
chain.set_code("eosio.token"_n, test_contracts::eosio_token_wasm());
chain.set_abi("eosio.token"_n, test_contracts::eosio_token_abi());
chain.produce_blocks();
chain.create_account("tester"_n);
chain.create_account("tester2"_n);
chain.produce_blocks(10);
transaction_trace_ptr trace;
// can't delete auth because it doesn't exist
BOOST_REQUIRE_EXCEPTION(
trace = chain.push_action(config::system_account_name, deleteauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first")),
permission_query_exception,
[] (const permission_query_exception &e)->bool {
expect_assert_message(e, "permission_query_exception: Permission Query Exception\nFailed to retrieve permission");
return true;
});
// update auth
chain.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first")
("parent", "active")
("auth", authority(chain.get_public_key(tester_account, "first")))
);
// link auth
chain.push_action(config::system_account_name, linkauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("code", "eosio.token")
("type", "transfer")
("requirement", "first"));
// create CUR token
chain.produce_blocks();
chain.push_action("eosio.token"_n, "create"_n, "eosio.token"_n, mutable_variant_object()
("issuer", "eosio.token" )
("maximum_supply", "9000000.0000 CUR" )
);
// issue to account "eosio.token"
chain.push_action("eosio.token"_n, name("issue"), "eosio.token"_n, fc::mutable_variant_object()
("to", "eosio.token")
("quantity", "1000000.0000 CUR")
("memo", "for stuff")
);
// transfer from eosio.token to tester
trace = chain.push_action("eosio.token"_n, name("transfer"), "eosio.token"_n, fc::mutable_variant_object()
("from", "eosio.token")
("to", "tester")
("quantity", "100.0000 CUR")
("memo", "hi" )
);
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
chain.produce_blocks();
auto liquid_balance = get_currency_balance(chain, "eosio.token"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("999900.0000 CUR"), liquid_balance);
liquid_balance = get_currency_balance(chain, "tester"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("100.0000 CUR"), liquid_balance);
trace = chain.push_action("eosio.token"_n, name("transfer"), "tester"_n, fc::mutable_variant_object()
("from", "tester")
("to", "tester2")
("quantity", "1.0000 CUR")
("memo", "hi" )
);
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
liquid_balance = get_currency_balance(chain, "eosio.token"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("999900.0000 CUR"), liquid_balance);
liquid_balance = get_currency_balance(chain, "tester"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("99.0000 CUR"), liquid_balance);
liquid_balance = get_currency_balance(chain, "tester2"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("1.0000 CUR"), liquid_balance);
// can't delete auth because it's linked
BOOST_REQUIRE_EXCEPTION(
trace = chain.push_action(config::system_account_name, deleteauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first")),
action_validate_exception,
[] (const action_validate_exception &e)->bool {
expect_assert_message(e, "action_validate_exception: message validation exception\nCannot delete a linked authority");
return true;
});
// unlink auth
trace = chain.push_action(config::system_account_name, unlinkauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("code", "eosio.token")
("type", "transfer"));
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
// delete auth
trace = chain.push_action(config::system_account_name, deleteauth::get_name(), tester_account, fc::mutable_variant_object()
("account", "tester")
("permission", "first"));
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
chain.produce_blocks(1);;
trace = chain.push_action("eosio.token"_n, name("transfer"), "tester"_n, fc::mutable_variant_object()
("from", "tester")
("to", "tester2")
("quantity", "3.0000 CUR")
("memo", "hi" )
);
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace->receipt->status);
chain.produce_blocks();
liquid_balance = get_currency_balance(chain, "tester"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("96.0000 CUR"), liquid_balance);
liquid_balance = get_currency_balance(chain, "tester2"_n);
BOOST_REQUIRE_EQUAL(asset::from_string("4.0000 CUR"), liquid_balance);
} FC_LOG_AND_RETHROW() }/// delete_auth_test
BOOST_AUTO_TEST_CASE( test_blockchain_params_enabled ) { try {
//since validation_tester activates all features here we will test how setparams works without
//blockchain_parameters enabled