Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
tests work after refactor to support account name type refactor #56
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemaster committed Jun 30, 2017
1 parent 22b4227 commit 0cf1076
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
12 changes: 8 additions & 4 deletions libraries/chain/chain_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ try {
for (const auto& tm : trx.messages) { /// TODO: this loop can be processed in parallel
const Message* m = reinterpret_cast<const Message*>(&tm); // m(tm);
m->for_each_handler( [&]( const AccountName& a ) {

#warning TODO: call validate handlers on all notified accounts, currently it only calls the recipient's validate

message_validate_context mvc(_db,*m,a);
auto contract_handlers_itr = message_validate_handlers.find(a);
if (contract_handlers_itr != message_validate_handlers.end()) {
Expand Down Expand Up @@ -586,9 +589,9 @@ void chain_controller::validate_expiration(const SignedTransaction& trx) const
void chain_controller::validate_message_precondition( precondition_validate_context& context )const
{ try {
const auto& m = context.msg;
auto contract_handlers_itr = precondition_validate_handlers.find( m.recipient );
auto contract_handlers_itr = precondition_validate_handlers.find( context.scope );
if( contract_handlers_itr != precondition_validate_handlers.end() ) {
auto message_handler_itr = contract_handlers_itr->second.find( {context.scope, m.type} );
auto message_handler_itr = contract_handlers_itr->second.find( {m.recipient, m.type} );
if( message_handler_itr != contract_handlers_itr->second.end() ) {
message_handler_itr->second(context);
return;
Expand Down Expand Up @@ -621,14 +624,15 @@ void chain_controller::process_message(Message message) {
void chain_controller::apply_message( apply_context& context )
{ try {
const auto& m = context.msg;
auto contract_handlers_itr = apply_handlers.find( m.recipient );
auto contract_handlers_itr = apply_handlers.find( context.scope );
if( contract_handlers_itr != apply_handlers.end() ) {
auto message_handler_itr = contract_handlers_itr->second.find( {context.scope, m.type} );
auto message_handler_itr = contract_handlers_itr->second.find( {m.recipient, m.type} );
if( message_handler_itr != contract_handlers_itr->second.end() ) {
message_handler_itr->second(context);
return;
}
}
ilog( "no native handler found" );
const auto& recipient = _db.get<account_object,by_name>( context.scope );
if( recipient.code.size() ) {
wasm_interface::get().apply( context );
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eos/chain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const static char KeyPrefix[] = "EOS";

const static char SystemContractName[] = "system";
const static char EosContractName[] = "eos";
const static char StakedBalanceContractName[] = "stake";
const static char StakedBalanceContractName[] = "staked";

const static ShareType InitialTokenSupply = Asset::fromString("90000000.00000000 EOS").amount;

Expand Down
20 changes: 11 additions & 9 deletions libraries/native_contract/eos_contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ void precondition_eos_transfer(precondition_validate_context& context) {
}

void apply_eos_transfer(apply_context& context) {
auto& db = context.mutable_db;
auto transfer = context.msg.as<types::transfer>();
const auto& from = db.get<BalanceObject, byOwnerName>(transfer.from);
const auto& to = db.get<BalanceObject, byOwnerName>(transfer.to);
db.modify(from, [&](BalanceObject& a) {
a.balance -= transfer.amount.amount;
});
db.modify(to, [&](BalanceObject& a) {
a.balance += transfer.amount.amount;
});
try {
auto& db = context.mutable_db;
const auto& from = db.get<BalanceObject, byOwnerName>(transfer.from);
const auto& to = db.get<BalanceObject, byOwnerName>(transfer.to);
db.modify(from, [&](BalanceObject& a) {
a.balance -= transfer.amount.amount;
});
db.modify(to, [&](BalanceObject& a) {
a.balance += transfer.amount.amount;
});
} FC_CAPTURE_AND_RETHROW( (transfer) )
}
///@}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StakedBalanceObject : public chainbase::object<chain::staked_balance_objec

types::ShareType stakedBalance = 0;
types::ShareType unstakingBalance = 0;
types::Time lastUnstakingTime = types::Time::maximum();
types::Time lastUnstakingTime = types::Time::maximum();

/// The account's vote on producers. This may either be a list of approved producers, or an account to proxy vote to
fc::static_variant<ProducerSlate, types::AccountName> producerVotes = ProducerSlate{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ void native_contract_chain_initializer::register_types(chain_controller& chain,
SET_PRE_HANDLER( staked, staked, okproducer );
SET_APP_HANDLER( staked, staked, okproducer );

SET_VAL_HANDLER( staked, staked, setproducer );
SET_PRE_HANDLER( staked, staked, setproducer );
SET_APP_HANDLER( staked, staked, setproducer );

// SET_VAL_HANDLER( staked, staked, setproxy );
SET_PRE_HANDLER( staked, staked, setproxy );
SET_APP_HANDLER( staked, staked, setproxy );
Expand All @@ -93,7 +97,7 @@ std::vector<chain::Message> native_contract_chain_initializer::prepare_database(
db.create<native::staked::ProducerScheduleObject>([](const auto&){});

/// Create the native contract accounts manually; sadly, we can't run their contracts to make them create themselves
auto CreateNativeAccount = [this, &db](auto name, auto liquidBalance) {
auto CreateNativeAccount = [this, &db](Name name, auto liquidBalance) {
db.create<account_object>([this, &name](account_object& a) {
a.name = name;
a.creation_date = genesis.initial_timestamp;
Expand Down
1 change: 1 addition & 0 deletions libraries/native_contract/staked_balance_contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void apply_system_newaccount( apply_context& context ) {
auto create = context.msg.as<types::newaccount>();
context.mutable_db.create<StakedBalanceObject>([&create](StakedBalanceObject& sbo) {
sbo.ownerName = create.name;
sbo.stakedBalance = create.deposit.amount;
});
}

Expand Down
7 changes: 4 additions & 3 deletions tests/tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ BOOST_FIXTURE_TEST_CASE(tapos_wrap, testing_fixture)
{ try {
Make_Blockchain(chain)
Make_Account(chain, acct);
Transfer_Asset(chain, system, acct, Asset(5));
Stake_Asset(chain, acct, Asset(5).amount);
elog("Hang on, this will take a minute...");
chain.produce_blocks(65536);
Expand Down Expand Up @@ -320,7 +321,7 @@ R"(
(export "String_unpack" (func $String_unpack))
(export "Transfer_unpack" (func $Transfer_unpack))
(export "onInit" (func $onInit))
(export "onApply_Transfer_simplecoin" (func $onApply_Transfer_simplecoin))
(export "onApply_transfer_simplecoin" (func $onApply_Transfer_simplecoin))
(func $malloc (param $0 i32) (result i32)
(local $1 i32)
(i32.store offset=8208
Expand Down Expand Up @@ -908,7 +909,7 @@ R"(
for (uint32_t i = 0; i < 1000; ++i)
{
eos::chain::SignedTransaction trx;
trx.emplaceMessage("simplecoin", "simplecoin", vector<AccountName>{"init1"}, "Transfer",
trx.emplaceMessage("simplecoin", "simplecoin", vector<AccountName>{"init1"}, "transfer",
types::transfer{"simplecoin", "init1", 1+i, "hello"} );
trx.expiration = chain.head_block_time() + 100;
trx.set_reference_block(chain.head_block_id());
Expand All @@ -920,7 +921,7 @@ R"(
{
wlog( "transfer 102 from init1 to init2" );
eos::chain::SignedTransaction trx;
trx.emplaceMessage("init1", "simplecoin", vector<AccountName>{"init2"}, "Transfer",
trx.emplaceMessage("init1", "simplecoin", vector<AccountName>{"init2"}, "transfer",
types::transfer{"init1", "init2", 102, "hello again"});
trx.expiration = chain.head_block_time() + 100;
trx.set_reference_block(chain.head_block_id());
Expand Down

0 comments on commit 0cf1076

Please sign in to comment.