未验证 提交 48a6a6be 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge branch 'master' into issue3140

......@@ -92,10 +92,16 @@
"base": "",
"fields": [
{"name": "proposal_name", "type": "name"},
{"name": "requested_approvals", "type": "permission_level[]"},
{"name": "provided_approvals", "type": "permission_level[]"},
{"name": "packed_transaction", "type": "bytes"}
]
},{
"name": "approvals_info",
"base": "",
"fields": [
{"name": "proposal_name", "type": "name"},
{"name": "requested_approvals", "type": "permission_level[]"},
{"name": "provided_approvals", "type": "permission_level[]"}
]
}
],
"actions": [{
......@@ -127,6 +133,12 @@
"index_type": "i64",
"key_names" : ["proposal_name"],
"key_types" : ["name"]
},{
"name": "approvals",
"type": "approvals_info",
"index_type": "i64",
"key_names" : ["proposal_name"],
"key_types" : ["name"]
}
],
"ricardian_clauses": []
......
......@@ -50,38 +50,41 @@ void multisig::propose() {
proptable.emplace( proposer, [&]( auto& prop ) {
prop.proposal_name = proposal_name;
prop.packed_transaction = bytes( buffer+trx_pos, buffer+size );
prop.requested_approvals = std::move(requested);
});
approvals apptable( _self, proposer );
apptable.emplace( proposer, [&]( auto& a ) {
a.proposal_name = proposal_name;
a.requested_approvals = std::move(requested);
});
}
void multisig::approve( account_name proposer, name proposal_name, permission_level level ) {
require_auth( level );
proposals proptable( _self, proposer );
auto prop_it = proptable.find( proposal_name );
eosio_assert( prop_it != proptable.end(), "proposal not found" );
approvals apptable( _self, proposer );
auto& apps = apptable.get( proposal_name, "proposal not found" );
auto itr = std::find( prop_it->requested_approvals.begin(), prop_it->requested_approvals.end(), level );
eosio_assert( itr != prop_it->requested_approvals.end(), "approval is not on the list of requested approvals" );
auto itr = std::find( apps.requested_approvals.begin(), apps.requested_approvals.end(), level );
eosio_assert( itr != apps.requested_approvals.end(), "approval is not on the list of requested approvals" );
proptable.modify( prop_it, proposer, [&]( auto& mprop ) {
mprop.provided_approvals.push_back( level );
mprop.requested_approvals.erase( itr );
apptable.modify( apps, proposer, [&]( auto& a ) {
a.provided_approvals.push_back( level );
a.requested_approvals.erase( itr );
});
}
void multisig::unapprove( account_name proposer, name proposal_name, permission_level level ) {
require_auth( level );
proposals proptable( _self, proposer );
auto prop_it = proptable.find( proposal_name );
eosio_assert( prop_it != proptable.end(), "proposal not found" );
auto itr = std::find( prop_it->provided_approvals.begin(), prop_it->provided_approvals.end(), level );
eosio_assert( itr != prop_it->provided_approvals.end(), "no approval previously granted" );
proptable.modify( prop_it, proposer, [&]( auto& mprop ) {
mprop.requested_approvals.push_back(level);
mprop.provided_approvals.erase(itr);
approvals apptable( _self, proposer );
auto& apps = apptable.get( proposal_name, "proposal not found" );
auto itr = std::find( apps.provided_approvals.begin(), apps.provided_approvals.end(), level );
eosio_assert( itr != apps.provided_approvals.end(), "no approval previously granted" );
apptable.modify( apps, proposer, [&]( auto& a ) {
a.requested_approvals.push_back(level);
a.provided_approvals.erase(itr);
});
}
......@@ -89,38 +92,44 @@ void multisig::cancel( account_name proposer, name proposal_name, account_name c
require_auth( canceler );
proposals proptable( _self, proposer );
auto prop_it = proptable.find( proposal_name );
eosio_assert( prop_it != proptable.end(), "proposal not found" );
auto& prop = proptable.get( proposal_name, "proposal not found" );
if( canceler != proposer ) {
eosio_assert( unpack<transaction_header>( prop_it->packed_transaction ).expiration < eosio::time_point_sec(now()), "cannot cancel until expiration" );
eosio_assert( unpack<transaction_header>( prop.packed_transaction ).expiration < eosio::time_point_sec(now()), "cannot cancel until expiration" );
}
proptable.erase(prop_it);
approvals apptable( _self, proposer );
auto& apps = apptable.get( proposal_name, "proposal not found" );
proptable.erase(prop);
apptable.erase(apps);
}
void multisig::exec( account_name proposer, name proposal_name, account_name executer ) {
require_auth( executer );
proposals proptable( _self, proposer );
auto prop_it = proptable.find( proposal_name );
eosio_assert( prop_it != proptable.end(), "proposal not found" );
auto& prop = proptable.get( proposal_name, "proposal not found" );
approvals apptable( _self, proposer );
auto& apps = apptable.get( proposal_name, "proposal not found" );
transaction_header trx_header;
datastream<const char*> ds( prop_it->packed_transaction.data(), prop_it->packed_transaction.size() );
datastream<const char*> ds( prop.packed_transaction.data(), prop.packed_transaction.size() );
ds >> trx_header;
eosio_assert( trx_header.expiration >= eosio::time_point_sec(now()), "transaction expired" );
bytes packed_provided_approvals = pack(prop_it->provided_approvals);
auto res = ::check_transaction_authorization( prop_it->packed_transaction.data(), prop_it->packed_transaction.size(),
bytes packed_provided_approvals = pack(apps.provided_approvals);
auto res = ::check_transaction_authorization( prop.packed_transaction.data(), prop.packed_transaction.size(),
(const char*)0, 0,
packed_provided_approvals.data(), packed_provided_approvals.size()
);
eosio_assert( res > 0, "transaction authorization failed" );
send_deferred( (uint128_t(proposer) << 64) | proposal_name, executer, prop_it->packed_transaction.data(), prop_it->packed_transaction.size() );
send_deferred( (uint128_t(proposer) << 64) | proposal_name, executer, prop.packed_transaction.data(), prop.packed_transaction.size() );
proptable.erase(prop_it);
proptable.erase(prop);
apptable.erase(apps);
}
} /// namespace eosio
......
......@@ -17,13 +17,20 @@ namespace eosio {
private:
struct proposal {
name proposal_name;
vector<permission_level> requested_approvals;
vector<permission_level> provided_approvals;
vector<char> packed_transaction;
auto primary_key()const { return proposal_name.value; }
};
typedef eosio::multi_index<N(proposal),proposal> proposals;
struct approvals_info {
name proposal_name;
vector<permission_level> requested_approvals;
vector<permission_level> provided_approvals;
auto primary_key()const { return proposal_name.value; }
};
typedef eosio::multi_index<N(approvals),approvals_info> approvals;
};
} /// namespace eosio
......@@ -98,10 +98,9 @@ namespace eosiosystem {
const authority& owner,
const authority& active*/ ) {
auto name_str = eosio::name{newact}.to_string();
eosio::print( eosio::name{creator}, " created ", eosio::name{newact}, "\n");
eosio_assert( name_str.size() == 12, "account names must be 12 chars long" );
eosio_assert( name_str.find_first_of('.') == std::string::npos, "account names cannot contain '.' character");
eosio_assert( name_str.size() == 12 || creator == N(eosio), "account names must be 12 chars long" );
eosio_assert( name_str.find_first_of('.') == std::string::npos || creator == N(eosio), "account names cannot contain '.' character");
user_resources_table userres( _self, newact);
......@@ -123,7 +122,6 @@ namespace eosiosystem {
auto itr = _rammarket.find(S(4,RAMEOS));
auto tmp = *itr;
auto eosout = tmp.convert( asset(bytes,S(0,RAM)), S(4,EOS) );
print( "eosout: ", eosout, " ", tmp.base.balance, " ", tmp.quote.balance, "\n" );
buyram( payer, receiver, eosout );
}
......@@ -139,7 +137,6 @@ namespace eosiosystem {
*/
void system_contract::buyram( account_name payer, account_name receiver, asset quant )
{
// print( "\n payer: ", eosio::name{payer}, " buys ram for ", eosio::name{receiver}, " with ", quant, "\n" );
require_auth( payer );
eosio_assert( quant.amount > 0, "must purchase a positive amount" );
......@@ -148,7 +145,6 @@ namespace eosiosystem {
{ payer, N(eosio), quant, std::string("buy ram") } );
}
// print( "free ram: ", _gstate.free_ram(), "\n");
int64_t bytes_out;
......@@ -157,7 +153,6 @@ namespace eosiosystem {
bytes_out = es.convert( quant, S(0,RAM) ).amount;
});
// print( "ram bytes out: ", bytes_out, "\n" );
eosio_assert( bytes_out > 0, "must reserve a positive amount" );
......@@ -199,7 +194,6 @@ namespace eosiosystem {
_rammarket.modify( itr, 0, [&]( auto& es ) {
/// the cast to int64_t of bytes is safe because we certify bytes is <= quota which is limited by prior purchases
tokens_out = es.convert( asset(bytes,S(0,RAM)), S(4,EOS) );
// print( "out: ", tokens_out, "\n" );
});
_gstate.total_ram_bytes_reserved -= bytes;
......@@ -225,7 +219,6 @@ namespace eosiosystem {
{
require_auth( from );
// print( "from: ", eosio::name{from}, " to: ", eosio::name{receiver}, " net: ", stake_net_quantity, " cpu: ", stake_cpu_quantity );
eosio_assert( stake_cpu_quantity >= asset(0), "must stake a positive amount" );
eosio_assert( stake_net_quantity >= asset(0), "must stake a positive amount" );
......
......@@ -201,7 +201,14 @@
"fields": [
{"name":"owner", "type":"account_name"}
]
}
},{
"name": "setpriv",
"base": "",
"fields": [
{"name":"account", "type":"account_name"},
{"name":"is_priv", "type":"int8"}
]
}
],
"actions": [
{
......@@ -252,6 +259,10 @@
"name": "claimrewards",
"type": "claimrewards",
"ricardian_contract": ""
},{
"name": "setpriv",
"type": "setpriv",
"ricardian_contract": ""
}
],
"tables": [{
......
......@@ -72,6 +72,11 @@ namespace eosiosystem {
_global.set( _gstate, _self );
}
void system_contract::setpriv( account_name account, uint8_t ispriv ) {
require_auth( _self );
set_privileged( account, ispriv );
}
} /// eosio.system
......@@ -85,7 +90,8 @@ EOSIO_ABI( eosiosystem::system_contract,
(regproxy)(regproducer)(unregprod)(voteproducer)
(claimrewards)
// native.hpp
//XXX
(onblock)
(newaccount)(updateauth)(deleteauth)(linkauth)(unlinkauth)(postrecovery)(passrecovery)(vetorecovery)(onerror)(canceldelay)
//this file
(setpriv)
)
......@@ -198,6 +198,8 @@ namespace eosiosystem {
// functions defined in producer_pay.cpp
void claimrewards( const account_name& owner );
void setpriv( account_name account, uint8_t ispriv );
private:
void update_elected_producers( block_timestamp timestamp );
......
......@@ -14,10 +14,7 @@
"base": "",
"fields": [
{"name":"issuer", "type":"account_name"},
{"name":"maximum_supply", "type":"asset"},
{"name":"can_freeze", "type":"uint8"},
{"name":"can_recall", "type":"uint8"},
{"name":"can_whitelist", "type":"uint8"}
{"name":"maximum_supply", "type":"asset"}
]
},{
"name": "issue",
......@@ -31,9 +28,7 @@
"name": "account",
"base": "",
"fields": [
{"name":"balance", "type":"asset"},
{"name":"frozen", "type":"uint8"},
{"name":"whitelist", "type":"uint8"}
{"name":"balance", "type":"asset"}
]
},{
"name": "currency_stats",
......@@ -41,12 +36,7 @@
"fields": [
{"name":"supply", "type":"asset"},
{"name":"max_supply", "type":"asset"},
{"name":"issuer", "type":"account_name"},
{"name":"can_freeze", "type":"uint8"},
{"name":"can_recall", "type":"uint8"},
{"name":"can_whitelist", "type":"uint8"},
{"name":"is_frozen", "type":"uint8"},
{"name":"enforce_whitelist", "type":"uint8"}
{"name":"issuer", "type":"account_name"}
]
}
],
......
......@@ -8,10 +8,7 @@
namespace eosio {
void token::create( account_name issuer,
asset maximum_supply,
uint8_t issuer_can_freeze,
uint8_t issuer_can_recall,
uint8_t issuer_can_whitelist )
asset maximum_supply )
{
require_auth( _self );
......@@ -28,9 +25,6 @@ void token::create( account_name issuer,
s.supply.symbol = maximum_supply.symbol;
s.max_supply = maximum_supply;
s.issuer = issuer;
s.can_freeze = issuer_can_freeze;
s.can_recall = issuer_can_recall;
s.can_whitelist = issuer_can_whitelist;
});
}
......@@ -94,15 +88,6 @@ void token::sub_balance( account_name owner, asset value, const currency_stats&
const auto& from = from_acnts.get( value.symbol.name() );
eosio_assert( from.balance.amount >= value.amount, "overdrawn balance" );
if( has_auth( owner ) ) {
eosio_assert( !st.can_freeze || !from.frozen, "account is frozen by issuer" );
eosio_assert( !st.can_freeze || !st.is_frozen, "all transfers are frozen by issuer" );
eosio_assert( !st.enforce_whitelist || from.whitelist, "account is not white listed" );
} else if( has_auth( st.issuer ) ) {
eosio_assert( st.can_recall, "issuer may not recall token" );
} else {
eosio_assert( false, "insufficient authority" );
}
if( from.balance.amount == value.amount ) {
from_acnts.erase( from );
......@@ -118,12 +103,10 @@ void token::add_balance( account_name owner, asset value, const currency_stats&
accounts to_acnts( _self, owner );
auto to = to_acnts.find( value.symbol.name() );
if( to == to_acnts.end() ) {
eosio_assert( !st.enforce_whitelist, "can only transfer to white listed accounts" );
to_acnts.emplace( ram_payer, [&]( auto& a ){
a.balance = value;
});
} else {
eosio_assert( !st.enforce_whitelist || to->whitelist, "receiver requires whitelist by issuer" );
to_acnts.modify( to, 0, [&]( auto& a ) {
a.balance += value;
});
......
......@@ -22,11 +22,7 @@ namespace eosio {
token( account_name self ):contract(self){}
void create( account_name issuer,
asset maximum_supply,
uint8_t issuer_can_freeze,
uint8_t issuer_can_recall,
uint8_t issuer_can_whitelist );
asset maximum_supply);
void issue( account_name to, asset quantity, string memo );
......@@ -46,8 +42,6 @@ namespace eosio {
private:
struct account {
asset balance;
bool frozen = false;
bool whitelist = true;
uint64_t primary_key()const { return balance.symbol.name(); }
};
......@@ -56,11 +50,6 @@ namespace eosio {
asset supply;
asset max_supply;
account_name issuer;
bool can_freeze = true;
bool can_recall = true;
bool can_whitelist = true;
bool is_frozen = false;
bool enforce_whitelist = false;
uint64_t primary_key()const { return supply.symbol.name(); }
};
......
# The Block Producer Agreement
As a Block Producer (BP), I/we promise to:
1. Produce exactly the authorized number of blocks faithfully, accurately, at the appointed time in the rotation
2. Never produce and sign two or more blocks with the same block height or block interval
3. Never censor governance related transactions such as votes or Arbitration related transactions
4. Only add "good" transactions from the transaction pool to the block
5. Make a good faith effort to include as many "good" transactions as possible to the block without undue discrimination
6. Exclude "bad" transactions from the block, and publish why they were excluded
7. Show no favoritism among transactions, ordering them in a FIFO fashion or using some other ordering mechanism that is declared publicly in advance, including the default ordering provided by the unmodified software
8. Refrain from using my/our superior information to "front run" transactions nor enabling anyone else to “front run”
9. Accept as valid any Arbitrator’s order that’s
1. signed by an Arbitrator
2. that the chain shows was assigned to a Case,
3. such that the order affects only the Accounts named in that Case, and
4. the Arbitrator is in good standing with their Arbitration Forum, and
5. the original Transaction that gave rise to the Case names that Arbitration Forum as the venue for dispute resolution
10. Only freeze accounts when authorized to do so by a valid Arbitrator’s order
11. Always file a dispute against myself/ourselves after taking initiative to act on an emergency
12. Provide at least four (4) public endpoints running full nodes (the Minimum Configuration)
13. Not requesting my/our daily Vote Bonus pay on days when I/we don’t have the Minimum Configuration running, and repaying any Vote Bonus income collected while the Minimum Configuration wasn’t running
14. Disclosing all ownership of my/our organization greater than 10%
15. Not sharing more than 10% ownership with another BP
# Article I
No user of this blockchain shall make knowingly false or misleading statements, nor statements that constitute discrimination or harassment, nor profit thereby.
# Article II
The rights of contract and of private property shall be inviolable, therefore no property shall change hands except with the consent of the owner or by a lawful Arbitrator’s order.
# Article III
Each Member agrees to resolve disputes through the blockchain’s default arbitration process, or any other process that the parties to a transaction may mutually agree to in advance.
# Article IV
No Member shall offer nor accept anything of value in exchange for a vote of any type, including for Block Producer candidates, Amendments or Worker Proposals, nor shall any Member unduly influence the vote of another.
# Article V
This EOS Blockchain has no owner, manager or fiduciary. It is governed exclusively under the terms of this Constitution.
# Article VI
No Member nor any Beneficial Interest shall own more than 10% of issued tokens.
# Article VII
Each Member agrees that penalties for violations may include, but are not limited to, fines, account freezing, and reversal of transactions.
# Article VIII
No Member shall serve as a Block Producer who has not agreed in advance to the Block Producer Agreement provided by the Members of this blockchain.
# Article IX
No Arbitrator shall serve except within an Arbitration Forum.
# Article X
No Member shall serve as an Arbitrator who has not
* Agreed in advance to the Arbitrator Agreement provided by the Members,
* Been nominated by at least two other Members, and
* Completed the course of study of, been certified by, and be in good standing with their Forum.
# Article XI
Each Member who makes available a smart contract on this blockchain shall be a Developer. Each Developer shall offer their smart contracts via a license, and each smart contract shall be documented with a Ricardian Contract stating the intent of all parties and naming the Arbitration Forum that will resolve disputes arising from that contract.
# Article XII
Multi-lingual contracts must specify the prevailing language in case of dispute.
# Article XIII
As Developers are able to offer services and provide interaction with the blockchain to non Members via their applications, the Developer assumes all responsibility for guaranteeing that non-Member interaction conforms to this Constitution.
# Article XIV
This Constitution creates no positive rights for or between any Members.
# Article XV
All disputes arising from this Constitution or its related governing documents shall be resolved using the EOS Core Arbitration Forum.
# Article XVI
This Constitution and its subordinate documents the Block Producer Agreement and Arbitrator Agreement shall not be amended except by a vote of the Token Holders with no less than 15% vote participation among eligible tokens and no fewer than 10% more Yes than No vote power, sustained for 30 continuous days within a 120 day period.
# Article XVII
Choice of law for disputes shall be, in order of precedence, this Constitution, the Maxims of Equity, and the laws of Malta.
......@@ -2437,6 +2437,7 @@ namespace eosio {
try {
chain_plug->accept_transaction( msg);
fc_dlog(logger, "chain accepted transaction" );
dispatcher->bcast_transaction(msg);
return;
}
catch( const fc::exception &ex) {
......
......@@ -153,7 +153,7 @@ struct txn_test_gen_plugin_impl {
act.account = N(eosio.token);
act.name = N(create);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"eosio.token\",\"maximum_supply\":\"1000000000.0000 CUR\", \"can_freeze\":0, \"can_recall\":0, \"can_whitelist\":0}}"));
act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"eosio.token\",\"maximum_supply\":\"1000000000.0000 CUR\"}}"));
trx.actions.push_back(act);
}
{
......
......@@ -122,7 +122,7 @@
printf "\\tInstalling LCOV.\\n"
if ! cd "${TEMP_DIR}"
then
printf "\\n\\tUnable to enter %s. Exiting now.\\n" "${TEMP_DIR}";
printf "\\n\\tUnable to enter %s. Exiting now.\\n" "${TEMP_DIR}"
exit 1;
fi
if ! git clone "https://github.com/linux-test-project/lcov.git"
......@@ -133,7 +133,7 @@
fi
if ! cd "${TEMP_DIR}/lcov"
then
printf "\\n\\tUnable to enter %s/lcov. Exiting now.\\n" "${TEMP_DIR}";
printf "\\n\\tUnable to enter %s/lcov. Exiting now.\\n" "${TEMP_DIR}"
exit 1;
fi
if ! sudo make install
......
此差异已折叠。
......@@ -410,9 +410,9 @@ mongodconf
printf "\\tExiting now.\\n\\n"
exit 1;
fi
printf "\\n\\tsecp256k1 successfully installed @ /usr/local/lib/libsecp256k1.a.\\n\\n"
printf "\\n\\tsecp256k1 successfully installed @ /usr/local/lib.\\n\\n"
else
printf "\\tsecp256k1 found @ /usr/local/lib/libsecp256k1.a.\\n"
printf "\\tsecp256k1 found @ /usr/local/lib.\\n"
fi
printf "\\n\\tChecking for LLVM with WASM support.\\n"
......
......@@ -320,7 +320,7 @@ try:
assert(actions)
try:
assert(actions["actions"][0]["action_trace"]["act"]["name"] == "transfer")
except (AssertionError, TypeError, KeyError) as e:
except (AssertionError, TypeError, KeyError) as _:
Print("Last action validation failed. Actions: %s" % (actions))
raise
......@@ -485,7 +485,7 @@ try:
expected="100000.0000 CUR"
actual=amountStr
if actual != expected:
errorExit("FAILURE - get currency1111 balance failed. Recieved response: <%s>" % (res), raw=True)
errorExit("FAILURE - currency1111 balance check failed. Expected: %s, Recieved %s" % (expected, actual), raw=True)
# TBD: "get currency1111 stats is still not working. Enable when ready.
# Print("Verify currency1111 contract has proper total supply of CUR (via get currency1111 stats)")
......@@ -529,6 +529,47 @@ try:
if actual != expected:
errorExit("FAILURE - Wrong currency1111 balance (expected=%s, actual=%s)" % (str(expected), str(actual)), raw=True)
Print("Test for block decoded packed transaction (issue 2932)")
blockId=node.getBlockIdByTransId(transId)
assert(blockId)
block=node.getBlock(blockId)
assert(block)
transactions=None
try:
transactions=block["transactions"]
assert(transactions)
except (AssertionError, TypeError, KeyError) as _:
Print("FAILURE - Failed to parse block. %s" % (block))
raise
myTrans=None
for trans in transactions:
assert(trans)
try:
myTransId=trans["trx"]["id"]
if transId == myTransId:
myTrans=trans["trx"]["transaction"]
assert(myTrans)
break
except (AssertionError, TypeError, KeyError) as _:
Print("FAILURE - Failed to parse block transactions. %s" % (trans))
raise
assert(myTrans)
try:
assert(myTrans["actions"][0]["name"] == "transfer")
assert(myTrans["actions"][0]["account"] == "currency1111")
assert(myTrans["actions"][0]["authorization"][0]["actor"] == "currency1111")
assert(myTrans["actions"][0]["authorization"][0]["permission"] == "active")
assert(myTrans["actions"][0]["data"]["from"] == "currency1111")
assert(myTrans["actions"][0]["data"]["to"] == "defproducera")
assert(myTrans["actions"][0]["data"]["quantity"] == "0.0050 CUR")
assert(myTrans["actions"][0]["data"]["memo"] == "test")
except (AssertionError, TypeError, KeyError) as _:
Print("FAILURE - Failed to parse block transaction. %s" % (myTrans))
raise
Print("Exchange Contract Tests")
Print("upload exchange contract")
......@@ -596,7 +637,7 @@ try:
Print("CurrentBlockNum: %d" % (currentBlockNum))
Print("Request blocks 1-%d" % (currentBlockNum))
for blockNum in range(1, currentBlockNum+1):
block=node.getBlock(blockNum, retry=False, silentErrors=True)
block=node.getBlock(str(blockNum), retry=False, silentErrors=True)
if block is None:
# TBD: Known issue (Issue 2099) that the block containing setprods isn't retrievable.
# Enable errorExit() once that is resolved.
......@@ -620,7 +661,7 @@ try:
Print("Request invalid block numbered %d. This will generate an expected error message." % (currentBlockNum+1000))
block=node.getBlock(currentBlockNum+1000, silentErrors=True, retry=False)
block=node.getBlock(str(currentBlockNum+1000), silentErrors=True, retry=False)
if block is not None:
errorExit("ERROR: Received block where not expected")
else:
......
......@@ -296,6 +296,8 @@ class Node(object):
# pylint: disable=too-many-branches
def getBlock(self, blockNum, retry=True, silentErrors=False):
"""Given a blockId will return block details."""
assert(isinstance(blockNum, str))
if not self.enableMongo:
cmd="%s %s get block %s" % (Utils.EosClientPath, self.endpointArgs, blockNum)
if Utils.Debug: Utils.Print("cmd: %s" % (cmd))
......@@ -361,7 +363,7 @@ class Node(object):
try:
last_irreversible_block_num=int(info["last_irreversible_block_num"])
except (TypeError, KeyError) as _:
Utils.Print("Failure in get info parsing. %s" % (trans))
Utils.Print("Failure in get info parsing. %s" % (info))
raise
return True if blockNum <= last_irreversible_block_num else True
......@@ -403,6 +405,68 @@ class Node(object):
return None
def isTransInBlock(self, transId, blockId):
"""Check if transId is within block identified by blockId"""
assert(transId)
assert(isinstance(transId, str))
assert(blockId)
assert(isinstance(blockId, str))
block=self.getBlock(blockId)
transactions=None
try:
transactions=block["transactions"]
except (AssertionError, TypeError, KeyError) as _:
Utils.Print("Failed to parse block. %s" % (block))
raise
if transactions is not None:
for trans in transactions:
assert(trans)
try:
myTransId=trans["trx"]["id"]
if transId == myTransId:
return True
except (TypeError, KeyError) as _:
Utils.Print("Failed to parse block transactions. %s" % (trans))
return False
def getBlockIdByTransId(self, transId):
"""Given a transaction Id (string), will return block id (string) containing the transaction"""
assert(transId)
assert(isinstance(transId, str))
trans=self.getTransaction(transId)
assert(trans)
refBlockNum=None
try:
refBlockNum=trans["trx"]["trx"]["ref_block_num"]
refBlockNum=int(refBlockNum)+1
except (TypeError, ValueError, KeyError) as _:
Utils.Print("transaction parsing failed. Transaction: %s" % (trans))
raise
headBlockNum=self.getIrreversibleBlockNum()
assert(headBlockNum)
try:
headBlockNum=int(headBlockNum)
except(ValueError) as _:
Utils.Print("Info parsing failed. %s" % (headBlockNum))
for blockNum in range(refBlockNum, headBlockNum+1):
if self.isTransInBlock(str(transId), str(blockNum)):
return str(blockNum)
return None
def doesNodeHaveTransId(self, transId):
"""Check if transaction (transId) has been finalized."""
assert(transId)
assert(isinstance(transId, str))
blockId=self.getBlockIdByTransId(transId)
return True if blockId else None
def getTransByBlockId(self, blockId, retry=True, silentErrors=False):
for _ in range(2):
cmd="%s %s" % (Utils.MongoPath, self.mongoEndpointArgs)
......@@ -471,26 +535,6 @@ class Node(object):
return None
def doesNodeHaveTransId(self, transId, silentErrors=True):
trans=self.getTransaction(transId, silentErrors)
if trans is None:
return False
blockNum=None
try:
if not self.enableMongo:
blockNum=int(trans["trx"]["trx"]["ref_block_num"])
else:
blockNum=int(trans["ref_block_num"])
except (TypeError, KeyError) as _:
if not silentErrors:
Utils.Print("Failure in transaction parsing. %s" % (trans))
return False
blockNum += 1
if Utils.Debug: Utils.Print("Check if block %d is irreversible." % (blockNum))
return self.doesNodeHaveBlockNum(blockNum)
# Create & initialize account and return creation transactions. Return transaction json object
def createInitializeAccount(self, account, creatorAccount, stakedDeposit=1000, waitForTransBlock=False):
cmd='%s %s system newaccount -j %s %s %s %s --stake-net "100 EOS" --stake-cpu "100 EOS" --buy-ram-EOS "100 EOS"' % (
......@@ -588,7 +632,7 @@ class Node(object):
assert(trans)
try:
return trans["rows"][0]["balance"]
except (TypeError, KeyError) as e:
except (TypeError, KeyError) as _:
print("Transaction parsing failed. Transaction: %s" % (trans))
raise
......@@ -719,9 +763,9 @@ class Node(object):
# Gets accounts mapped to key. Returns array
def getAccountsArrByKey(self, key):
trans=self.getAccountsByKey(key)
assert(trans)
assert("account_names" in trans)
trans=self.getAccountsByKey(key)
accounts=trans["account_names"]
return accounts
......@@ -931,6 +975,7 @@ class Node(object):
return False if info is None else True
def getHeadBlockNum(self):
"""returns head block number(string) as returned by cleos get info."""
if not self.enableMongo:
info=self.getInfo()
if info is not None:
......@@ -1355,7 +1400,7 @@ class Cluster(object):
def initializeNodes(self, defproduceraPrvtKey=None, defproducerbPrvtKey=None, onlyBios=False):
port=Cluster.__BiosPort if onlyBios else self.port
host=Cluster.__BiosHost if onlyBios else self.host
node=Node(self.host, self.port, enableMongo=self.enableMongo, mongoHost=self.mongoHost, mongoPort=self.mongoPort, mongoDb=self.mongoDb)
node=Node(host, port, enableMongo=self.enableMongo, mongoHost=self.mongoHost, mongoPort=self.mongoPort, mongoDb=self.mongoDb)
node.setWalletEndpointArgs(self.walletEndpointArgs)
if Utils.Debug: Utils.Print("Node:", node)
......@@ -1839,6 +1884,7 @@ class Cluster(object):
if Utils.Debug: Utils.Print("setprods: %s" % (setProdsStr))
Utils.Print("Setting producers: %s." % (", ".join(prodNames)))
opts="--permission eosio@active"
# pylint: disable=redefined-variable-type
trans=biosNode.pushMessage("eosio", "setprods", setProdsStr, opts)
if trans is None or not trans[0]:
Utils.Print("ERROR: Failed to set producer %s." % (keys["name"]))
......@@ -1961,6 +2007,7 @@ class Cluster(object):
nodes=[]
pgrepOpts="-fl"
# pylint: disable=deprecated-method
if platform.linux_distribution()[0] in ["Ubuntu", "LinuxMint", "Fedora","CentOS Linux","arch"]:
pgrepOpts="-a"
......
......@@ -96,10 +96,7 @@ public:
void create_currency( name contract, name manager, asset maxsupply, const private_key_type* signer = nullptr ) {
auto act = mutable_variant_object()
("issuer", manager )
("maximum_supply", maxsupply )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0);
("maximum_supply", maxsupply );
base_tester::push_action(contract, N(create), contract, act );
}
......
......@@ -122,9 +122,6 @@ BOOST_AUTO_TEST_CASE( link_delay_direct_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR")
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
......@@ -281,9 +278,6 @@ BOOST_AUTO_TEST_CASE(delete_auth_test) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", "eosio.token" )
("maximum_supply", "9000000.0000 CUR" )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
// issue to account "eosio.token"
......@@ -404,9 +398,6 @@ BOOST_AUTO_TEST_CASE( link_delay_direct_parent_permission_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR")
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -551,9 +542,6 @@ BOOST_AUTO_TEST_CASE( link_delay_direct_walk_parent_permissions_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR")
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -692,9 +680,6 @@ BOOST_AUTO_TEST_CASE( link_delay_permission_change_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token )
("maximum_supply", "9000000.0000 CUR" )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -892,9 +877,6 @@ BOOST_AUTO_TEST_CASE( link_delay_permission_change_with_delay_heirarchy_test ) {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR" )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -1092,9 +1074,6 @@ BOOST_AUTO_TEST_CASE( link_delay_link_change_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR" )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -1291,9 +1270,6 @@ BOOST_AUTO_TEST_CASE( link_delay_unlink_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token )
("maximum_supply", "9000000.0000 CUR" )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -1495,9 +1471,6 @@ BOOST_AUTO_TEST_CASE( link_delay_link_change_heirarchy_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR" )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -1664,9 +1637,6 @@ BOOST_AUTO_TEST_CASE( mindelay_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR")
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -1811,9 +1781,6 @@ BOOST_AUTO_TEST_CASE( canceldelay_test ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR")
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -2057,9 +2024,6 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", eosio_token)
("maximum_supply", "9000000.0000 CUR")
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
......@@ -2326,9 +2290,6 @@ BOOST_AUTO_TEST_CASE( max_transaction_delay_execute ) { try {
chain.push_action(N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", "eosio.token" )
("maximum_supply", "9000000.0000 CUR" )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
chain.push_action(N(eosio.token), name("issue"), N(eosio.token), fc::mutable_variant_object()
("to", "tester")
......
......@@ -238,9 +238,6 @@ BOOST_FIXTURE_TEST_CASE( dice_test, dice_tester ) try {
push_action(N(eosio.token), N(create), N(eosio.token), mvo()
("issuer", "eosio.token")
("maximum_supply", "1000000000.0000 EOS")
("can_freeze", "0")
("can_recall", "0")
("can_whitelist", "0")
);
push_action(N(eosio.token), N(issue), N(eosio.token), mvo()
......
......@@ -4,6 +4,7 @@
#include <eosio/chain/contract_table_objects.hpp>
#include <eosio/chain/global_property_object.hpp>
#include <eosio/chain/resource_limits.hpp>
#include <eosio/chain/wast_to_wasm.hpp>
#include <eosio.system/eosio.system.wast.hpp>
#include <eosio.system/eosio.system.abi.hpp>
......@@ -11,6 +12,9 @@
#include <eosio.token/eosio.token.wast.hpp>
#include <eosio.token/eosio.token.abi.hpp>
#include <eosio.msig/eosio.msig.wast.hpp>
#include <eosio.msig/eosio.msig.abi.hpp>
#include <Runtime/Runtime.h>
#include <fc/variant_object.hpp>
......@@ -343,10 +347,7 @@ public:
void create_currency( name contract, name manager, asset maxsupply ) {
auto act = mutable_variant_object()
("issuer", manager )
("maximum_supply", maxsupply )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0);
("maximum_supply", maxsupply );
base_tester::push_action(contract, N(create), contract, act );
}
......@@ -1885,6 +1886,184 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester, * boost::uni
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(producers_upgrade_system_contract, eosio_system_tester) try {
//install multisig contract
abi_serializer msig_abi_ser;
{
create_account_with_resources( N(eosio.msig), N(eosio) );
BOOST_REQUIRE_EQUAL( success(), buyram( "eosio", "eosio.msig", "5000.0000 EOS" ) );
produce_block();
auto trace = base_tester::push_action(config::system_account_name, N(setpriv),
config::system_account_name, mutable_variant_object()
("account", "eosio.msig")
("is_priv", 1)
);
set_code( N(eosio.msig), eosio_msig_wast );
set_abi( N(eosio.msig), eosio_msig_abi );
produce_blocks();
const auto& accnt = control->db().get<account_object,by_name>( N(eosio.msig) );
abi_def msig_abi;
BOOST_REQUIRE_EQUAL(abi_serializer::to_abi(accnt.abi, msig_abi), true);
msig_abi_ser.set_abi(msig_abi);
}
//stake more than 15% of total EOS supply to activate chain
transfer( "eosio", "alice1111111", "650000000.0000 EOS", "eosio" );
BOOST_REQUIRE_EQUAL( success(), stake( "alice1111111", "alice1111111", "300000000.0000 EOS", "300000000.0000 EOS" ) );
// create accounts {defproducera, defproducerb, ..., defproducerz} and register as producers
std::vector<account_name> producer_names;
{
producer_names.reserve('z' - 'a' + 1);
const std::string root("defproducer");
for ( char c = 'a'; c < 'a'+21; ++c ) {
producer_names.emplace_back(root + std::string(1, c));
}
setup_producer_accounts(producer_names);
for (const auto& p: producer_names) {
BOOST_REQUIRE_EQUAL( success(), regproducer(p) );
}
}
produce_blocks( 250);
//BOOST_REQUIRE_EQUAL( name("defproducer2"), producer_keys[1].producer_name );
auto trace_auth = TESTER::push_action(config::system_account_name, updateauth::get_name(), config::system_account_name, mvo()
("account", name(config::system_account_name).to_string())
("permission", name(config::active_name).to_string())
("parent", name(config::owner_name).to_string())
("auth", authority(1, {key_weight{get_public_key( config::system_account_name, "active" ), 1}}, {
permission_level_weight{{config::system_account_name, config::eosio_code_name}, 1},
permission_level_weight{{config::producers_account_name, config::active_name}, 1}
}
))
);
BOOST_REQUIRE_EQUAL(transaction_receipt::executed, trace_auth->receipt->status);
//vote for producers
{
transfer( config::system_account_name, "alice1111111", "100000000.0000 EOS", config::system_account_name );
BOOST_REQUIRE_EQUAL(success(), stake( "alice1111111", "30000000.0000 EOS", "30000000.0000 EOS" ) );
BOOST_REQUIRE_EQUAL(success(), buyram( "alice1111111", "alice1111111", "30000000.0000 EOS" ) );
BOOST_REQUIRE_EQUAL(success(), push_action(N(alice1111111), N(voteproducer), mvo()
("voter", "alice1111111")
("proxy", name(0).to_string())
("producers", vector<account_name>(producer_names.begin(), producer_names.begin()+21))
)
);
}
produce_blocks( 250 );
auto producer_keys = control->head_block_state()->active_schedule.producers;
BOOST_REQUIRE_EQUAL( 21, producer_keys.size() );
BOOST_REQUIRE_EQUAL( name("defproducera"), producer_keys[0].producer_name );
//helper function
auto push_action_msig = [&]( const account_name& signer, const action_name &name, const variant_object &data, bool auth = true ) -> action_result {
string action_type_name = msig_abi_ser.get_action_type(name);
action act;
act.account = N(eosio.msig);
act.name = name;
act.data = msig_abi_ser.variant_to_binary( action_type_name, data );
return base_tester::push_action( std::move(act), auth ? uint64_t(signer) : signer == N(bob111111111) ? N(alice1111111) : N(bob111111111) );
};
// test begins
vector<permission_level> prod_perms;
for ( auto& x : producer_names ) {
prod_perms.push_back( { name(x), config::active_name } );
}
//prepare system contract with different hash (contract differs in one byte)
string eosio_system_wast2 = eosio_system_wast;
string msg = "producer votes must be unique and sorted";
auto pos = eosio_system_wast2.find(msg);
BOOST_REQUIRE( pos != std::string::npos );
msg[0] = 'P';
eosio_system_wast2.replace( pos, msg.size(), msg );
transaction trx;
{
auto code = wast_to_wasm( eosio_system_wast2 );
variant pretty_trx = fc::mutable_variant_object()
("expiration", "2020-01-01T00:30")
("ref_block_num", 2)
("ref_block_prefix", 3)
("max_net_usage_words", 0)
("max_cpu_usage_ms", 0)
("delay_sec", 0)
("actions", fc::variants({
fc::mutable_variant_object()
("account", name(config::system_account_name))
("name", "setcode")
("authorization", vector<permission_level>{ { config::system_account_name, config::active_name } })
("data", fc::mutable_variant_object() ("account", name(config::system_account_name))
("vmtype", 0)
("vmversion", "0")
("code", bytes( code.begin(), code.end() ))
)
})
);
abi_serializer::from_variant(pretty_trx, trx, get_resolver());
}
BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(propose), mvo()
("proposer", "alice1111111")
("proposal_name", "upgrade1")
("trx", trx)
("requested", prod_perms)
)
);
// get 15 approvals
for ( size_t i = 0; i < 14; ++i ) {
BOOST_REQUIRE_EQUAL(success(), push_action_msig( name(producer_names[i]), N(approve), mvo()
("proposer", "alice1111111")
("proposal_name", "upgrade1")
("level", permission_level{ name(producer_names[i]), config::active_name })
)
);
}
//should fail
BOOST_REQUIRE_EQUAL(error("condition: assertion failed: transaction authorization failed"),
push_action_msig( N(alice1111111), N(exec), mvo()
("proposer", "alice1111111")
("proposal_name", "upgrade1")
("executer", "alice1111111")
)
);
// one more approval
BOOST_REQUIRE_EQUAL(success(), push_action_msig( name(producer_names[14]), N(approve), mvo()
("proposer", "alice1111111")
("proposal_name", "upgrade1")
("level", permission_level{ name(producer_names[14]), config::active_name })
)
);
transaction_trace_ptr trace;
control->applied_transaction.connect([&]( const transaction_trace_ptr& t) { if (t->scheduled) { trace = t; } } );
BOOST_REQUIRE_EQUAL(success(), push_action_msig( N(alice1111111), N(exec), mvo()
("proposer", "alice1111111")
("proposal_name", "upgrade1")
("executer", "alice1111111")
)
);
BOOST_REQUIRE( bool(trace) );
BOOST_REQUIRE_EQUAL( 1, trace->action_traces.size() );
BOOST_REQUIRE_EQUAL( transaction_receipt::executed, trace->receipt->status );
produce_blocks( 250 );
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE(producer_onblock_check, eosio_system_tester) try {
......
......@@ -66,17 +66,11 @@ public:
}
action_result create( account_name issuer,
asset maximum_supply,
uint8_t issuer_can_freeze,
uint8_t issuer_can_recall,
uint8_t issuer_can_whitelist ) {
asset maximum_supply ) {
return push_action( N(eosio.token), N(create), mvo()
( "issuer", issuer)
( "maximum_supply", maximum_supply)
( "can_freeze", issuer_can_freeze)
( "can_recall", issuer_can_recall)
( "can_whitelist", issuer_can_whitelist)
);
}
......@@ -107,17 +101,12 @@ BOOST_AUTO_TEST_SUITE(eosio_token_tests)
BOOST_FIXTURE_TEST_CASE( create_tests, eosio_token_tester ) try {
auto token = create( N(alice), asset::from_string("1000.000 TKN"), false, false, false);
auto token = create( N(alice), asset::from_string("1000.000 TKN"));
auto stats = get_stats("3,TKN");
REQUIRE_MATCHING_OBJECT( stats, mvo()
("supply", "0.000 TKN")
("max_supply", "1000.000 TKN")
("issuer", "alice")
("can_freeze",0)
("can_recall",0)
("can_whitelist",0)
("is_frozen",false)
("enforce_whitelist",false)
);
produce_blocks(1);
......@@ -126,53 +115,43 @@ BOOST_FIXTURE_TEST_CASE( create_tests, eosio_token_tester ) try {
BOOST_FIXTURE_TEST_CASE( create_negative_max_supply, eosio_token_tester ) try {
BOOST_REQUIRE_EQUAL( error( "condition: assertion failed: max-supply must be positive" ),
create( N(alice), asset::from_string("-1000.000 TKN"), false, false, false)
create( N(alice), asset::from_string("-1000.000 TKN"))
);
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( symbol_already_exists, eosio_token_tester ) try {
auto token = create( N(alice), asset::from_string("100 TKN"), true, false, false);
auto token = create( N(alice), asset::from_string("100 TKN"));
auto stats = get_stats("0,TKN");
REQUIRE_MATCHING_OBJECT( stats, mvo()
("supply", "0 TKN")
("max_supply", "100 TKN")
("issuer", "alice")
("can_freeze",1)
("can_recall",0)
("can_whitelist",0)
("is_frozen",false)
("enforce_whitelist",false)
("supply", "0 TKN")
("max_supply", "100 TKN")
("issuer", "alice")
);
produce_blocks(1);
BOOST_REQUIRE_EQUAL( error( "condition: assertion failed: token with symbol already exists" ),
create( N(alice), asset::from_string("100 TKN"), true, false, false)
create( N(alice), asset::from_string("100 TKN"))
);
} FC_LOG_AND_RETHROW()
BOOST_FIXTURE_TEST_CASE( create_max_supply, eosio_token_tester ) try {
auto token = create( N(alice), asset::from_string("4611686018427387903 TKN"), true, false, false);
auto token = create( N(alice), asset::from_string("4611686018427387903 TKN"));
auto stats = get_stats("0,TKN");
REQUIRE_MATCHING_OBJECT( stats, mvo()
("supply", "0 TKN")
("max_supply", "4611686018427387903 TKN")
("issuer", "alice")
("can_freeze",1)
("can_recall",0)
("can_whitelist",0)
("is_frozen",false)
("enforce_whitelist",false)
);
produce_blocks(1);
asset max(10, symbol(SY(0, NKT)));
max.amount = 4611686018427387904;
BOOST_CHECK_EXCEPTION( create( N(alice), max, true, false, false) , asset_type_exception, [](const asset_type_exception& e) {
BOOST_CHECK_EXCEPTION( create( N(alice), max) , asset_type_exception, [](const asset_type_exception& e) {
return expect_assert_message(e, "magnitude of asset amount must be less than 2^62");
});
......@@ -181,17 +160,12 @@ BOOST_FIXTURE_TEST_CASE( create_max_supply, eosio_token_tester ) try {
BOOST_FIXTURE_TEST_CASE( create_max_decimals, eosio_token_tester ) try {
auto token = create( N(alice), asset::from_string("1.000000000000000000 TKN"), true, false, false);
auto token = create( N(alice), asset::from_string("1.000000000000000000 TKN"));
auto stats = get_stats("18,TKN");
REQUIRE_MATCHING_OBJECT( stats, mvo()
("supply", "0.000000000000000000 TKN")
("max_supply", "1.000000000000000000 TKN")
("issuer", "alice")
("can_freeze",1)
("can_recall",0)
("can_whitelist",0)
("is_frozen",false)
("enforce_whitelist",false)
);
produce_blocks(1);
......@@ -199,7 +173,7 @@ BOOST_FIXTURE_TEST_CASE( create_max_decimals, eosio_token_tester ) try {
//1.0000000000000000000 => 0x8ac7230489e80000L
max.amount = 0x8ac7230489e80000L;
BOOST_CHECK_EXCEPTION( create( N(alice), max, true, false, false) , asset_type_exception, [](const asset_type_exception& e) {
BOOST_CHECK_EXCEPTION( create( N(alice), max) , asset_type_exception, [](const asset_type_exception& e) {
return expect_assert_message(e, "magnitude of asset amount must be less than 2^62");
});
......@@ -207,7 +181,7 @@ BOOST_FIXTURE_TEST_CASE( create_max_decimals, eosio_token_tester ) try {
BOOST_FIXTURE_TEST_CASE( issue_tests, eosio_token_tester ) try {
auto token = create( N(alice), asset::from_string("1000.000 TKN"), false, false, false);
auto token = create( N(alice), asset::from_string("1000.000 TKN"));
produce_blocks(1);
issue( N(alice), N(alice), asset::from_string("500.000 TKN"), "hola" );
......@@ -217,18 +191,11 @@ BOOST_FIXTURE_TEST_CASE( issue_tests, eosio_token_tester ) try {
("supply", "500.000 TKN")
("max_supply", "1000.000 TKN")
("issuer", "alice")
("can_freeze",0)
("can_recall",0)
("can_whitelist",0)
("is_frozen",false)
("enforce_whitelist",false)
);
auto alice_balance = get_account(N(alice), "3,TKN");
REQUIRE_MATCHING_OBJECT( alice_balance, mvo()
("balance", "500.000 TKN")
("frozen", 0)
("whitelist", 1)
);
BOOST_REQUIRE_EQUAL( error( "condition: assertion failed: quantity exceeds available supply" ),
......@@ -248,7 +215,7 @@ BOOST_FIXTURE_TEST_CASE( issue_tests, eosio_token_tester ) try {
BOOST_FIXTURE_TEST_CASE( transfer_tests, eosio_token_tester ) try {
auto token = create( N(alice), asset::from_string("1000 CERO"), false, false, false);
auto token = create( N(alice), asset::from_string("1000 CERO"));
produce_blocks(1);
issue( N(alice), N(alice), asset::from_string("1000 CERO"), "hola" );
......@@ -258,18 +225,11 @@ BOOST_FIXTURE_TEST_CASE( transfer_tests, eosio_token_tester ) try {
("supply", "1000 CERO")
("max_supply", "1000 CERO")
("issuer", "alice")
("can_freeze",0)
("can_recall",0)
("can_whitelist",0)
("is_frozen",false)
("enforce_whitelist",false)
);
auto alice_balance = get_account(N(alice), "0,CERO");
REQUIRE_MATCHING_OBJECT( alice_balance, mvo()
("balance", "1000 CERO")
("frozen", 0)
("whitelist", 1)
);
transfer( N(alice), N(bob), asset::from_string("300 CERO"), "hola" );
......
......@@ -4,9 +4,6 @@
#include <eosio/chain/abi_serializer.hpp>
#include <eosio/chain/symbol.hpp>
#include <eosio.token/eosio.token.wast.hpp>
#include <eosio.token/eosio.token.abi.hpp>
#include <exchange/exchange.wast.hpp>
#include <exchange/exchange.abi.hpp>
......@@ -78,7 +75,7 @@ class exchange_tester : public TESTER {
}
asset get_balance(const account_name& account) const {
return get_currency_balance(N(eosio.token), symbol(SY(4,CUR)), account);
return get_currency_balance(N(exchange), symbol(SY(4,CUR)), account);
}
exchange_state get_market_state( account_name exchange, symbol sym ) {
......@@ -145,11 +142,6 @@ class exchange_tester : public TESTER {
FC_ASSERT( false, "unable to find loan balance" );
}
void deploy_currency( account_name ac ) {
create_account( ac );
set_code( ac, eosio_token_wast /*currency_wast*/ );
}
void deploy_exchange( account_name ac ) {
create_account( ac );
set_code( ac, exchange_wast );
......@@ -161,7 +153,7 @@ class exchange_tester : public TESTER {
("maximum_supply", maxsupply )
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
("can_whitelist", 0)
);
}
......@@ -236,20 +228,19 @@ class exchange_tester : public TESTER {
create_account( N(trader) );
deploy_exchange( N(exchange) );
deploy_currency( N(eosio.token) );
create_currency( N(eosio.token), N(eosio.token), A(1000000.00 USD) );
create_currency( N(eosio.token), N(eosio.token), A(1000000.00 BTC) );
create_currency( N(exchange), N(exchange), A(1000000.00 USD) );
create_currency( N(exchange), N(exchange), A(1000000.00 BTC) );
issue( N(eosio.token), N(eosio.token), N(dan), A(1000.00 USD) );
issue( N(eosio.token), N(eosio.token), N(dan), A(1000.00 BTC) );
issue( N(exchange), N(exchange), N(dan), A(1000.00 USD) );
issue( N(exchange), N(exchange), N(dan), A(1000.00 BTC) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 USD), N(eosio.token) ) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 BTC), N(eosio.token) ) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 USD), N(exchange) ) );
deposit( N(exchange), N(dan), extended_asset( A(500.00 BTC), N(exchange) ) );
create_exchange( N(exchange), N(dan),
extended_asset( A(400.00 USD), N(eosio.token) ),
extended_asset( A(400.00 BTC), N(eosio.token) ),
extended_asset( A(400.00 USD), N(exchange) ),
extended_asset( A(400.00 BTC), N(exchange) ),
A(10000000.00 EXC) );
produce_block();
......@@ -263,9 +254,9 @@ BOOST_AUTO_TEST_SUITE(exchange_tests)
BOOST_AUTO_TEST_CASE( bootstrap ) try {
auto expected = asset::from_string( "1000000.0000 CUR" );
exchange_tester t;
t.create_currency( N(eosio.token), N(eosio.token), expected );
t.issue( N(eosio.token), N(eosio.token), N(eosio.token), expected );
auto actual = t.get_currency_balance(N(eosio.token), expected.get_symbol(), N(eosio.token));
t.create_currency( N(exchange), N(exchange), expected );
t.issue( N(exchange), N(exchange), N(exchange), expected );
auto actual = t.get_currency_balance(N(exchange), expected.get_symbol(), N(exchange));
BOOST_REQUIRE_EQUAL(expected, actual);
} FC_LOG_AND_RETHROW() /// test_api_bootstrap
......@@ -274,38 +265,38 @@ BOOST_AUTO_TEST_CASE( exchange_create ) try {
auto expected = asset::from_string( "1000000.0000 CUR" );
exchange_tester t;
t.issue( N(eosio.token), N(eosio.token), N(trader), A(2000.00 BTC) );
t.issue( N(eosio.token), N(eosio.token), N(trader), A(2000.00 USD) );
t.issue( N(exchange), N(exchange), N(trader), A(2000.00 BTC) );
t.issue( N(exchange), N(exchange), N(trader), A(2000.00 USD) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 USD), N(eosio.token) ) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 BTC), N(eosio.token) ) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 USD), N(exchange) ) );
t.deposit( N(exchange), N(trader), extended_asset( A(1500.00 BTC), N(exchange) ) );
auto trader_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(trader) );
auto trader_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(trader) );
auto dan_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(dan) );
auto dan_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(dan) );
auto trader_ex_usd = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"USD"), N(trader) );
auto trader_ex_btc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"BTC"), N(trader) );
auto dan_ex_usd = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"USD"), N(dan) );
auto dan_ex_btc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"BTC"), N(dan) );
auto dan_ex_exc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"EXC"), N(dan) );
wdump((dan_ex_exc));
auto result = t.trade( N(exchange), N(trader), symbol(2,"EXC"),
extended_asset( A(10.00 BTC), N(eosio.token) ),
extended_asset( A(0.01 USD), N(eosio.token) ) );
extended_asset( A(10.00 BTC), N(exchange) ),
extended_asset( A(0.01 USD), N(exchange) ) );
for( const auto& at : result->action_traces )
ilog( "${s}", ("s",at.console) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(trader) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"BTC"), N(trader) );
wdump((trader_ex_btc.quantity));
wdump((trader_ex_usd.quantity));
result = t.trade( N(exchange), N(trader), symbol(2,"EXC"),
extended_asset( A(9.75 USD), N(eosio.token) ),
extended_asset( A(0.01 BTC), N(eosio.token) ) );
extended_asset( A(9.75 USD), N(exchange) ),
extended_asset( A(0.01 BTC), N(exchange) ) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(trader) );
trader_ex_usd = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"USD"), N(trader) );
trader_ex_btc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"BTC"), N(trader) );
for( const auto& at : result->action_traces )
ilog( "${s}", ("s",at.console) );
......@@ -326,19 +317,19 @@ BOOST_AUTO_TEST_CASE( exchange_lend ) try {
exchange_tester t;
t.create_account( N(lender) );
t.issue( N(eosio.token), N(eosio.token), N(lender), A(2000.00 BTC) );
t.issue( N(eosio.token), N(eosio.token), N(lender), A(2000.00 USD) );
t.issue( N(exchange), N(exchange), N(lender), A(2000.00 BTC) );
t.issue( N(exchange), N(exchange), N(lender), A(2000.00 USD) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 USD), N(eosio.token) ) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 BTC), N(eosio.token) ) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 USD), N(exchange) ) );
t.deposit( N(exchange), N(lender), extended_asset( A(1500.00 BTC), N(exchange) ) );
auto lender_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(lender) );
auto lender_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(lender) );
auto lender_ex_usd = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"USD"), N(lender) );
auto lender_ex_btc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"BTC"), N(lender) );
t.lend( N(exchange), N(lender), extended_asset( A(1000.00 USD), N(eosio.token) ), symbol(2,"EXC") );
t.lend( N(exchange), N(lender), extended_asset( A(1000.00 USD), N(exchange) ), symbol(2,"EXC") );
lender_ex_usd = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"USD"), N(lender) );
lender_ex_btc = t.get_exchange_balance( N(exchange), N(eosio.token), symbol(2,"BTC"), N(lender) );
lender_ex_usd = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"USD"), N(lender) );
lender_ex_btc = t.get_exchange_balance( N(exchange), N(exchange), symbol(2,"BTC"), N(lender) );
wdump((lender_ex_btc.quantity));
wdump((lender_ex_usd.quantity));
......@@ -351,7 +342,7 @@ BOOST_AUTO_TEST_CASE( exchange_lend ) try {
wdump((t.get_market_state( N(exchange), symbol(2,"EXC") ) ));
t.unlend( N(exchange), N(lender), lentshares, extended_symbol{ symbol(2,"USD"), N(eosio.token)}, symbol(2,"EXC") );
t.unlend( N(exchange), N(lender), lentshares, extended_symbol{ symbol(2,"USD"), N(exchange)}, symbol(2,"EXC") );
lentshares = t.get_lent_shares( N(exchange), symbol(2,"EXC"), N(lender), true );
wdump((lentshares));
......
......@@ -63,9 +63,6 @@ BOOST_AUTO_TEST_CASE( forking ) try {
auto cr = c.push_action( N(eosio.token), N(create), N(eosio.token), mutable_variant_object()
("issuer", "eosio" )
("maximum_supply", "10000000.0000 EOS")
("can_freeze", 0)
("can_recall", 0)
("can_whitelist", 0)
);
wdump((fc::json::to_pretty_string(cr)));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册