From e5266f2d5ff810cd772dcae0b041ad3159bb61c8 Mon Sep 17 00:00:00 2001 From: Andrew Petelin Date: Mon, 28 Oct 2019 23:02:37 +0300 Subject: [PATCH] CYB-409 SYS->BET; fixed tests --- CMakeLists.txt | 6 ++- Docker/dev/Dockerfile | 2 +- scripts/daobet_build.sh | 2 +- testnet.template | 54 ++++++++++++++----- tests/CMakeLists.txt | 37 ++++++++----- tests/get_table_tests.cpp | 28 +++++----- .../bios-boot-tutorial/bios-boot-tutorial.py | 4 +- unittests/abi_tests.cpp | 7 +-- unittests/bootseq_tests.cpp | 4 +- unittests/contracts.hpp.in | 12 ++--- unittests/currency_tests.cpp | 10 ++-- 11 files changed, 101 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d188021f64e..1e190b7493d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -223,9 +223,10 @@ 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) @@ -233,9 +234,10 @@ 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() diff --git a/Docker/dev/Dockerfile b/Docker/dev/Dockerfile index c928dca5c02..6f4078e1ff5 100644 --- a/Docker/dev/Dockerfile +++ b/Docker/dev/Dockerfile @@ -1,6 +1,6 @@ ARG registry FROM ${registry}/haya:latest-builder as builder -ARG symbol=SYS +ARG symbol=BET ADD . daobet WORKDIR daobet diff --git a/scripts/daobet_build.sh b/scripts/daobet_build.sh index ad862f87eed..0eef3601578 100755 --- a/scripts/daobet_build.sh +++ b/scripts/daobet_build.sh @@ -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 ) diff --git a/testnet.template b/testnet.template index 8c910da7bd6..42cdef2e534 100644 --- a/testnet.template +++ b/testnet.template @@ -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 @@ -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 @@ -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)) } @@ -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 } @@ -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] diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 683a476822c..0f285ec5015 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/get_table_tests.cpp b/tests/get_table_tests.cpp index 6abeb325913..5ac13c58645 100644 --- a/tests/get_table_tests.cpp +++ b/tests/get_table_tests.cpp @@ -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", "") ); } @@ -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", "") ); } @@ -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 @@ -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 @@ -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()); @@ -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 @@ -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", "") ); } @@ -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 diff --git a/tutorials/bios-boot-tutorial/bios-boot-tutorial.py b/tutorials/bios-boot-tutorial/bios-boot-tutorial.py index dea393a5168..45a51e8ad0a 100755 --- a/tutorials/bios-boot-tutorial/bios-boot-tutorial.py +++ b/tutorials/bios-boot-tutorial/bios-boot-tutorial.py @@ -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)) @@ -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) diff --git a/unittests/abi_tests.cpp b/unittests/abi_tests.cpp index 7e6c84fb6f2..40cd796e2d6 100644 --- a/unittests/abi_tests.cpp +++ b/unittests/abi_tests.cpp @@ -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", diff --git a/unittests/bootseq_tests.cpp b/unittests/bootseq_tests.cpp index a3df02b652c..fd33c716275 100644 --- a/unittests/bootseq_tests.cpp +++ b/unittests/bootseq_tests.cpp @@ -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); diff --git a/unittests/contracts.hpp.in b/unittests/contracts.hpp.in index 8dd1f2b4dcf..14717067b2a 100644 --- a/unittests/contracts.hpp.in +++ b/unittests/contracts.hpp.in @@ -6,20 +6,14 @@ #include -#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) \ diff --git a/unittests/currency_tests.cpp b/unittests/currency_tests.cpp index 0485d0a4681..a1d431b25b6 100644 --- a/unittests/currency_tests.cpp +++ b/unittests/currency_tests.cpp @@ -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());