提交 bf230e9c 编写于 作者: D Daniel Larimer

progress testing system

上级 e2c6a8b0
...@@ -29,7 +29,22 @@ ...@@ -29,7 +29,22 @@
"fields": [ "fields": [
{"name":"value", "type":"string"} {"name":"value", "type":"string"}
] ]
},{
"name": "regproducer",
"base": "",
"fields": [
{"name":"producer", "type":"account_name"}
{"name":"producer_key", "type":"bytes"}
]
},{
"name": "stakevote",
"base": "",
"fields": [
{"name":"voter", "type":"account_name"}
{"name":"amount", "type":"asset"}
]
} }
], ],
"actions": [{ "actions": [{
"name": "transfer", "name": "transfer",
...@@ -40,6 +55,12 @@ ...@@ -40,6 +55,12 @@
},{ },{
"name": "nonce", "name": "nonce",
"type": "nonce" "type": "nonce"
},{
"name": "regproducer",
"type": "regproducer"
},{
"name": "stakevote",
"type": "stakevote"
} }
], ],
"tables": [{ "tables": [{
...@@ -50,4 +71,4 @@ ...@@ -50,4 +71,4 @@
"key_types" : ["name"] "key_types" : ["name"]
} }
] ]
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ extern "C" { ...@@ -11,6 +11,7 @@ extern "C" {
/// The apply method implements the dispatch of events to this contract /// The apply method implements the dispatch of events to this contract
void apply( uint64_t code, uint64_t act ) { void apply( uint64_t code, uint64_t act ) {
print( name(code), "::", name(act) );
eosiosystem::contract<N(eosio)>::apply( code, act ); eosiosystem::contract<N(eosio)>::apply( code, act );
} }
} }
...@@ -23,6 +23,7 @@ namespace eosiosystem { ...@@ -23,6 +23,7 @@ namespace eosiosystem {
using eosio::bytes; using eosio::bytes;
using std::map; using std::map;
using std::pair; using std::pair;
using eosio::print;
template<account_name SystemAccount> template<account_name SystemAccount>
class contract { class contract {
...@@ -116,10 +117,10 @@ namespace eosiosystem { ...@@ -116,10 +117,10 @@ namespace eosiosystem {
}; };
ACTION( SystemAccount, regproducer ) { ACTION( SystemAccount, regproducer ) {
account_name producer_to_register; account_name producer;
bytes producer_key; bytes producer_key;
EOSLIB_SERIALIZE( regproducer, (producer_to_register)(producer_key) ); EOSLIB_SERIALIZE( regproducer, (producer)(producer_key) );
}; };
ACTION( SystemAccount, regproxy ) { ACTION( SystemAccount, regproxy ) {
...@@ -250,7 +251,7 @@ namespace eosiosystem { ...@@ -250,7 +251,7 @@ namespace eosiosystem {
/** /**
* This method will create a producr_config and producer_votes object for 'producer_to_register' * This method will create a producr_config and producer_votes object for 'producer'
* *
* @pre producer is not already registered * @pre producer is not already registered
* @pre producer to register is an account * @pre producer to register is an account
...@@ -258,7 +259,7 @@ namespace eosiosystem { ...@@ -258,7 +259,7 @@ namespace eosiosystem {
* *
*/ */
static void on( const regproducer& reg ) { static void on( const regproducer& reg ) {
auto producer = reg.producer_to_register; auto producer = reg.producer;
require_auth( producer ); require_auth( producer );
producer_votes_index_type votes( SystemAccount, SystemAccount ); producer_votes_index_type votes( SystemAccount, SystemAccount );
...@@ -279,14 +280,16 @@ namespace eosiosystem { ...@@ -279,14 +280,16 @@ namespace eosiosystem {
ACTION( SystemAccount, stakevote ) { ACTION( SystemAccount, stakevote ) {
account_name voter; account_name voter;
system_token_type amount_to_stake; system_token_type amount;
EOSLIB_SERIALIZE( stakevote, (voter)(amount_to_stake) ) EOSLIB_SERIALIZE( stakevote, (voter)(amount) )
}; };
static void on( const stakevote& sv ) { static void on( const stakevote& sv ) {
eosio_assert( sv.amount_to_stake.quantity > 0, "must stake some tokens" ); print( "on stake vote\n" );
eosio_assert( sv.amount.quantity > 0, "must stake some tokens" );
require_auth( sv.voter ); require_auth( sv.voter );
return;
account_votes_index_type avotes( SystemAccount, SystemAccount ); account_votes_index_type avotes( SystemAccount, SystemAccount );
...@@ -300,7 +303,7 @@ namespace eosiosystem { ...@@ -300,7 +303,7 @@ namespace eosiosystem {
} }
uint128_t old_weight = acv->staked.quantity; uint128_t old_weight = acv->staked.quantity;
uint128_t new_weight = old_weight + sv.amount_to_stake.quantity; uint128_t new_weight = old_weight + sv.amount.quantity;
producer_votes_index_type votes( SystemAccount, SystemAccount ); producer_votes_index_type votes( SystemAccount, SystemAccount );
...@@ -313,10 +316,10 @@ namespace eosiosystem { ...@@ -313,10 +316,10 @@ namespace eosiosystem {
avotes.update( *acv, 0, [&]( auto av ) { avotes.update( *acv, 0, [&]( auto av ) {
av.last_update = now(); av.last_update = now();
av.staked += sv.amount_to_stake; av.staked += sv.amount;
}); });
currency::inline_transfer( sv.voter, SystemAccount, sv.amount_to_stake, "stake for voting" ); // currency::inline_transfer( sv.voter, SystemAccount, sv.amount, "stake for voting" );
}; };
ACTION( SystemAccount, voteproducer ) { ACTION( SystemAccount, voteproducer ) {
......
...@@ -116,6 +116,7 @@ bool apply_context::is_account( const account_name& account )const { ...@@ -116,6 +116,7 @@ bool apply_context::is_account( const account_name& account )const {
void apply_context::require_authorization( const account_name& account )const { void apply_context::require_authorization( const account_name& account )const {
for( const auto& auth : act.authorization ) for( const auto& auth : act.authorization )
if( auth.actor == account ) return; if( auth.actor == account ) return;
wdump((act));
EOS_ASSERT( false, tx_missing_auth, "missing authority of ${account}", ("account",account)); EOS_ASSERT( false, tx_missing_auth, "missing authority of ${account}", ("account",account));
} }
void apply_context::require_authorization(const account_name& account, void apply_context::require_authorization(const account_name& account,
......
...@@ -36,6 +36,13 @@ namespace eosio { namespace chain { ...@@ -36,6 +36,13 @@ namespace eosio { namespace chain {
fc::datastream<char*> ds( abi.data(), abi.size() ); fc::datastream<char*> ds( abi.data(), abi.size() );
fc::raw::pack( ds, a ); fc::raw::pack( ds, a );
} }
eosio::chain::contracts::abi_def get_abi()const {
eosio::chain::contracts::abi_def a;
fc::datastream<const char*> ds( abi.data(), abi.size() );
fc::raw::unpack( ds, a );
return a;
}
}; };
using account_id_type = account_object::id_type; using account_id_type = account_object::id_type;
......
...@@ -29,7 +29,11 @@ namespace eosio { namespace testing { ...@@ -29,7 +29,11 @@ namespace eosio { namespace testing {
transaction_trace push_transaction( packed_transaction& trx ); transaction_trace push_transaction( packed_transaction& trx );
transaction_trace push_transaction( signed_transaction& trx ); transaction_trace push_transaction( signed_transaction& trx );
action_result push_action(action&& cert_act, uint64_t authorizer); action_result push_action(action&& cert_act, uint64_t authorizer);
transaction_trace push_action( const account_name& code, const action_name& act, const account_name& signer, const variant_object &data );
void set_tapos( signed_transaction& trx ) const; void set_tapos( signed_transaction& trx ) const;
void create_accounts( vector<account_name> names, bool multisig = false ) { void create_accounts( vector<account_name> names, bool multisig = false ) {
......
...@@ -366,4 +366,30 @@ namespace eosio { namespace testing { ...@@ -366,4 +366,30 @@ namespace eosio { namespace testing {
return s; return s;
} }
transaction_trace tester::push_action( const account_name& code,
const action_name& acttype,
const account_name& actor,
const variant_object& data
)
{ try {
chain::contracts::abi_serializer abis( control->get_database().get<account_object,by_name>(code).get_abi() );
string action_type_name = abis.get_action_type(acttype);
action act;
act.account = code;
act.name = acttype;
act.authorization = vector<permission_level>{{actor, config::active_name}};
act.data = abis.variant_to_binary(action_type_name, data);
wdump((act));
signed_transaction trx;
trx.actions.emplace_back(std::move(act));
set_tapos(trx);
trx.sign(get_private_key(actor, "active"), chain_id_type());
wdump((get_public_key( actor, "active" )));;
return push_transaction(trx);
} FC_CAPTURE_AND_RETHROW( (code)(acttype)(actor) ) }
} } /// eosio::test } } /// eosio::test
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册