remove the --debug-allow-gm-commands-from-account option

allow usage of an alternate game account key pair for tests instead
This commit is contained in:
Crypto City 2022-08-03 04:47:41 +00:00
parent 516c893e6f
commit 070a4d46da
9 changed files with 40 additions and 56 deletions

View File

@ -120,6 +120,7 @@
#define MAYOR_CC_PMSPK "46ac846c12a551312e8447a51d0dbf9317f09ebed05bbd7f00d471c153f8c84d"
#define MAYOR_CC_PMVPK "4ba3008c0b8936f78b580f3ae8bf61456d3583ade32fe7d0fd576f1fb3aa9d36"
#define GAME_CC_KEY "bc65c0c663977a7501ec1771f1ddd934bcedbec01e3ba4d2b7729b9fe1ad46fd"
#define GAME_TEST_CC_KEY "ff7f4801ac6942c195bf21a5d3a720d55147c6161204153530aba6f7fdfc9cfb"
using namespace cryptonote;
@ -2823,7 +2824,10 @@ bool add_init_state(cryptonote::BlockchainDB &db)
epee::string_tools::hex_to_pod(MAYOR_CC_KEY, spend_mayor);
epee::string_tools::hex_to_pod(MAYOR_CC_PMSPK, pmspk_mayor);
epee::string_tools::hex_to_pod(MAYOR_CC_PMVPK, pmvpk_mayor);
epee::string_tools::hex_to_pod(GAME_CC_KEY, spend_game);
if (getenv("CC_USE_TEST_GAME_KEY"))
epee::string_tools::hex_to_pod(GAME_TEST_CC_KEY, spend_game);
else
epee::string_tools::hex_to_pod(GAME_CC_KEY, spend_game);
// 1: mayor account
uint32_t id = db.allocate_new_cc_account(spend_mayor, "Sigrid Sigrúnarsdóttir", pmspk_mayor, pmvpk_mayor);

View File

@ -75,8 +75,6 @@ DISABLE_VS_WARNINGS(4355)
// basically at least how many bytes the block itself serializes to without the miner tx
#define BLOCK_SIZE_SANITY_LEEWAY 100
static uint32_t allow_gm_commands_from_account = GAME_ACCOUNT;
namespace cryptonote
{
const command_line::arg_descriptor<bool, false> arg_testnet_on = {
@ -239,11 +237,6 @@ namespace cryptonote
, "Keep alternative blocks on restart"
, false
};
const command_line::arg_descriptor<uint32_t> arg_debug_allow_gm_commands_from_account = {
"debug-allow-gm-commands-from-account"
, "Change which account may issue GM commands for testing purposes (do not use on real network)."
, GAME_ACCOUNT
};
//-----------------------------------------------------------------------------------------------
core::core(i_cryptonote_protocol* pprotocol):
@ -372,7 +365,6 @@ namespace cryptonote
command_line::add_arg(desc, arg_reorg_notify);
command_line::add_arg(desc, arg_block_rate_notify);
command_line::add_arg(desc, arg_keep_alt_blocks);
command_line::add_arg(desc, arg_debug_allow_gm_commands_from_account);
miner::init_options(desc);
BlockchainDB::init_options(desc);
@ -419,9 +411,6 @@ namespace cryptonote
test_drop_download();
epee::debug::g_test_dbg_lock_sleep() = command_line::get_arg(vm, arg_test_dbg_lock_sleep);
allow_gm_commands_from_account = command_line::get_arg(vm, arg_debug_allow_gm_commands_from_account);
cc::cc_command_handler_new_item::test_game_account_delegate = allow_gm_commands_from_account;
return true;
}
@ -1311,10 +1300,10 @@ namespace cryptonote
if (cryptonote::is_cc_command_restricted(tx.cc_cmd))
{
const cryptonote::cc_command_base_t *base = cryptonote::get_cc_command_base(tx.cc_cmd);
if (!base || base->cc_account != allow_gm_commands_from_account)
if (!base || base->cc_account != GAME_ACCOUNT)
{
MERROR_VER("Only the game account may issue this command");
MERROR_VER("Allowed: " << allow_gm_commands_from_account << ", actual " << base->cc_account);
MERROR_VER("Allowed: " << GAME_ACCOUNT << ", actual " << base->cc_account);
return false;
}
}

View File

@ -46,12 +46,6 @@ using namespace tb;
extern "C" void cn_slow_hash_free_state(void);
static const command_line::arg_descriptor<uint32_t> arg_debug_allow_gm_commands_from_account = {
"debug-allow-gm-commands-from-account",
"Change which account may issue GM commands for testing purposes (do not use on real network).",
GAME_ACCOUNT
};
static const command_line::arg_descriptor<bool> arg_dump_load_timings = {
"dump-load-timings",
"Dump load timings on console.",
@ -431,7 +425,6 @@ public:
std::string get_daemon_error() const { return daemon_error; }
bool is_loading() const { return loading; }
bool is_syncing() const { return needs_sync; }
uint32_t get_authorized_game_account() const { return authorized_game_account; }
bool is_daemon_syncing();
std::string get_mining_state() { boost::lock_guard<boost::mutex> lock(mining_state_lock); return mining_state; }
@ -513,7 +506,6 @@ private:
GameWallet::Connection connection;
std::string daemon_error;
bool loading;
uint32_t authorized_game_account;
#ifdef CC_USE_ZMQ_PUBSUB
void *zmq_context;
boost::thread *zmq_thread;
@ -550,7 +542,6 @@ GameWalletInternal::GameWalletInternal(Context *ctx):
spectator(true),
connection(GameWallet::disconnected),
loading(false),
authorized_game_account(GAME_ACCOUNT),
#ifdef CC_USE_ZMQ_PUBSUB
zmq_context(NULL),
zmq_thread(NULL),
@ -568,7 +559,6 @@ void GameWalletInternal::init(int argc, const char **argv)
boost::program_options::options_description desc_params(wallet_args::tr("Wallet options"));
tools::wallet2::init_options(desc_params);
command_line::add_arg(desc_params, wallet_args::arg_wallet_file());
command_line::add_arg(desc_params, arg_debug_allow_gm_commands_from_account);
command_line::add_arg(desc_params, arg_dump_load_timings);
boost::program_options::positional_options_description positional_options;
@ -593,8 +583,6 @@ void GameWalletInternal::init(int argc, const char **argv)
SubscribeToEvent(&loader, E_WALLET_LOADING_WALLET, URHO3D_HANDLER(GameWalletInternal, HandleLoadingWallet));
loader.Run();
authorized_game_account = command_line::get_arg(*vm, arg_debug_allow_gm_commands_from_account);
create_spectator_wallet();
}
@ -2782,11 +2770,6 @@ void GameWallet::HandleCreatingNewAccount(StringHash eventType, VariantMap& even
SendEvent(E_WALLET_CREATING_NEW_ACCOUNT, eventData);
}
uint32_t GameWallet::get_authorized_game_account()
{
return internal->get_authorized_game_account();
}
uint32_t GameWallet::lookup_account(const std::string &pkey)
{
return internal->lookup_account(pkey);

View File

@ -142,7 +142,6 @@ public:
std::string get_daemon_error();
bool is_loading();
bool is_syncing();
uint32_t get_authorized_game_account();
bool generate_invitation(uint64_t amount, uint64_t expiration, const crypto::public_key &recipient, std::string &invitation);
bool generate_new_wallet(const char *wallet_file);

View File

@ -68,7 +68,7 @@ UIScriptsDialog::ScriptWidget::ScriptWidget(ScriptItem *item, ScriptSource *sour
const bool enable_play = item->mode == UIScriptsDialog::mode_play;
const bool enable_select = item->mode == UIScriptsDialog::mode_select;
boost::optional<bool> enabled;
if (item->dialog->game->playerState.id == item->dialog->authorized_game_account)
if (item->dialog->game->playerState.id == GAME_ACCOUNT)
enabled = item->enabled;
SetupScriptRow(GetContentRoot(), item->str, item->desc, item->icon, item->available, enable_play, enable_select, item->requirements, enabled);
@ -133,7 +133,6 @@ UIScriptsDialog::UIScriptsDialog(Context *ctx, const GameState *game, mode_t mod
view_script_source(0),
enable_script(0),
disable_script(0),
authorized_game_account(0),
prev_script(0),
prev_script_state(0),
newScriptDialog(nullptr)
@ -172,7 +171,7 @@ void UIScriptsDialog::Refresh(const std::shared_ptr<GameWallet> &w)
const uint32_t current_script = game->playerState.script;
const uint32_t current_script_state = game->playerState.script_state;
listContainer->SetValue(current_script == 0 || (game->debug && game->playerState.id == w->get_authorized_game_account()));
listContainer->SetValue(current_script == 0 || (game->debug && game->playerState.id == GAME_ACCOUNT));
scriptContainer->SetValue(current_script != 0 && !choice_made);
waitingContainer->SetValue(!!choice_made);
@ -187,10 +186,10 @@ void UIScriptsDialog::Refresh(const std::shared_ptr<GameWallet> &w)
current_script_data = script_data;
}
const bool force = current_script == 0 || current_script != prev_script || current_script_state != prev_script_state || (game->debug && game->playerState.id == w->get_authorized_game_account());
const bool force = current_script == 0 || current_script != prev_script || current_script_state != prev_script_state || (game->debug && game->playerState.id == GAME_ACCOUNT);
if (force)
{
if (current_script == 0 || (game->debug && game->playerState.id == w->get_authorized_game_account()))
if (current_script == 0 || (game->debug && game->playerState.id == GAME_ACCOUNT))
FillScriptList(w);
if (!choice_made)
FillChoiceList(w);
@ -334,7 +333,7 @@ void UIScriptsDialog::FillScriptList(const std::shared_ptr<GameWallet> &w)
if (!really_show_all)
{
if (!enabled && game->playerState.id != w->get_authorized_game_account())
if (!enabled && game->playerState.id != GAME_ACCOUNT)
continue;
if (mode == mode_play)
{
@ -351,7 +350,7 @@ void UIScriptsDialog::FillScriptList(const std::shared_ptr<GameWallet> &w)
}
// add the script number if we're the game account, makes it easier to manage scripts
if (game->playerState.id == w->get_authorized_game_account())
if (game->playerState.id == GAME_ACCOUNT)
name = "[" + std::to_string(id) + "] " + name;
ScriptItem *item = new ScriptItem(this, id, name, icon, desc, available || mode == mode_select, requirements, overrides, selected_text, mode, enabled);
@ -619,11 +618,7 @@ void UIScriptsDialog::FillChoiceList(const std::shared_ptr<GameWallet> &w)
void UIScriptsDialog::Update(const std::shared_ptr<GameWallet> &w, const std::unordered_map<std::string, cryptonote::cc_command_t> &queued_commands)
{
if (authorized_game_account == 0)
{
authorized_game_account = w->get_authorized_game_account();
gameContainer->SetValue(game->playerState.id == authorized_game_account);
}
gameContainer->SetValue(game->playerState.id == GAME_ACCOUNT);
if (last_refresh_stop_hash != game->top_hash)
{
@ -643,7 +638,7 @@ void UIScriptsDialog::Update(const std::shared_ptr<GameWallet> &w, const std::un
const bool is_script_command_pending = i != queued_commands.end();
if (is_script_command_pending)
{
listContainer->SetValue(0 || (game->debug && game->playerState.id == w->get_authorized_game_account()));
listContainer->SetValue(0 || (game->debug && game->playerState.id == GAME_ACCOUNT));
scriptContainer->SetValue(0);
waitingContainer->SetValue(1);
}

View File

@ -141,7 +141,6 @@ private:
uint32_t view_script_source;
uint32_t enable_script;
uint32_t disable_script;
uint32_t authorized_game_account;
std::map<std::string, uint64_t> script_variables;
uint32_t prev_script;

View File

@ -697,7 +697,7 @@ void UIUrho3D::UpdateCalendar()
void UIUrho3D::UpdateGameAccountOverlay(const std::shared_ptr<GameWallet> &w)
{
const bool hasAccount = gameState->playerState.has_wallet && gameState->playerState.id > 0;
game_account_overlay->SetVisible(hasAccount && gameState->playerState.id == w->get_authorized_game_account());
game_account_overlay->SetVisible(hasAccount && gameState->playerState.id == GAME_ACCOUNT);
}
void UIUrho3D::UpdateThermometer()
@ -1125,7 +1125,7 @@ void UIUrho3D::Update(float timeStep, uint32_t mouse_x, uint32_t mouse_y, uint32
ShowWidget(flagOwnerInfoButton, hasFlagSelected);
ShowWidget("gm-section", hasAccount && gameState->playerState.id == w->get_authorized_game_account());
ShowWidget("gm-section", hasAccount && gameState->playerState.id == GAME_ACCOUNT);
TBButton *chatText = command_window->GetWidgetByIDAndType<TBButton>(TBID("actions-chat"));
if (chatText)

View File

@ -350,7 +350,7 @@ class CCTest():
'teardrop owls later width skater gadget different pegs yard ahead onslaught dynamite thorn espionage dwelt rural eels aimless shipped toaster shocking rounded maverick mystery thorn',
'geek origin industrial payment friendly physics width putty beyond addicted rogue metro midst anvil unplugs tequila efficient feast elapse liquid degrees smuggled also bawled tequila',
'tidy heron aching outbreak terminal inorganic nexus umpire economics auctions hope soapy hive vigilant hunter tadpoles hippo southern observant rabbits asked vector gimmick godfather heron',
'aimless zesty juvenile hedgehog sash eden inflamed faxed abbey piloted silk gigantic affair snout guarded inquest utmost tunnel remedy sighting otherwise alley illness jubilee gigantic',
'foyer mittens gaze vocal dwindling unnoticed pimple foolish sword stacking unveil fuming husband bodies exit mugged omnibus jump whale sanity loincloth menu bite cactus vocal',
'journal vitals technical dying dice taken evicted essential pepper dented psychic vaults oatmeal pairing wrong request damp rugged buffet lids bias pouch ladder leisure rugged',
]
self.wallet = [None] * len(seeds)
@ -364,6 +364,8 @@ class CCTest():
ok = False
try: res = self.wallet[i].cc_get_info()
except: ok = True
if i == 3: # we're restoring the game account, which is pre-created
ok = not ok
assert ok
self.wallet[i].set_daemon('127.0.0.1:18182')
self.daemon = Daemon(idx = 2)
@ -385,7 +387,7 @@ class CCTest():
for data in [
['TF1MMEY5v2dN49XKNCKCdBqmTMM6GdZZA5UBbDgTewaUd3c2jDazN5yKrG1BBHX3UyPqKD9hrh3DpPTDmWiCmsuRpePT1MTaPxm', 30], # wallet[0]
['TF1MM5mG6EQkz899pz3uFDR6D2EUowvZWw75hcE6TETrodxHXSKFK6u3SRtEQzJ6epc5HD85dEgYF7xhgBtoFjMHKNFAEuGg1Lk', 500], # wallet[1]
['TF1MMCHHDFKYSQ1DkLWskTxU2fC7jtZLwcATXHP3uvJo4dV757dtGwUE9ZL6SE9DJhxrvzThAsG4drVmAPHzEvh6TCq19AbzTo4', 660], # wallet[3]
['TF1MMBerc1QPyAGKFnREmBkQZ8Ujg6ZVkdJNseCoHebyXpF4adjr8r8PfcbRrDP2LhcJ7KLZV5Efgxb7MiXwFsxw6h8eUxa8s7b', 660], # wallet[3]
['TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1000], # wallet[2]
['TF1MMA4mMyUGkR373BQYWhkssgXWPuWdSauDXiRLJEmSXiJKbw3um94tDxogJShqXHt51a8UBotBRXuMvjFjaxSumjRXDrY7wSm', 0], # wallet[4]
]:
@ -4761,7 +4763,7 @@ class CCTest():
for name in ["foo", "foO", "FOO"]:
ok = False
try:
res = self.wallet[3].cc_deposit(amount = 100000000, name = name)
res = self.wallet[4].cc_deposit(amount = 100000000, name = name)
except:
ok = True
assert ok
@ -5561,7 +5563,7 @@ class CCTest():
assert res.items_[0].id == COINS_ITEM_GROUP
assert res.items_[0].group == 0
assert res.items_[0].is_group
assert res.items_[0].amount == 5
assert res.items_[0].amount == 4
assert res.items_[0].creator == GAME_ACCOUNT
assert res.items_[0].creation_height == 0
assert res.items_[1].id == COIN_ITEM_SETTLEMENT
@ -5582,7 +5584,7 @@ class CCTest():
num_newbie_coins += res.items_[i].amount
assert res.items_[i].creator == GAME_ACCOUNT
assert res.items_[i].creation_height == 0
assert num_newbie_coins == 5
assert num_newbie_coins == 4
res = daemon.cc_get_custom_items()
n_existing_custom_items = len(res.items_)
@ -5912,6 +5914,10 @@ class CCTest():
print("Testing fire")
flag_id = 3
self.wallet[2].cc_rename_flag(flag_id, old_name = 'test:event:0', new_name = 'good name')
self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
flag_mil1_x0 = FIRST_CITY_X - 270
flag_mil1_y0 = FIRST_CITY_Y - 220
flag_mil1_x1 = flag_mil1_x0 + 32 - 1
@ -6066,6 +6072,10 @@ class CCTest():
res = daemon.cc_get_flag(flag_id)
assert res.fire_state == 0
flag_id = 3
self.wallet[2].cc_rename_flag(flag_id, old_name = 'good name', new_name = 'test:event:0')
self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
def test_derelict(self):
daemon = self.daemon
@ -6801,7 +6811,7 @@ class CCTest():
self.assert_exception(lambda: self.wallet[2].cc_script_choice(1, state = 0, city = 11, owner = GAME_ACCOUNT, choice = 0))
self.assert_exception(lambda: self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = GAME_ACCOUNT, choice = -1))
self.assert_exception(lambda: self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = GAME_ACCOUNT, choice = 11))
self.assert_exception(lambda: self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = account3_id, choice = 0))
self.assert_exception(lambda: self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = account2_id, choice = 0))
res = self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = GAME_ACCOUNT, choice = 0)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
@ -7483,6 +7493,10 @@ script {
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
# the gold goes to the script owner
expected_balances[3] += gold_content
res = daemon.cc_get_custom_items([item_id])
assert len(res.items_) == 1
expected_balances[3] += 2 * res.items_[0].gold
expected_item_balances[1] = self.add_item(expected_item_balances[1], item_id, -2)
expected_item_balances[1] = self.add_item(expected_item_balances[1], coin_id, -1)
@ -7493,7 +7507,7 @@ script {
# check balances
for i in range(4):
res = daemon.cc_get_account(account_id[i])
assert res.balance == expected_balances[i], "exp " + str(expected_balances[i]) + ', got ' + str(res.balance)
assert res.balance == expected_balances[i], "exp " + str(expected_balances[i]) + ', got ' + str(res.balance) + " for wallet " + str(i)
assert (res.item_balances if 'item_balances' in res else []) == expected_item_balances[i]
def test_background_scripts(self):

View File

@ -47,7 +47,7 @@ WALLET_DIRECTORY = builddir + "/functional-tests-directory"
FUNCTIONAL_TESTS_DIRECTORY = builddir + "/tests/functional_tests"
DIFFICULTY = 10
monerod_base = [builddir + "/bin/townforged", "--regtest", "--fixed-difficulty", str(DIFFICULTY), "--no-igd", "--p2p-bind-port", "monerod_p2p_port", "--rpc-bind-port", "monerod_rpc_port", "--zmq-rpc-bind-port", "monerod_zmq_port", "--non-interactive", "--disable-dns-checkpoints", "--check-updates", "disabled", "--rpc-ssl", "disabled", "--data-dir", "monerod_data_dir", "--log-level", "1", "--debug-allow-gm-commands-from-account", "8"]
monerod_base = [builddir + "/bin/townforged", "--regtest", "--fixed-difficulty", str(DIFFICULTY), "--no-igd", "--p2p-bind-port", "monerod_p2p_port", "--rpc-bind-port", "monerod_rpc_port", "--zmq-rpc-bind-port", "monerod_zmq_port", "--non-interactive", "--disable-dns-checkpoints", "--check-updates", "disabled", "--rpc-ssl", "disabled", "--data-dir", "monerod_data_dir", "--log-level", "1"]
monerod_extra = [
["--offline"],
["--rpc-payment-address", "TF1MM9BNc8w9fXr3hMfuj4zAcW2uwkRXmL8JmC8kusgfaxoKAzc3dWJvP3wV6q8sCR6PDUTu2u2c3vK4Pekw1A2urHw4KFzeZ2n", "--rpc-payment-difficulty", str(DIFFICULTY), "--rpc-payment-credits", "5000", "--offline"],
@ -105,6 +105,7 @@ try:
os.environ['CC_FIXED_COST_CITIES'] = "1"
if 'CC_TEST_RARE_CONDITIONS' not in os.environ:
os.environ['CC_TEST_RARE_CONDITIONS'] = "1"
os.environ['CC_USE_TEST_GAME_KEY'] = "1"
for i in range(len(command_lines)):
if False: