提交 07675d86 编写于 作者: B Bill Hamilton

Merge branch 'master' into eosio_build_centos

Merging master to avoid conflicts
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
...@@ -83,5 +83,5 @@ ...@@ -83,5 +83,5 @@
"key_types" : ["uint64"] "key_types" : ["uint64"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -213,5 +213,5 @@ ...@@ -213,5 +213,5 @@
"type": "account" "type": "account"
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -76,5 +76,5 @@ ...@@ -76,5 +76,5 @@
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
...@@ -125,5 +125,5 @@ ...@@ -125,5 +125,5 @@
"key_types" : ["name"] "key_types" : ["name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -239,5 +239,5 @@ ...@@ -239,5 +239,5 @@
], ],
"tables": [ "tables": [
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -72,5 +72,5 @@ ...@@ -72,5 +72,5 @@
"key_types" : ["uint64"] "key_types" : ["uint64"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -160,5 +160,5 @@ ...@@ -160,5 +160,5 @@
"key_types" : ["uint64"] "key_types" : ["uint64"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -112,5 +112,5 @@ ...@@ -112,5 +112,5 @@
"key_types": [ "account_name" ] "key_types": [ "account_name" ]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -15,5 +15,5 @@ ...@@ -15,5 +15,5 @@
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
...@@ -21,5 +21,5 @@ ...@@ -21,5 +21,5 @@
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
...@@ -35,5 +35,5 @@ ...@@ -35,5 +35,5 @@
"key_types" : ["name"] "key_types" : ["name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -35,5 +35,5 @@ ...@@ -35,5 +35,5 @@
"key_types" : ["name"] "key_types" : ["name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -41,5 +41,5 @@ ...@@ -41,5 +41,5 @@
"key_types" : ["my_account_name"] "key_types" : ["my_account_name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -76,5 +76,5 @@ ...@@ -76,5 +76,5 @@
"key_types" : ["account_name"] "key_types" : ["account_name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
...@@ -76,7 +76,7 @@ abi_def chain_initializer::eos_contract_abi(const abi_def& eosio_system_abi) ...@@ -76,7 +76,7 @@ abi_def chain_initializer::eos_contract_abi(const abi_def& eosio_system_abi)
eos_abi.actions.push_back( action_def{name("onblock"), "onblock",""} ); eos_abi.actions.push_back( action_def{name("onblock"), "onblock",""} );
eos_abi.actions.push_back( action_def{name("canceldelay"), "canceldelay",""} ); eos_abi.actions.push_back( action_def{name("canceldelay"), "canceldelay",""} );
// TODO add any clauses // TODO add any ricardian_clauses
// //
// ACTION PAYLOADS // ACTION PAYLOADS
...@@ -304,7 +304,7 @@ abi_def chain_initializer::eos_contract_abi(const abi_def& eosio_system_abi) ...@@ -304,7 +304,7 @@ abi_def chain_initializer::eos_contract_abi(const abi_def& eosio_system_abi)
{"structs", "struct_def[]"}, {"structs", "struct_def[]"},
{"actions", "action_def[]"}, {"actions", "action_def[]"},
{"tables", "table_def[]"}, {"tables", "table_def[]"},
{"clauses", "clause_pair[]"} {"ricardian_clauses", "clause_pair[]"}
} }
}); });
......
...@@ -118,7 +118,7 @@ inline bool validate( const Authority& auth ) { ...@@ -118,7 +118,7 @@ inline bool validate( const Authority& auth ) {
total_weight += a.weight; total_weight += a.weight;
pa = &a; pa = &a;
} }
return total_weight > 0 && total_weight >= auth.threshold; return auth.threshold > 0 && total_weight >= auth.threshold;
} }
} } // namespace eosio::chain } } // namespace eosio::chain
......
...@@ -102,14 +102,14 @@ struct clause_pair { ...@@ -102,14 +102,14 @@ struct clause_pair {
struct abi_def { struct abi_def {
abi_def() = default; abi_def() = default;
abi_def(const vector<type_def>& types, const vector<struct_def>& structs, const vector<action_def>& actions, const vector<table_def>& tables, const vector<clause_pair>& clauses) abi_def(const vector<type_def>& types, const vector<struct_def>& structs, const vector<action_def>& actions, const vector<table_def>& tables, const vector<clause_pair>& clauses)
:types(types), structs(structs), actions(actions), tables(tables), clauses(clauses) :types(types), structs(structs), actions(actions), tables(tables), ricardian_clauses(clauses)
{} {}
vector<type_def> types; vector<type_def> types;
vector<struct_def> structs; vector<struct_def> structs;
vector<action_def> actions; vector<action_def> actions;
vector<table_def> tables; vector<table_def> tables;
vector<clause_pair> clauses; vector<clause_pair> ricardian_clauses;
}; };
struct newaccount { struct newaccount {
...@@ -301,7 +301,7 @@ FC_REFLECT( eosio::chain::contracts::struct_def , (name)(b ...@@ -301,7 +301,7 @@ FC_REFLECT( eosio::chain::contracts::struct_def , (name)(b
FC_REFLECT( eosio::chain::contracts::action_def , (name)(type)(ricardian_contract) ) FC_REFLECT( eosio::chain::contracts::action_def , (name)(type)(ricardian_contract) )
FC_REFLECT( eosio::chain::contracts::clause_pair , (id)(body) ) FC_REFLECT( eosio::chain::contracts::clause_pair , (id)(body) )
FC_REFLECT( eosio::chain::contracts::table_def , (name)(index_type)(key_names)(key_types)(type) ) FC_REFLECT( eosio::chain::contracts::table_def , (name)(index_type)(key_names)(key_types)(type) )
FC_REFLECT( eosio::chain::contracts::abi_def , (types)(structs)(actions)(tables)(clauses) ) FC_REFLECT( eosio::chain::contracts::abi_def , (types)(structs)(actions)(tables)(ricardian_clauses) )
FC_REFLECT( eosio::chain::contracts::newaccount , (creator)(name)(owner)(active)(recovery) ) FC_REFLECT( eosio::chain::contracts::newaccount , (creator)(name)(owner)(active)(recovery) )
FC_REFLECT( eosio::chain::contracts::setcode , (account)(vmtype)(vmversion)(code) ) //abi FC_REFLECT( eosio::chain::contracts::setcode , (account)(vmtype)(vmversion)(code) ) //abi
......
...@@ -36,7 +36,7 @@ namespace eosio { namespace chain { namespace resource_limits { ...@@ -36,7 +36,7 @@ namespace eosio { namespace chain { namespace resource_limits {
uint32_t last_ordinal; ///< The ordinal of the last period which has contributed to the average uint32_t last_ordinal; ///< The ordinal of the last period which has contributed to the average
uint64_t value_ex; ///< The current average pre-multiplied by Precision uint64_t value_ex; ///< The current average pre-multiplied by Precision
uint64_t consumed; ///< The the last periods average + the current periods contribution so far uint64_t consumed; ///< The last periods average + the current periods contribution so far
/** /**
* return the average value * return the average value
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
#include <eosio/testing/tester.hpp> #include <eosio/testing/tester.hpp>
#include <eosio/chain/contracts/abi_serializer.hpp> #include <eosio/chain/contracts/abi_serializer.hpp>
#include <eosio/chain/resource_limits.hpp>
#include <eosio/chain/resource_limits_private.hpp>
#ifdef NON_VALIDATING_TEST #ifdef NON_VALIDATING_TEST
#define TESTER tester #define TESTER tester
#else #else
...@@ -318,4 +321,114 @@ BOOST_AUTO_TEST_CASE( any_auth ) { try { ...@@ -318,4 +321,114 @@ BOOST_AUTO_TEST_CASE( any_auth ) { try {
} FC_LOG_AND_RETHROW() } } FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(no_double_billing) {
try {
TESTER chain;
chain.produce_block();
account_name acc1 = N("bill1");
account_name acc2 = N("bill2");
account_name acc1a = N("bill1a");
chain.create_account(acc1);
chain.create_account(acc1a);
chain.produce_block();
chainbase::database &db = chain.control->get_mutable_database();
using resource_usage_object = eosio::chain::resource_limits::resource_usage_object;
using by_owner = eosio::chain::resource_limits::by_owner;
auto create_acc = [&](account_name a) {
signed_transaction trx;
chain.set_transaction_headers(trx);
authority owner_auth = authority( chain.get_public_key( a, "owner" ) );
vector<permission_level> pls = {{acc1, "active"}};
pls.push_back({acc1, "owner"}); // same account but different permission names
pls.push_back({acc1a, "owner"});
trx.actions.emplace_back( pls,
contracts::newaccount{
.creator = acc1,
.name = a,
.owner = owner_auth,
.active = authority( chain.get_public_key( a, "active" ) ),
.recovery = authority( chain.get_public_key( a, "recovery" ) ),
});
chain.set_transaction_headers(trx);
trx.sign( chain.get_private_key( acc1, "active" ), chain_id_type() );
trx.sign( chain.get_private_key( acc1, "owner" ), chain_id_type() );
trx.sign( chain.get_private_key( acc1a, "owner" ), chain_id_type() );
return chain.push_transaction( trx );
};
create_acc(acc2);
const auto &usage = db.get<resource_usage_object,by_owner>(acc1);
const auto &usage2 = db.get<resource_usage_object,by_owner>(acc1a);
BOOST_TEST(usage.cpu_usage.average() > 0);
BOOST_TEST(usage.net_usage.average() > 0);
BOOST_REQUIRE_EQUAL(usage.cpu_usage.average(), usage2.cpu_usage.average());
BOOST_REQUIRE_EQUAL(usage.net_usage.average(), usage2.net_usage.average());
chain.produce_block();
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(stricter_auth) {
try {
TESTER chain;
chain.produce_block();
account_name acc1 = N("acc1");
account_name acc2 = N("acc2");
account_name acc3 = N("acc3");
account_name acc4 = N("acc4");
chain.create_account(acc1);
chain.produce_block();
auto create_acc = [&](account_name a, account_name creator, int threshold) {
signed_transaction trx;
chain.set_transaction_headers(trx);
authority invalid_auth = authority(threshold, {key_weight{chain.get_public_key( a, "owner" ), 1}}, {permission_level_weight{{creator, config::active_name}, 1}});
vector<permission_level> pls;
pls.push_back({creator, "active"});
trx.actions.emplace_back( pls,
contracts::newaccount{
.creator = creator,
.name = a,
.owner = authority( chain.get_public_key( a, "owner" ) ),
.active = invalid_auth,//authority( chain.get_public_key( a, "active" ) ),
.recovery = authority( chain.get_public_key( a, "recovery" ) ),
});
chain.set_transaction_headers(trx);
trx.sign( chain.get_private_key( creator, "active" ), chain_id_type() );
return chain.push_transaction( trx );
};
try {
create_acc(acc2, acc1, 0);
BOOST_FAIL("threshold can't be zero");
} catch (...) { }
try {
create_acc(acc4, acc1, 3);
BOOST_FAIL("threshold can't be more than total weight");
} catch (...) { }
create_acc(acc3, acc1, 1);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
...@@ -328,7 +328,7 @@ const char* my_abi = R"=====( ...@@ -328,7 +328,7 @@ const char* my_abi = R"=====(
], ],
"actions": [], "actions": [],
"tables": [], "tables": [],
"clauses": [{"id":"clause A","body":"clause body A"}, "ricardian_clauses": [{"id":"clause A","body":"clause body A"},
{"id":"clause B","body":"clause body B"}] {"id":"clause B","body":"clause body B"}]
} }
)====="; )=====";
...@@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(uint_types) ...@@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(uint_types)
}], }],
"actions": [], "actions": [],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -654,7 +654,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_all_types, abi_gen_helper) ...@@ -654,7 +654,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_all_types, abi_gen_helper)
"type" : "test_struct" "type" : "test_struct"
}], }],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
BOOST_TEST( generate_abi(all_types, all_types_abi) == true); BOOST_TEST( generate_abi(all_types, all_types_abi) == true);
...@@ -895,7 +895,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_all_indexes, abi_gen_helper) ...@@ -895,7 +895,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_all_indexes, abi_gen_helper)
}, },
], ],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1053,7 +1053,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_full_table_decl, abi_gen_helper) ...@@ -1053,7 +1053,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_full_table_decl, abi_gen_helper)
"uint64" "uint64"
] ]
}], }],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1105,7 +1105,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_str_table_decl, abi_gen_helper) ...@@ -1105,7 +1105,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_str_table_decl, abi_gen_helper)
"type": "table1" "type": "table1"
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1203,7 +1203,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_template_base, abi_gen_helper) ...@@ -1203,7 +1203,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_template_base, abi_gen_helper)
"uint64" "uint64"
] ]
}], }],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1255,7 +1255,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_action_and_table, abi_gen_helper) ...@@ -1255,7 +1255,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_action_and_table, abi_gen_helper)
"uint64" "uint64"
] ]
}], }],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1319,7 +1319,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_simple_typedef, abi_gen_helper) ...@@ -1319,7 +1319,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_simple_typedef, abi_gen_helper)
"ricardian_contract" : "" "ricardian_contract" : ""
}], }],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1397,7 +1397,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_field_typedef, abi_gen_helper) ...@@ -1397,7 +1397,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_field_typedef, abi_gen_helper)
"uint64" "uint64"
] ]
}], }],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1465,7 +1465,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_vector_of_POD, abi_gen_helper) ...@@ -1465,7 +1465,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_vector_of_POD, abi_gen_helper)
"type": "table1" "type": "table1"
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1549,7 +1549,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_vector_of_structs, abi_gen_helper) ...@@ -1549,7 +1549,7 @@ BOOST_FIXTURE_TEST_CASE(abigen_vector_of_structs, abi_gen_helper)
"type": "table1" "type": "table1"
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1640,7 +1640,7 @@ BOOST_FIXTURE_TEST_CASE(abgigen_vector_alias, abi_gen_helper) ...@@ -1640,7 +1640,7 @@ BOOST_FIXTURE_TEST_CASE(abgigen_vector_alias, abi_gen_helper)
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1700,7 +1700,7 @@ BOOST_FIXTURE_TEST_CASE(abgigen_eosioabi_macro, abi_gen_helper) ...@@ -1700,7 +1700,7 @@ BOOST_FIXTURE_TEST_CASE(abgigen_eosioabi_macro, abi_gen_helper)
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1773,7 +1773,7 @@ BOOST_FIXTURE_TEST_CASE(abgigen_contract_inheritance, abi_gen_helper) ...@@ -1773,7 +1773,7 @@ BOOST_FIXTURE_TEST_CASE(abgigen_contract_inheritance, abi_gen_helper)
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -1957,20 +1957,20 @@ BOOST_AUTO_TEST_CASE(general) ...@@ -1957,20 +1957,20 @@ BOOST_AUTO_TEST_CASE(general)
"structs" : [{"name":"struct1", "base":"base1", "fields": [{"name":"name1", "type": "type1"}, {"name":"name2", "type": "type2"}] }], "structs" : [{"name":"struct1", "base":"base1", "fields": [{"name":"name1", "type": "type1"}, {"name":"name2", "type": "type2"}] }],
"actions" : [{"name":"action1","type":"type1", "ricardian_contract":""}], "actions" : [{"name":"action1","type":"type1", "ricardian_contract":""}],
"tables" : [{"name":"table1","index_type":"indextype1","key_names":["keyname1"],"key_types":["typename1"],"type":"type1"}], "tables" : [{"name":"table1","index_type":"indextype1","key_names":["keyname1"],"key_types":["typename1"],"type":"type1"}],
"clauses": [] "ricardian_clauses": []
}, },
"abidef_arr": [{ "abidef_arr": [{
"types" : [{"new_type_name":"new", "type":"old"}], "types" : [{"new_type_name":"new", "type":"old"}],
"structs" : [{"name":"struct1", "base":"base1", "fields": [{"name":"name1", "type": "type1"}, {"name":"name2", "type": "type2"}] }], "structs" : [{"name":"struct1", "base":"base1", "fields": [{"name":"name1", "type": "type1"}, {"name":"name2", "type": "type2"}] }],
"actions" : [{"name":"action1","type":"type1", "ricardian_contract":""}], "actions" : [{"name":"action1","type":"type1", "ricardian_contract":""}],
"tables" : [{"name":"table1","index_type":"indextype1","key_names":["keyname1"],"key_types":["typename1"],"type":"type1"}], "tables" : [{"name":"table1","index_type":"indextype1","key_names":["keyname1"],"key_types":["typename1"],"type":"type1"}],
"clauses": [] "ricardian_clauses": []
},{ },{
"types" : [{"new_type_name":"new", "type":"old"}], "types" : [{"new_type_name":"new", "type":"old"}],
"structs" : [{"name":"struct1", "base":"base1", "fields": [{"name":"name1", "type": "type1"}, {"name":"name2", "type": "type2"}] }], "structs" : [{"name":"struct1", "base":"base1", "fields": [{"name":"name1", "type": "type1"}, {"name":"name2", "type": "type2"}] }],
"actions" : [{"name":"action1","type":"type1", "ricardian_contract": ""}], "actions" : [{"name":"action1","type":"type1", "ricardian_contract": ""}],
"tables" : [{"name":"table1","index_type":"indextype1","key_names":["keyname1"],"key_types":["typename1"],"type":"type1"}], "tables" : [{"name":"table1","index_type":"indextype1","key_names":["keyname1"],"key_types":["typename1"],"type":"type1"}],
"clauses": [] "ricardian_clauses": []
}] }]
} }
)====="; )=====";
...@@ -1995,7 +1995,7 @@ BOOST_AUTO_TEST_CASE(abi_cycle) ...@@ -1995,7 +1995,7 @@ BOOST_AUTO_TEST_CASE(abi_cycle)
"structs": [], "structs": [],
"actions": [], "actions": [],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -2017,7 +2017,7 @@ BOOST_AUTO_TEST_CASE(abi_cycle) ...@@ -2017,7 +2017,7 @@ BOOST_AUTO_TEST_CASE(abi_cycle)
}], }],
"actions": [], "actions": [],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -2437,7 +2437,7 @@ BOOST_AUTO_TEST_CASE(setabi) ...@@ -2437,7 +2437,7 @@ BOOST_AUTO_TEST_CASE(setabi)
"key_types" : ["name"] "key_types" : ["name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
} }
)====="; )=====";
...@@ -2803,7 +2803,7 @@ BOOST_AUTO_TEST_CASE(packed_transaction) ...@@ -2803,7 +2803,7 @@ BOOST_AUTO_TEST_CASE(packed_transaction)
} }
], ],
"tables": [], "tables": [],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
fc::variant var; fc::variant var;
...@@ -2879,7 +2879,7 @@ BOOST_AUTO_TEST_CASE(abi_type_repeat) ...@@ -2879,7 +2879,7 @@ BOOST_AUTO_TEST_CASE(abi_type_repeat)
"key_types" : ["name"] "key_types" : ["name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -2936,7 +2936,7 @@ BOOST_AUTO_TEST_CASE(abi_struct_repeat) ...@@ -2936,7 +2936,7 @@ BOOST_AUTO_TEST_CASE(abi_struct_repeat)
"key_types" : ["name"] "key_types" : ["name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
...@@ -2996,7 +2996,7 @@ BOOST_AUTO_TEST_CASE(abi_action_repeat) ...@@ -2996,7 +2996,7 @@ BOOST_AUTO_TEST_CASE(abi_action_repeat)
"key_types" : ["name"] "key_types" : ["name"]
} }
], ],
"clauses": [] "ricardian_clauses": []
} }
)====="; )=====";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册