forked from EOSIO/eos
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test for a deferred transaction via proxy account
exposed many bugs in the contract code and producer fixed what I found ref EOSIO#175
- Loading branch information
1 parent
befe187
commit b75983c
Showing
11 changed files
with
241 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
add_subdirectory(currency) | ||
add_subdirectory(exchange) | ||
add_subdirectory(infinite) | ||
add_subdirectory(proxy) | ||
add_subdirectory(test_api) | ||
add_subdirectory(simpledb) | ||
#add_subdirectory(social) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
file(GLOB SOURCE_FILES "*.cpp") | ||
add_wast_target(proxy "${SOURCE_FILES}" "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <proxy/proxy.hpp> | ||
#include <currency/currency.hpp> | ||
|
||
namespace proxy { | ||
using namespace eos; | ||
|
||
template<typename T> | ||
void apply_transfer(AccountName code, const T& transfer) { | ||
const auto self = currentCode(); | ||
Config config; | ||
assert(Configs::get(config, self), "Attempting to use unconfigured proxy"); | ||
if (transfer.from == self) { | ||
assert(transfer.to == config.owner, "proxy may only pay its owner" ); | ||
} else { | ||
assert(transfer.to == self, "proxy is not involved in this transfer"); | ||
T newTransfer = T(transfer); | ||
newTransfer.from = self; | ||
newTransfer.to = config.owner; | ||
|
||
auto outMsg = Message(code, N(transfer), newTransfer, self, N(code)); | ||
Transaction out; | ||
out.addMessage(outMsg); | ||
out.addScope(self); | ||
out.addScope(config.owner); | ||
out.send(); | ||
} | ||
} | ||
|
||
void apply_setowner(AccountName owner) { | ||
const auto self = currentCode(); | ||
Config config; | ||
bool configured = Configs::get(config, self); | ||
config.owner = owner; | ||
if (configured) { | ||
Configs::update(config, self); | ||
} else { | ||
Configs::store(config, self); | ||
} | ||
} | ||
|
||
} | ||
|
||
using namespace proxy; | ||
using namespace eos; | ||
|
||
extern "C" { | ||
void init() { | ||
} | ||
|
||
/// The apply method implements the dispatch of events to this contract | ||
void apply( uint64_t code, uint64_t action ) { | ||
if( code == N(currency) ) { | ||
if( action == N(transfer) ) { | ||
apply_transfer(code, currentMessage<currency::Transfer>()); | ||
} | ||
} else if ( code == N(eos) ) { | ||
if( action == N(transfer) ) { | ||
apply_transfer(code, currentMessage<eos::Transfer>()); | ||
} | ||
} else if (code == N(proxy) ) { | ||
if ( action == N(setowner)) { | ||
apply_setowner(currentMessage<AccountName>()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <eoslib/eos.hpp> | ||
#include <eoslib/db.hpp> | ||
|
||
namespace proxy { | ||
struct PACKED( Config ) { | ||
Config( AccountName o = AccountName() ):owner(o){} | ||
const uint64_t key = N(config); | ||
AccountName owner; | ||
}; | ||
|
||
using Configs = Table<N(proxy),N(proxy),N(configs),Config,uint64_t>; | ||
|
||
} /// namespace proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (c) 2017, Respective Authors. | ||
* | ||
* The MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <eos/chain/chain_controller.hpp> | ||
#include <eos/chain/exceptions.hpp> | ||
#include <eos/chain/account_object.hpp> | ||
#include <eos/chain/key_value_object.hpp> | ||
#include <eos/chain/block_summary_object.hpp> | ||
|
||
#include <eos/utilities/tempdir.hpp> | ||
|
||
#include <fc/crypto/digest.hpp> | ||
|
||
#include "../common/database_fixture.hpp" | ||
|
||
#include <Inline/BasicTypes.h> | ||
#include <IR/Module.h> | ||
#include <IR/Validate.h> | ||
#include <WAST/WAST.h> | ||
#include <WASM/WASM.h> | ||
#include <Runtime/Runtime.h> | ||
|
||
#include <proxy/proxy.wast.hpp> | ||
|
||
using namespace eos; | ||
using namespace chain; | ||
|
||
|
||
void Set_Proxy_Owner( testing_blockchain& chain, AccountName proxy, AccountName owner ) { | ||
eos::chain::SignedTransaction trx; | ||
trx.scope = sort_names({proxy,owner}); | ||
transaction_emplace_message(trx, "proxy", | ||
vector<types::AccountPermission>({ }), | ||
"setowner", owner); | ||
|
||
trx.expiration = chain.head_block_time() + 100; | ||
transaction_set_reference_block(trx, chain.head_block_id()); | ||
idump((trx)); | ||
chain.push_transaction(trx); | ||
} | ||
|
||
// declared in slow_test.cpp | ||
namespace slow_tests { | ||
void SetCode( testing_blockchain& chain, AccountName account, const char* wast ); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE(deferred_tests) | ||
|
||
BOOST_FIXTURE_TEST_CASE(opaque_proxy, testing_fixture) | ||
{ try { | ||
Make_Blockchain(chain); | ||
chain.produce_blocks(1); | ||
Make_Account(chain, newguy); | ||
Make_Account(chain, proxy); | ||
chain.produce_blocks(1); | ||
|
||
slow_tests::SetCode(chain, "proxy", proxy_wast); | ||
//chain.produce_blocks(1); | ||
|
||
Set_Proxy_Owner(chain, "proxy", "newguy"); | ||
chain.produce_blocks(7); | ||
|
||
Transfer_Asset(chain, inita, proxy, Asset(100)); | ||
chain.produce_blocks(1); | ||
BOOST_CHECK_EQUAL(chain.get_liquid_balance("newguy"), Asset(0)); | ||
BOOST_CHECK_EQUAL(chain.get_liquid_balance("inita"), Asset(100000-300)); | ||
BOOST_CHECK_EQUAL(chain.get_liquid_balance("proxy"), Asset(100)); | ||
|
||
|
||
chain.produce_blocks(1); | ||
BOOST_CHECK_EQUAL(chain.get_liquid_balance("newguy"), Asset(100)); | ||
BOOST_CHECK_EQUAL(chain.get_liquid_balance("inita"), Asset(100000-300)); | ||
BOOST_CHECK_EQUAL(chain.get_liquid_balance("proxy"), Asset(0)); | ||
|
||
BOOST_CHECK_EQUAL(chain.head_block_num(), 12); | ||
BOOST_CHECK(chain.fetch_block_by_number(12).valid()); | ||
BOOST_CHECK(!chain.fetch_block_by_number(12)->cycles.empty()); | ||
BOOST_CHECK(!chain.fetch_block_by_number(12)->cycles.front().empty()); | ||
BOOST_CHECK_EQUAL(chain.fetch_block_by_number(12)->cycles.front().front().generated_input.size(), 1); | ||
} FC_LOG_AND_RETHROW() } | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |