示例#1
0
 def test_setconfig_non_auth_boolean(self):
     self.assertEqual(
         True,
         Commands._setconfig_normalize_value('show_console_tab', "true"))
     self.assertEqual(
         True,
         Commands._setconfig_normalize_value('show_console_tab', "True"))
示例#2
0
 def test_setconfig_non_auth_number(self):
     self.assertEqual(
         7777, Commands._setconfig_normalize_value('rpcport', "7777"))
     self.assertEqual(
         7777, Commands._setconfig_normalize_value('rpcport', '7777'))
     self.assertAlmostEqual(
         Decimal(2.3),
         Commands._setconfig_normalize_value('somekey', '2.3'))
示例#3
0
 def test_setconfig_non_auth_list(self):
     self.assertEqual(['file:///var/www/', 'https://electrum.org'],
                      Commands._setconfig_normalize_value(
                          'url_rewrite',
                          "['file:///var/www/','https://electrum.org']"))
     self.assertEqual(['file:///var/www/', 'https://electrum.org'],
                      Commands._setconfig_normalize_value(
                          'url_rewrite',
                          '["file:///var/www/","https://electrum.org"]'))
示例#4
0
 def test_setconfig_auth(self):
     self.assertEqual(
         "7777", Commands._setconfig_normalize_value('rpcuser', "7777"))
     self.assertEqual(
         "7777", Commands._setconfig_normalize_value('rpcuser', '7777'))
     self.assertEqual(
         "7777", Commands._setconfig_normalize_value('rpcpassword', '7777'))
     self.assertEqual(
         "2asd", Commands._setconfig_normalize_value('rpcpassword', '2asd'))
     self.assertEqual(
         "['file:///var/www/','https://electrum.org']",
         Commands._setconfig_normalize_value(
             'rpcpassword', "['file:///var/www/','https://electrum.org']"))
示例#5
0
    def test_createmultisig(self):
        c = Commands(None, None, None)
        pubkeys = [
            "03b25918969e43702abeb6a60942e72e3a3c603dfd272de59e7679a52f35527ccf",
            "0383cf538b41dbba7b7ee57a53bc673fef8a6896734ae587032f755ac0cba86cc2"
        ]

        result = c.createmultisig(2, pubkeys)
        result_rev = c.createmultisig(2, list(reversed(pubkeys)))
        assert result == result_rev
        assert result == {
            "address":
            "3AiUfSRMbvXzyAHhFoFAtVFibWPdkNV9DW",
            "redeemScript":
            ("52210383cf538b41dbba7b7ee57a53bc673fef8a6896734ae587032f755ac0cba86c"
             "c22103b25918969e43702abeb6a60942e72e3a3c603dfd272de59e7679a52f35527ccf52ae"
             )
        }
示例#6
0
def run_offline_command(config, config_options):
    cmdname = config.get('cmd')
    cmd = known_commands[cmdname]
    password = config_options.get('password')
    if cmd.requires_wallet:
        wallet_path = config.get_wallet_path()
        if not WalletStorage.files_are_matched_by_path(wallet_path):
            print("Error: wallet does not exist at given path")
            sys.exit(1)
        storage = WalletStorage(wallet_path)
        if storage.is_encrypted():
            storage.decrypt(password)
        parent_wallet = ParentWallet(storage)
    else:
        parent_wallet = None
    # check password
    if cmd.requires_password and parent_wallet.has_password():
        try:
            parent_wallet.check_password(password)
        except InvalidPassword:
            print("Error: This password does not decode this wallet.")
            sys.exit(1)
    if cmd.requires_network:
        print("Warning: running command offline")
    # arguments passed to function
    args = [config.get(x) for x in cmd.params]
    # decode json arguments
    if cmdname not in ('setconfig', ):
        args = [json_decode(arg) for arg in args]
    # options
    kwargs = {}
    for x in cmd.options:
        kwargs[x] = (config_options.get(x)
                     if x in ['password', 'new_password'] else config.get(x))
    cmd_runner = Commands(config, parent_wallet, None)
    func = getattr(cmd_runner, cmd.name)
    result = func(*args, **kwargs)
    # save wallet
    if parent_wallet:
        parent_wallet.save_storage()
    return result
示例#7
0
def run_offline_command(config, config_options):
    cmdname = config.get('cmd')
    cmd = known_commands[cmdname]
    password = config_options.get('password')
    if cmd.requires_wallet:
        wallet_path = config.get_cmdline_wallet_filepath()
        if not WalletStorage.files_are_matched_by_path(wallet_path):
            print("Error: wallet does not exist at given path")
            sys.exit(1)
        storage = WalletStorage(wallet_path)
        wallet = Wallet(storage)
    else:
        wallet = None
    if cmd.requires_password:
        try:
            wallet.check_password(password)
        except (InvalidPassword, IncompatibleWalletError):
            print(
                "Error: This password cannot access the wallet's private data."
            )
            sys.exit(1)
    if cmd.requires_network:
        print("Warning: running command offline")
    # arguments passed to function
    args = [config.get(x) for x in cmd.params]
    # decode json arguments
    if cmdname not in ('setconfig', ):
        args = [json_decode(arg) for arg in args]
    # options
    kwargs = {}
    for x in cmd.options:
        kwargs[x] = (config_options.get(x)
                     if x in ['password', 'new_password'] else config.get(x))
    cmd_runner = Commands(config, wallet, None)
    func = getattr(cmd_runner, cmd.name)
    result = func(*args, **kwargs)
    # save wallet
    if wallet:
        wallet.save_storage()
    return result
示例#8
0
 def test_verifymessage(self):
     c = Commands(None, None, None)
     message = 'Hello'
     signature = privkey.sign_message_to_base64(message)
     address = privkey.public_key.to_address()
     assert c.verifymessage(address, signature, message)
示例#9
0
 def test_encrypt(self):
     c = Commands(None, None, None)
     msg = 'BitcoinSV'
     enc_msg = c.encrypt(pubkey_hex, msg)
     assert privkey.decrypt_message(enc_msg).decode() == msg
示例#10
0
 def test_setconfig_non_auth_number_as_string(self):
     self.assertEqual(
         "7777", Commands._setconfig_normalize_value('somekey', "'7777'"))