Skip to content

Commit

Permalink
Merge pull request #13 from DaoCasino/fix-tests-409
Browse files Browse the repository at this point in the history
CYB-409 SYS->BET; fixed tests
  • Loading branch information
adrianopol authored Oct 29, 2019
2 parents 3219ee2 + e5266f2 commit 44e3ef0
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 65 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,21 @@ if(ENABLE_TX_SPONSORSHIP)
endif()

include(utils)
###

if("${CORE_SYMBOL_NAME}" STREQUAL "")
set(CORE_SYMBOL_NAME "SYS")
set(CORE_SYMBOL_NAME "BET")
endif()
string(TOUPPER ${CORE_SYMBOL_NAME} CORE_SYMBOL_NAME)

string(LENGTH ${CORE_SYMBOL_NAME} CORE_SYMBOL_NAME_LENGTH)
if(CORE_SYMBOL_NAME_LENGTH GREATER 7)
message(FATAL_ERROR "CORE_SYMBOL_NAME length must be between 1 and 7 characters")
endif()

message(STATUS "Using '${CORE_SYMBOL_NAME}' as CORE symbol name")

###

if("${EOSIO_ROOT_KEY}" STREQUAL "")
set(EOSIO_ROOT_KEY "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV")
endif()
Expand Down
2 changes: 1 addition & 1 deletion Docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG registry
FROM ${registry}/haya:latest-builder as builder
ARG symbol=SYS
ARG symbol=BET

ADD . daobet
WORKDIR daobet
Expand Down
2 changes: 1 addition & 1 deletion scripts/daobet_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CMAKE_BUILD_TYPE=Release
export DISK_MIN=20
DOXYGEN=false
ENABLE_COVERAGE_TESTING=false
CORE_SYMBOL_NAME="SYS"
CORE_SYMBOL_NAME="BET"
START_MAKE=true

TIME_BEGIN=$( date -u +%s )
Expand Down
54 changes: 41 additions & 13 deletions testnet.template
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash

set -eu

readonly core_symbol=BET

# set up a wallet just for holding the key used during blockchain ignition

bioshost=$BIOS_HOSTNAME
bioshost=${BIOS_HOSTNAME:-}
if [ -z "$bioshost" ]; then
bioshost=localhost
fi

biosport=$BIOS_HTTP_PORT
biosport=${BIOS_HTTP_PORT:-}
if [ -z "$biosport" ]; then
biosport=9776
fi
Expand All @@ -33,7 +37,7 @@ fi
mkdir $wddir

step=1
echo Initializing ignition sequence at $(date) | tee $logfile
echo "Initializing ignition sequence at $(date)" | tee $logfile

echo "http-server-address = $wdaddr" > $wddir/config.ini

Expand All @@ -44,9 +48,9 @@ sleep 1

ecmd () {
echo ===== Start: $step ============ >> $logfile
echo executing: daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport $* | tee -a $logfile
echo ----------------------- >> $logfile
set -x
programs/daobet-cli/daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport $* >> $logfile 2>&1
set +x
echo ==== End: $step ============== >> $logfile
step=$(($step + 1))
}
Expand All @@ -56,7 +60,16 @@ wcmd () {
}

cacmd () {
programs/daobet-cli/daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport system newaccount --transfer --stake-net "10000000.0000 SYS" --stake-cpu "10000000.0000 SYS" --stake-vote "1.0000 SYS" --buy-ram "10000000.0000 SYS" eosio $* >> $logfile 2>&1
programs/daobet-cli/daobet-cli \
--wallet-url $wdurl \
--url http://$bioshost:$biosport \
system newaccount \
--transfer \
--stake-net "10000000.0000 $core_symbol" \
--stake-cpu "10000000.0000 $core_symbol" \
--stake-vote "1.0000 $core_symbol" \
--buy-ram "10000000.0000 $core_symbol" eosio $* \
>> $logfile 2>&1
ecmd system regproducer $1 $2
ecmd system voteproducer prods $1 $1
}
Expand Down Expand Up @@ -98,17 +111,32 @@ ecmd set contract eosio.token unittests/contracts/eosio.token eosio.token.wasm e
ecmd set contract eosio.msig unittests/contracts/eosio.msig eosio.msig.wasm eosio.msig.abi
ecmd set contract eosio.wrap unittests/contracts/eosio.wrap eosio.wrap.wasm eosio.wrap.abi

echo ===== Start: $step ============ >> $logfile
echo executing: daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio.token create '[ "eosio", "10000000000.0000 SYS" ]' -p eosio.token | tee -a $logfile
echo executing: daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio.token issue '[ "eosio", "1000000000.0000 SYS", "memo" ]' -p eosio | tee -a $logfile
echo ----------------------- >> $logfile
programs/daobet-cli/daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio.token create '[ "eosio", "10000000000.0000 SYS" ]' -p eosio.token >> $logfile 2>&1
programs/daobet-cli/daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio.token issue '[ "eosio", "1000000000.0000 SYS", "memo" ]' -p eosio >> $logfile 2>&1
echo "===== Start: $step ============" >> $logfile
set -x
programs/daobet-cli/daobet-cli \
--wallet-url $wdurl \
--url http://$bioshost:$biosport \
push action eosio.token create "[ \"eosio\", \"10000000000.0000 $core_symbol\" ]" \
-p eosio.token \
>> $logfile 2>&1

programs/daobet-cli/daobet-cli \
--wallet-url $wdurl \
--url http://$bioshost:$biosport \
push action eosio.token issue "[ \"eosio\", \"1000000000.0000 $core_symbol\", \"memo\" ]" \
-p eosio \
>> $logfile 2>&1
set +x
echo ==== End: $step ============== >> $logfile
step=$(($step + 1))

ecmd set contract eosio unittests/contracts/eosio.system eosio.system.wasm eosio.system.abi
programs/daobet-cli/daobet-cli --wallet-url $wdurl --url http://$bioshost:$biosport push action eosio init '[0, "4,SYS"]' -p eosio >> $logfile 2>&1
programs/daobet-cli/daobet-cli \
--wallet-url $wdurl \
--url http://$bioshost:$biosport \
push action eosio init "[0, \"4,$core_symbol\"]" \
-p eosio \
>> $logfile 2>&1

# Manual deployers, add a series of lines below this block that looks like:
# cacmd $PRODNAME[0] $OWNERKEY[0] $ACTIVEKEY[0]
Expand Down
37 changes: 24 additions & 13 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@ find_package(LLVM 4.0 REQUIRED CONFIG)

link_directories(${LLVM_LIBRARY_DIR})

set( CMAKE_CXX_STANDARD 14 )
set(CMAKE_CXX_STANDARD 14)

add_executable(plugin_test
chain_plugin_tests.cpp
get_table_tests.cpp
main.cpp
wallet_tests.cpp
)

target_link_libraries(plugin_test
chain_plugin
chainbase
eosio_chain
eosio_testing
fc
wallet_plugin
${PLATFORM_SPECIFIC_LIBS})

target_include_directories(plugin_test PUBLIC
${CMAKE_BINARY_DIR}/unittests/include
${CMAKE_SOURCE_DIR}/plugins/chain_plugin/include
${CMAKE_SOURCE_DIR}/plugins/net_plugin/include
${CMAKE_SOURCE_DIR}/plugins/wallet_plugin/include
)

include_directories("${CMAKE_SOURCE_DIR}/plugins/wallet_plugin/include")

file(GLOB UNIT_TESTS "*.cpp")

add_executable( plugin_test ${UNIT_TESTS} )
target_link_libraries( plugin_test eosio_testing eosio_chain chainbase chain_plugin wallet_plugin fc ${PLATFORM_SPECIFIC_LIBS} )

target_include_directories( plugin_test PUBLIC
${CMAKE_SOURCE_DIR}/plugins/net_plugin/include
${CMAKE_SOURCE_DIR}/plugins/chain_plugin/include
${CMAKE_BINARY_DIR}/unittests/include/ )

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/core_symbol.py.in ${CMAKE_CURRENT_BINARY_DIR}/core_symbol.py)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testUtils.py ${CMAKE_CURRENT_BINARY_DIR}/testUtils.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/WalletMgr.py ${CMAKE_CURRENT_BINARY_DIR}/WalletMgr.py COPYONLY)
Expand Down
28 changes: 14 additions & 14 deletions tests/get_table_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ BOOST_FIXTURE_TEST_CASE( get_scope_test, TESTER ) try {
// create currency
auto act = mutable_variant_object()
("issuer", "eosio")
("maximum_supply", eosio::chain::asset::from_string("1000000000.0000 SYS"));
("maximum_supply", eosio::chain::asset::from_string("1000000000.0000 " CORE_SYMBOL_NAME));
push_action(N(eosio.token), N(create), N(eosio.token), act );

// issue
for (account_name a: accs) {
push_action( N(eosio.token), N(issue), "eosio", mutable_variant_object()
("to", name(a) )
("quantity", eosio::chain::asset::from_string("999.0000 SYS") )
("quantity", eosio::chain::asset::from_string("999.0000 " CORE_SYMBOL_NAME) )
("memo", "")
);
}
Expand Down Expand Up @@ -131,14 +131,14 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, TESTER ) try {
// create currency
auto act = mutable_variant_object()
("issuer", "eosio")
("maximum_supply", eosio::chain::asset::from_string("1000000000.0000 SYS"));
("maximum_supply", eosio::chain::asset::from_string("1000000000.0000 " CORE_SYMBOL_NAME));
push_action(N(eosio.token), N(create), N(eosio.token), act );

// issue
for (account_name a: accs) {
push_action( N(eosio.token), N(issue), "eosio", mutable_variant_object()
("to", name(a) )
("quantity", eosio::chain::asset::from_string("10000.0000 SYS") )
("quantity", eosio::chain::asset::from_string("10000.0000 " CORE_SYMBOL_NAME) )
("memo", "")
);
}
Expand Down Expand Up @@ -204,7 +204,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, TESTER ) try {
BOOST_REQUIRE_EQUAL("9999.0000 AAA", result.rows[0]["balance"].as_string());
BOOST_REQUIRE_EQUAL("8888.0000 BBB", result.rows[1]["balance"].as_string());
BOOST_REQUIRE_EQUAL("7777.0000 CCC", result.rows[2]["balance"].as_string());
BOOST_REQUIRE_EQUAL("10000.0000 SYS", result.rows[3]["balance"].as_string());
BOOST_REQUIRE_EQUAL("10000.0000 " CORE_SYMBOL_NAME, result.rows[3]["balance"].as_string());
}

// get table: reverse ordered
Expand All @@ -216,7 +216,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, TESTER ) try {
BOOST_REQUIRE_EQUAL("9999.0000 AAA", result.rows[3]["balance"].as_string());
BOOST_REQUIRE_EQUAL("8888.0000 BBB", result.rows[2]["balance"].as_string());
BOOST_REQUIRE_EQUAL("7777.0000 CCC", result.rows[1]["balance"].as_string());
BOOST_REQUIRE_EQUAL("10000.0000 SYS", result.rows[0]["balance"].as_string());
BOOST_REQUIRE_EQUAL("10000.0000 " CORE_SYMBOL_NAME, result.rows[0]["balance"].as_string());
}

// get table: reverse ordered, with ram payer
Expand All @@ -229,7 +229,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, TESTER ) try {
BOOST_REQUIRE_EQUAL("9999.0000 AAA", result.rows[3]["data"]["balance"].as_string());
BOOST_REQUIRE_EQUAL("8888.0000 BBB", result.rows[2]["data"]["balance"].as_string());
BOOST_REQUIRE_EQUAL("7777.0000 CCC", result.rows[1]["data"]["balance"].as_string());
BOOST_REQUIRE_EQUAL("10000.0000 SYS", result.rows[0]["data"]["balance"].as_string());
BOOST_REQUIRE_EQUAL("10000.0000 " CORE_SYMBOL_NAME, result.rows[0]["data"]["balance"].as_string());
BOOST_REQUIRE_EQUAL("eosio", result.rows[0]["payer"].as_string());
BOOST_REQUIRE_EQUAL("eosio", result.rows[1]["payer"].as_string());
BOOST_REQUIRE_EQUAL("eosio", result.rows[2]["payer"].as_string());
Expand Down Expand Up @@ -280,7 +280,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, TESTER ) try {
BOOST_REQUIRE_EQUAL(1u, result.rows.size());
BOOST_REQUIRE_EQUAL(true, result.more);
if (result.rows.size() >= 1) {
BOOST_REQUIRE_EQUAL("10000.0000 SYS", result.rows[0]["balance"].as_string());
BOOST_REQUIRE_EQUAL("10000.0000 " CORE_SYMBOL_NAME, result.rows[0]["balance"].as_string());
}

// get table: normal case, with bound & limit
Expand Down Expand Up @@ -326,14 +326,14 @@ BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, TESTER ) try {
// create currency
auto act = mutable_variant_object()
("issuer", "eosio")
("maximum_supply", eosio::chain::asset::from_string("1000000000.0000 SYS"));
("maximum_supply", eosio::chain::asset::from_string("1000000000.0000 " CORE_SYMBOL_NAME));
push_action(N(eosio.token), N(create), N(eosio.token), act );

// issue
for (account_name a: accs) {
push_action( N(eosio.token), N(issue), "eosio", mutable_variant_object()
("to", name(a) )
("quantity", eosio::chain::asset::from_string("10000.0000 SYS") )
("quantity", eosio::chain::asset::from_string("10000.0000 " CORE_SYMBOL_NAME) )
("memo", "")
);
}
Expand All @@ -356,10 +356,10 @@ BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, TESTER ) try {
);
};

bidname(N(inita), N(com), eosio::chain::asset::from_string("10.0000 SYS"));
bidname(N(initb), N(org), eosio::chain::asset::from_string("11.0000 SYS"));
bidname(N(initc), N(io), eosio::chain::asset::from_string("12.0000 SYS"));
bidname(N(initd), N(html), eosio::chain::asset::from_string("14.0000 SYS"));
bidname(N(inita), N(com), eosio::chain::asset::from_string("10.0000 " CORE_SYMBOL_NAME));
bidname(N(initb), N(org), eosio::chain::asset::from_string("11.0000 " CORE_SYMBOL_NAME));
bidname(N(initc), N(io), eosio::chain::asset::from_string("12.0000 " CORE_SYMBOL_NAME));
bidname(N(initd), N(html), eosio::chain::asset::from_string("14.0000 " CORE_SYMBOL_NAME));
produce_blocks(1);

// get table: normal case
Expand Down
4 changes: 2 additions & 2 deletions tutorials/bios-boot-tutorial/bios-boot-tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def stepSetSystemContract():
sleep(1)
run(args.cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active')
def stepInitSystemContract():
run(args.cleos + 'push action eosio init' + jsonArg(['0', '4,SYS']) + '-p eosio@active')
run(args.cleos + 'push action eosio init' + jsonArg(['0', '4,BET']) + '-p eosio@active')
sleep(1)
def stepCreateStakedAccounts():
createStakedAccounts(0, len(accounts))
Expand Down Expand Up @@ -359,7 +359,7 @@ def stepLog():
parser.add_argument('--genesis', metavar='', help="Path to genesis.json", default="./genesis.json")
parser.add_argument('--wallet-dir', metavar='', help="Path to wallet directory", default='./wallet/')
parser.add_argument('--log-path', metavar='', help="Path to log file", default='./output.log')
parser.add_argument('--symbol', metavar='', help="The eosio.system symbol", default='SYS')
parser.add_argument('--symbol', metavar='', help="The eosio.system symbol", default='BET')
parser.add_argument('--user-limit', metavar='', help="Max number of users. (0 = no limit)", type=int, default=3000)
parser.add_argument('--max-user-keys', metavar='', help="Maximum user keys to import into wallet", type=int, default=10)
parser.add_argument('--ram-funds', metavar='', help="How much funds for each user to spend on ram", type=float, default=0.1)
Expand Down
7 changes: 4 additions & 3 deletions unittests/abi_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,10 @@ BOOST_AUTO_TEST_CASE(general)
{
"publickey" : "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"publickey_arr" : ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"],
"asset" : "100.0000 SYS",
"asset_arr" : ["100.0000 SYS","100.0000 SYS"],
)====="
" \"asset\" : \"100.0000 " CORE_SYMBOL_NAME "\","
" \"asset_arr\" : [\"100.0000 " CORE_SYMBOL_NAME "\",\"100.0000 " CORE_SYMBOL_NAME "\"],"
R"=====(
"string" : "ola ke ase",
"string_arr" : ["ola ke ase","ola ke desi"],
"block_timestamp_type" : "2021-12-20T15",
Expand Down
4 changes: 2 additions & 2 deletions unittests/bootseq_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ BOOST_FIXTURE_TEST_CASE( bootseq_test, bootseq_tester ) {
BOOST_TEST(eosio_token_acc.privileged == true);


// Create SYS tokens in eosio.token, set its manager as eosio
// Create CORE_SYMBOL_NAME tokens in eosio.token, set its manager as eosio
auto max_supply = core_from_string("10000000000.0000"); /// 1x larger than 1B initial tokens
auto initial_supply = core_from_string("1000000000.0000"); /// 1x larger than 1B initial tokens
create_currency(N(eosio.token), config::system_account_name, max_supply);
// Issue the genesis supply of 1 billion SYS tokens to eosio.system
// Issue the genesis supply of 1 billion CORE_SYMBOL_NAME tokens to eosio.system
issue(N(eosio.token), config::system_account_name, config::system_account_name, initial_supply);

auto actual = get_balance(config::system_account_name);
Expand Down
12 changes: 3 additions & 9 deletions unittests/contracts.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@

#include <eosio/testing/tester.hpp>

#define CORE_SYM_NAME "${CORE_SYMBOL_NAME}"
// CORE_SYMBOL_NAME macro is passed from the build system
#define CORE_SYM_PRECISION 4

#define _STRINGIZE1(x) #x
#define _STRINGIZE2(x) _STRINGIZE1(x)

#define CORE_SYM_STR ( _STRINGIZE2(CORE_SYM_PRECISION) "," CORE_SYM_NAME )
#define CORE_SYM ( ::eosio::chain::string_to_symbol_c( CORE_SYM_PRECISION, CORE_SYM_NAME ) )

struct core_sym {
static inline eosio::chain::asset from_string(const std::string& s) {
return eosio::chain::asset::from_string(s + " " CORE_SYM_NAME);
}
};
#define CORE_SYM_STR ( _STRINGIZE2(CORE_SYM_PRECISION) "," CORE_SYMBOL_NAME )
#define CORE_SYM ( ::eosio::chain::string_to_symbol_c( CORE_SYM_PRECISION, CORE_SYMBOL_NAME ) )

// CN -> contract C++ name, C -> contract name, D -> top level directory
#define MAKE_READ_WASM_ABI(CN,C, D) \
Expand Down
10 changes: 5 additions & 5 deletions unittests/currency_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ BOOST_FIXTURE_TEST_CASE(test_symbol, TESTER) try {
}

{
symbol sys(4, "SYS");
BOOST_REQUIRE_EQUAL(SY(4,SYS), sys.value());
BOOST_REQUIRE_EQUAL("4,SYS", sys.to_string());
BOOST_REQUIRE_EQUAL("SYS", sys.name());
symbol sys(4, CORE_SYMBOL_NAME);
BOOST_REQUIRE_EQUAL(::eosio::chain::string_to_symbol_c(4, CORE_SYMBOL_NAME), sys.value());
BOOST_REQUIRE_EQUAL("4," CORE_SYMBOL_NAME, sys.to_string());
BOOST_REQUIRE_EQUAL(CORE_SYMBOL_NAME, sys.name());
BOOST_REQUIRE_EQUAL(4, sys.decimals());
}

// default is "4,${CORE_SYMBOL_NAME}"
// default is ("4," CORE_SYMBOL_NAME)
{
symbol def;
BOOST_REQUIRE_EQUAL(4, def.decimals());
Expand Down

0 comments on commit 44e3ef0

Please sign in to comment.