提交 ccd9ad7b 编写于 作者: B Bart Wyatt

split nonce from the `require_auth` invoker for test system, unified users of such a thing

上级 37d50288
......@@ -34,10 +34,15 @@
{"name":"producer", "type":"producer_key[]"}
]
},{
"name": "nonce",
"name": "require_auth",
"base": "",
"fields": [
{"name":"from", "type":"account_name"},
]
},{
"name": "nonce",
"base": "",
"fields": [
{"name":"value", "type":"string"}
]
}],
......@@ -50,6 +55,9 @@
},{
"name": "setprods",
"type": "set_producers"
},{
"name": "reqauth",
"type": "require_auth"
},{
"name": "nonce",
"type": "nonce"
......
......@@ -60,11 +60,11 @@ namespace testsystem {
EOSLIB_SERIALIZE( set_producers, (version)(producers) );
};
struct nonce : dispatchable<N(nonce)> {
struct require_auth : dispatchable<N(reqauth)> {
account_name from;
static void process(const nonce& n) {
require_auth(n.from);
static void process(const require_auth& r) {
::require_auth(r.from);
}
};
......@@ -90,7 +90,7 @@ namespace testsystem {
}
};
using dispatcher = dispatcher_impl<set_account_limits, set_global_limits, set_producers, nonce>;
using dispatcher = dispatcher_impl<set_account_limits, set_global_limits, set_producers, require_auth>;
};
......
......@@ -42,6 +42,7 @@ namespace eosio { namespace testing {
void create_account( account_name name, account_name creator = config::system_account_name, bool multisig = false );
transaction_trace push_reqauth( account_name from, const vector<permission_level>& auths, const vector<private_key_type>& keys );
transaction_trace push_nonce( account_name from, const string& v = "blah" );
transaction_trace transfer( account_name from, account_name to, asset amount, string memo, account_name currency );
transaction_trace transfer( account_name from, account_name to, string amount, string memo, account_name currency );
......
......@@ -140,6 +140,28 @@ namespace eosio { namespace testing {
return success();
}
transaction_trace tester::push_reqauth( account_name from, const vector<permission_level>& auths, const vector<private_key_type>& keys ) {
variant pretty_trx = fc::mutable_variant_object()
("actions", fc::variants({
fc::mutable_variant_object()
("account", name(config::system_account_name))
("name", "reqauth")
("authorization", auths)
("data", fc::mutable_variant_object()
("from", from)
)
})
);
signed_transaction trx;
contracts::abi_serializer::from_variant(pretty_trx, trx, get_resolver());
set_tapos( trx );
for(auto iter = keys.begin(); iter != keys.end(); iter++)
trx.sign( *iter, chain_id_type() );
return push_transaction( trx );
}
transaction_trace tester::push_nonce(account_name from, const string& v) {
variant pretty_trx = fc::mutable_variant_object()
("actions", fc::variants({
......
......@@ -7,50 +7,26 @@ using namespace eosio::chain;
using namespace eosio::chain::contracts;
using namespace eosio::testing;
struct auth_tester : public tester {
transaction_trace push_nonce(account_name from, std::initializer_list<permission_level> &&permissions, std::initializer_list<private_key_type> &&sign_with) {
variant pretty_trx = fc::mutable_variant_object()
("actions", fc::variants({
fc::mutable_variant_object()
("account", name(config::system_account_name))
("name", "nonce")
("authorization", vector<permission_level>(permissions))
("data", fc::mutable_variant_object()
("from", from)
("value", fc::time_point::now())
)
})
);
signed_transaction trx;
contracts::abi_serializer::from_variant(pretty_trx, trx, get_resolver());
set_tapos( trx );
for(auto iter = sign_with.begin(); iter != sign_with.end(); iter++)
trx.sign( *iter, chain_id_type() );
return push_transaction( trx );
}
};
BOOST_AUTO_TEST_SUITE(auth_tests)
BOOST_FIXTURE_TEST_CASE( missing_sigs, auth_tester ) { try {
BOOST_FIXTURE_TEST_CASE( missing_sigs, tester ) { try {
create_accounts( {N(alice)} );
produce_block();
BOOST_REQUIRE_THROW( push_nonce( N(alice), {permission_level{N(alice), config::active_name}}, {} ), tx_missing_sigs );
auto trace = push_nonce(N(alice), {permission_level{N(alice), config::active_name}}, { get_private_key(N(alice), "active") } );
BOOST_REQUIRE_THROW( push_reqauth( N(alice), {permission_level{N(alice), config::active_name}}, {} ), tx_missing_sigs );
auto trace = push_reqauth(N(alice), {permission_level{N(alice), config::active_name}}, { get_private_key(N(alice), "active") } );
produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace.id));
} FC_LOG_AND_RETHROW() } /// missing_sigs
BOOST_FIXTURE_TEST_CASE( missing_auths, auth_tester ) { try {
BOOST_FIXTURE_TEST_CASE( missing_auths, tester ) { try {
create_accounts( {N(alice), N(bob)} );
produce_block();
/// action not provided from authority
BOOST_REQUIRE_THROW( push_nonce( N(alice), {permission_level{N(bob), config::active_name}}, { get_private_key(N(bob), "active") } ), tx_missing_auth);
BOOST_REQUIRE_THROW( push_reqauth( N(alice), {permission_level{N(bob), config::active_name}}, { get_private_key(N(bob), "active") } ), tx_missing_auth);
} FC_LOG_AND_RETHROW() } /// transfer_test
......@@ -59,7 +35,7 @@ BOOST_FIXTURE_TEST_CASE( missing_auths, auth_tester ) { try {
* This test case will attempt to allow one account to transfer on behalf
* of another account by updating the active authority.
*/
BOOST_FIXTURE_TEST_CASE( delegate_auth, auth_tester ) { try {
BOOST_FIXTURE_TEST_CASE( delegate_auth, tester ) { try {
create_accounts( {N(alice),N(bob)});
produce_block();
......@@ -73,7 +49,7 @@ BOOST_FIXTURE_TEST_CASE( delegate_auth, auth_tester ) { try {
produce_block( fc::hours(2) ); ///< skip 2 hours
/// execute nonce from alice signed by bob
auto trace = push_nonce(N(alice), {permission_level{N(alice), config::active_name}}, { get_private_key(N(bob), "active") } );
auto trace = push_reqauth(N(alice), {permission_level{N(alice), config::active_name}}, { get_private_key(N(bob), "active") } );
produce_block();
BOOST_REQUIRE_EQUAL(true, chain_has_transaction(trace.id));
......
......@@ -36,25 +36,8 @@ auto make_vetorecovery(const tester &t, account_name account, permission_name ve
}
struct recov_tester : public tester {
transaction_trace push_nonce(account_name from, string role) {
variant pretty_trx = fc::mutable_variant_object()
("actions", fc::variants({
fc::mutable_variant_object()
("account", name(config::system_account_name))
("name", "nonce")
("authorization", vector<permission_level>{{ from, config::owner_name }})
("data", fc::mutable_variant_object()
("from", from)
("value", fc::time_point::now())
)
})
);
signed_transaction trx;
contracts::abi_serializer::from_variant(pretty_trx, trx, get_resolver());
set_tapos( trx );
trx.sign( get_private_key(from, role), chain_id_type() );
return push_transaction( trx );
transaction_trace push_reqauth(account_name from, string role) {
return tester::push_reqauth(from, vector<permission_level>{{from, config::owner_name}}, {get_private_key(from, role)} );
}
};
......@@ -84,13 +67,13 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner, recov_tester ) try {
auto skip_time = expected_recovery - control->head_block_time() - fc::milliseconds(config::block_interval_ms);
produce_block(skip_time);
control->push_deferred_transactions(true);
auto last_old_nonce_id = push_nonce(N(alice), "owner").id;
auto last_old_nonce_id = push_reqauth(N(alice), "owner").id;
produce_block();
control->push_deferred_transactions(true);
BOOST_REQUIRE_EQUAL(chain_has_transaction(last_old_nonce_id), true);
BOOST_REQUIRE_THROW(push_nonce(N(alice), "owner"), tx_missing_sigs);
auto first_new_nonce_id = push_nonce(N(alice), "owner.recov").id;
BOOST_REQUIRE_THROW(push_reqauth(N(alice), "owner"), tx_missing_sigs);
auto first_new_nonce_id = push_reqauth(N(alice), "owner.recov").id;
produce_block();
BOOST_REQUIRE_EQUAL(chain_has_transaction(first_new_nonce_id), true);
......@@ -116,7 +99,7 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner_veto, recov_tester ) try {
auto skip_time = expected_recovery - control->head_block_time() - fc::milliseconds(config::block_interval_ms);
produce_block(skip_time);
control->push_deferred_transactions(true);
auto last_old_nonce_id = push_nonce(N(alice), "owner").id;
auto last_old_nonce_id = push_reqauth(N(alice), "owner").id;
// post the veto at the last possible time
{
......@@ -131,8 +114,8 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_owner_veto, recov_tester ) try {
// make sure the old owner is still in control
BOOST_REQUIRE_THROW(push_nonce(N(alice), "owner.recov"), tx_missing_sigs);
auto first_new_nonce_id = push_nonce(N(alice), "owner").id;
BOOST_REQUIRE_THROW(push_reqauth(N(alice), "owner.recov"), tx_missing_sigs);
auto first_new_nonce_id = push_reqauth(N(alice), "owner").id;
produce_block();
BOOST_REQUIRE_EQUAL(chain_has_transaction(first_new_nonce_id), true);
......@@ -184,7 +167,7 @@ BOOST_FIXTURE_TEST_CASE( test_recovery_bad_creator, recov_tester ) try {
control->push_deferred_transactions(true);
// make sure the recovery goes through
auto first_new_nonce_id = push_nonce(N(alice), "owner").id;
auto first_new_nonce_id = push_reqauth(N(alice), "owner").id;
produce_block();
BOOST_REQUIRE_EQUAL(chain_has_transaction(first_new_nonce_id), true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册