Exemplo n.º 1
0
 def run_recover(self, seed):
     try:
         testlog = open('test_recover', 'wb')
         p = pexpect.spawn('python wallet-tool.py recover', logfile=testlog)
         expected = [
             'Input 12 word recovery seed',
             'Enter wallet encryption passphrase:',
             'Reenter wallet encryption passphrase:',
             'Input wallet file name'
         ]
         test_in = [seed, 'abc123', 'abc123', 'test_recover_wallet.json']
         interact(p, test_in, expected)
         p.expect('saved to')
         time.sleep(1)
         p.close()
         testlog.close()
         #anything to check in the log?
         with open(os.path.join('test_recover')) as f:
             print f.read()
         if p.exitstatus != 0:
             print 'failed due to exit status: ' + str(p.exitstatus)
             return False
         #check the wallet exists (and contains appropriate json? todo)
         if not os.path.isfile('wallets/test_recover_wallet.json'):
             print 'failed due to wallet missing'
             return False
         os.remove('wallets/test_recover_wallet.json')
     except:
         return False
     return True
Exemplo n.º 2
0
def setup_import(mainnet=True):
    try:
        os.remove("wallets/test_import_wallet.json")
    except:
        pass
    if mainnet:
        jm_single().config.set("BLOCKCHAIN", "network", "mainnet")
    pwd = 'import-pwd'
    test_in = [pwd, pwd, 'test_import_wallet.json']
    expected = [
        'Enter wallet encryption passphrase:',
        'Reenter wallet encryption passphrase:', 'Input wallet file name'
    ]
    testlog = open('test/testlog-' + pwd, 'wb')
    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)
    p.close()
    testlog.close()
    #anything to check in the log?
    with open(os.path.join('test', 'testlog-' + pwd)) as f:
        print f.read()
    if p.exitstatus != 0:
        raise Exception('failed due to exit status: ' + str(p.exitstatus))
    jm_single().config.set("BLOCKCHAIN", "network", "testnet")
Exemplo n.º 3
0
 def run_generate(self, pwd):
     try:
         test_in = [pwd, pwd, 'testwallet.json']
         expected = [
             'Enter wallet encryption passphrase:',
             'Reenter wallet encryption passphrase:',
             'Input wallet file name'
         ]
         testlog = open('test/testlog-' + pwd, 'wb')
         p = pexpect.spawn('python wallet-tool.py generate',
                           logfile=testlog)
         interact(p, test_in, expected)
         p.expect('saved to')
         time.sleep(1)
         p.close()
         testlog.close()
         #anything to check in the log?
         with open(os.path.join('test', 'testlog-' + pwd)) as f:
             print f.read()
         if p.exitstatus != 0:
             print 'failed due to exit status: ' + str(p.exitstatus)
             print 'signal status is: ' + str(p.signalstatus)
             return False
         #check the wallet exists (and contains appropriate json?)
         if not os.path.isfile('wallets/testwallet.json'):
             print 'failed due to wallet missing'
             return False
         os.remove('wallets/testwallet.json')
     except:
         return False
     return True
Exemplo n.º 4
0
def setup_import(mainnet=True):
    try:
        os.remove("wallets/test_import_wallet.json")
    except:
        pass
    if mainnet:
        jm_single().config.set("BLOCKCHAIN", "network", "mainnet")
    pwd = 'import-pwd'
    test_in = [pwd, pwd, 'test_import_wallet.json']
    expected = ['Enter wallet encryption passphrase:',
                'Reenter wallet encryption passphrase:',
                'Input wallet file name']
    testlog = open('test/testlog-' + pwd, 'wb')
    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)
    p.close()
    testlog.close()
    #anything to check in the log?
    with open(os.path.join('test', 'testlog-' + pwd)) as f:
        print f.read()
    if p.exitstatus != 0:
        raise Exception('failed due to exit status: ' + str(p.exitstatus))
    jm_single().config.set("BLOCKCHAIN", "network", "testnet")
Exemplo n.º 5
0
 def run_recover(self, seed):
     try:
         testlog = open('test_recover', 'wb')
         p = pexpect.spawn('python wallet-tool.py recover', logfile=testlog)
         expected = ['Input 12 word recovery seed',
                     'Enter wallet encryption passphrase:',
                     'Reenter wallet encryption passphrase:',
                     'Input wallet file name']
         test_in = [seed, 'abc123', 'abc123', 'test_recover_wallet.json']
         interact(p, test_in, expected)
         p.expect('saved to')
         time.sleep(1)
         p.close()
         testlog.close()
         #anything to check in the log?
         with open(os.path.join('test_recover')) as f:
             print f.read()
         if p.exitstatus != 0:
             print 'failed due to exit status: ' + str(p.exitstatus)
             return False
         #check the wallet exists (and contains appropriate json? todo)
         if not os.path.isfile('wallets/test_recover_wallet.json'):
             print 'failed due to wallet missing'
             return False
         os.remove('wallets/test_recover_wallet.json')
     except:
         return False
     return True
Exemplo n.º 6
0
 def run_generate(self, pwd):
     try:
         test_in = [pwd, pwd, 'testwallet.json']
         expected = ['Enter wallet encryption passphrase:',
                     'Reenter wallet encryption passphrase:',
                     'Input wallet file name']
         testlog = open('test/testlog-' + pwd, 'wb')
         p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
         interact(p, test_in, expected)
         p.expect('saved to')
         time.sleep(1)
         p.close()
         testlog.close()
         #anything to check in the log?
         with open(os.path.join('test', 'testlog-' + pwd)) as f:
             print f.read()
         if p.exitstatus != 0:
             print 'failed due to exit status: ' + str(p.exitstatus)
             print 'signal status is: ' + str(p.signalstatus)
             return False
         #check the wallet exists (and contains appropriate json?)
         if not os.path.isfile('wallets/testwallet.json'):
             print 'failed due to wallet missing'
             return False
         os.remove('wallets/testwallet.json')
     except:
         return False
     return True
Exemplo n.º 7
0
def test_import_privkey(setup_wallets, setup_import, pwd, in_privs):
    """This tests successful import of WIF compressed private keys
    into the wallet for mainnet.
    """
    test_in = [pwd, ' '.join(in_privs)]
    expected = ['Enter wallet decryption passphrase:',
                'to import:']
    testlog = open('test/testlog-' + pwd, 'wb')
    p = pexpect.spawn('python wallet-tool.py test_import_wallet.json importprivkey',
                      logfile=testlog)
    interact(p, test_in, expected)
    #p.expect('Private key(s) successfully imported')
    #time.sleep(1)
    #p.close()
    testlog.close()
Exemplo n.º 8
0
def test_change_passphrase(setup_wallets, pwd, new_pwd, expected_output):
    """This tests successfully changing the passphrase for wallets
    using wallet-tool.py, to ensure it works it also changes the password
    back to what it was originally
    """
    setup_import()

    test_in = [pwd, new_pwd, new_pwd]
    testlog = open('test/testlog-' + new_pwd, 'wb')
    p = pexpect.spawn('python wallet-tool.py test_import_wallet.json changepassphrase', logfile=testlog)
    interact(p, test_in, expected_output)
    p.expect(': passphrase has been updated')

    test_in = [new_pwd, pwd, pwd]
    p = pexpect.spawn('python wallet-tool.py test_import_wallet.json changepassphrase', logfile=testlog)
    interact(p, test_in, expected_output)
    p.expect(': passphrase has been updated')
    time.sleep(1)
    p.close()
    testlog.close()
Exemplo n.º 9
0
def test_change_passphrase(setup_wallets, pwd, new_pwd, expected_output):
    """This tests successfully changing the passphrase for wallets
    using wallet-tool.py, to ensure it works it also changes the password
    back to what it was originally
    """
    setup_import()

    test_in = [pwd, new_pwd, new_pwd]
    testlog = open('test/testlog-' + new_pwd, 'wb')
    p = pexpect.spawn(
        'python wallet-tool.py test_import_wallet.json changepassphrase',
        logfile=testlog)
    interact(p, test_in, expected_output)
    p.expect(': passphrase has been updated')

    test_in = [new_pwd, pwd, pwd]
    p = pexpect.spawn(
        'python wallet-tool.py test_import_wallet.json changepassphrase',
        logfile=testlog)
    interact(p, test_in, expected_output)
    p.expect(': passphrase has been updated')
    time.sleep(1)
    p.close()
    testlog.close()
Exemplo n.º 10
0
    def run_tumble(self, amt):
        yigen_procs = []
        for i in range(6):
            ygp = local_command([python_cmd, yg_cmd,\
                                 str(self.wallets[i]['seed'])], bg=True)
            time.sleep(2)  #give it a chance
            yigen_procs.append(ygp)

#A significant delay is needed to wait for the yield generators to sync
        time.sleep(60)

        #start a tumbler
        amt = amt * 1e8  #in satoshis
        #send to any old address
        dest_address = btc.privkey_to_address(os.urandom(32), get_p2pk_vbyte())
        try:
            #default mixdepth source is zero, so will take coins from m 0.
            #see tumbler.py --h for details
            expected = ['tumble with these tx']
            test_in = ['y']
            p = pexpect.spawn(python_cmd,
                              ['tumbler.py', '-N', '2', '0', '-a', '0', '-M',
                               '5', '-w', '10', '-l', '0.2', '-s', '1000000',
                               '-q', '5', self.wallets[6]['seed'], dest_address])
            interact(p, test_in, expected)
            p.expect(pexpect.EOF, timeout=100000)
            p.close()
            if p.exitstatus != 0:
                print 'failed due to exit status: ' + str(p.exitstatus)
                return False
        except subprocess.CalledProcessError, e:
            for ygp in yigen_procs:
                ygp.kill()
            print e.returncode
            print e.message
            raise
Exemplo n.º 11
0
def test_multiple_default_wallets(mainnet=True):
    """ This creates three wallets in succession without naming them. creates
    wallet.json, wallet1.json, wallet2.json etc.
    """
    # Wasn't sure if it was a good idea to check and remove before starting,
    # probably not
    # I wouldn't want someone to run tests and then delete their wallets
    # unknowingly
    #   try:
    #       os.remove("wallets/wallet.json")
    #       os.remove("wallets/wallet.json")
    #       os.remove("wallets/wallet.json")
    #   except:
    #       pass

    pwd = 'import-pwd'
    test_in = [pwd, pwd, '']
    expected = [
        'Enter wallet encryption passphrase:',
        'Reenter wallet encryption passphrase:', 'Input wallet file name'
    ]
    testlog = open('test/testlog-generate-multiple-default-wallets', 'wb')

    test_in = [pwd, pwd, '']
    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)

    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)

    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)

    p.close()
    testlog.close()
Exemplo n.º 12
0
def test_multiple_default_wallets(mainnet=True):
    """ This creates three wallets in succession without naming them. creates
    wallet.json, wallet1.json, wallet2.json etc.
    """
# Wasn't sure if it was a good idea to check and remove before starting,
# probably not
# I wouldn't want someone to run tests and then delete their wallets
# unknowingly
#   try:
#       os.remove("wallets/wallet.json")
#       os.remove("wallets/wallet.json")
#       os.remove("wallets/wallet.json")
#   except:
#       pass

    pwd = 'import-pwd'
    test_in = [pwd, pwd, '']
    expected = ['Enter wallet encryption passphrase:',
                'Reenter wallet encryption passphrase:',
                'Input wallet file name']
    testlog = open('test/testlog-generate-multiple-default-wallets', 'wb')

    test_in = [pwd, pwd, '']
    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)

    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)

    p = pexpect.spawn('python wallet-tool.py generate', logfile=testlog)
    interact(p, test_in, expected)
    p.expect('saved to')
    time.sleep(1)

    p.close()
    testlog.close()