Ejemplo n.º 1
0
 def test_generate_privkey(self):
     # generate random private key
     randomKey = generate_privkey()
     # check length
     self.assertEqual(len(randomKey), 51)
     # check leading char '8'
     self.assertEqual(randomKey[0], '8')
     # decode and verify checksum
     randomKey_bin = bytes.fromhex(b58decode(randomKey).hex())
     randomKey_bin_check = bitcoin.bin_dbl_sha256(randomKey_bin[0:-4])[0:4]
     self.assertEqual(randomKey_bin[-4:], randomKey_bin_check)
Ejemplo n.º 2
0
 def test_pubkey_to_address(self):
     # generate random private key and convert to public
     randomPubKey = bitcoin.privkey_to_pubkey(generate_privkey())
     # compute address
     randomQmcAddr = pubkey_to_address(randomPubKey)
     # check leading char 'D'
     self.assertEqual(randomQmcAddr[0], 'D')
     # decode and verify checksum
     randomQmcAddr_bin = bytes.fromhex(b58decode(randomQmcAddr).hex())
     randomQmcAddr_bin_check = bitcoin.bin_dbl_sha256(
         randomQmcAddr_bin[0:-4])[0:4]
     self.assertEqual(randomQmcAddr_bin[-4:], randomQmcAddr_bin_check)
Ejemplo n.º 3
0
    def onGenerateMNkey(self):
        printDbg("Generate MNkey pressed")
        reply = QMessageBox.Yes

        if self.ui.edt_mnPrivKey.text() != "":
            reply = self.caller.myPopUp(
                QMessageBox.Warning, "GENERATE PRIV KEY",
                "Are you sure?\nThis will overwrite current private key",
                QMessageBox.No)

        if reply == QMessageBox.No:
            return

        newkey = generate_privkey(self.isTestnet())
        self.ui.edt_mnPrivKey.setText(newkey)
Ejemplo n.º 4
0
 def test_checkQmcAddr(self):
     # Generate Valid QMC address
     pK = privkey_to_pubkey(generate_privkey())
     qmcAddr = pubkey_to_address(pK)
     # Check valid address
     self.assertTrue(checkQmcAddr(qmcAddr))
     # Check malformed address 1: change leading char
     qmcAddr2 = self.getRandomChar() + qmcAddr[1:]
     while qmcAddr2[0] == 'D':
         qmcAddr2 = self.getRandomChar() + qmcAddr[1:]
     self.assertFalse(checkQmcAddr(qmcAddr2))
     # Check malformed address 1: add random chars
     qmcAddr3 = qmcAddr
     for _ in range(10):
         qmcAddr3 += self.getRandomChar()
     self.assertFalse(checkQmcAddr(qmcAddr3))
Ejemplo n.º 5
0
 def test_compose_tx_locking_script(self):
     # check with P2PKH addresses
     # Generate Valid QMC address
     pK = privkey_to_pubkey(generate_privkey())
     qmcAddr = pubkey_to_address(pK)
     # compose TX script
     result = compose_tx_locking_script(qmcAddr)
     print(result)
     # check OP_DUP
     self.assertEqual(result[0], int('76', 16))
     # check OP_HASH160
     self.assertEqual(result[1], int('A9', 16))
     pubkey_hash = bytearray.fromhex(b58check_to_hex(qmcAddr))
     self.assertEqual(result[2], len(pubkey_hash))
     self.assertEqual(result[3:23], pubkey_hash)
     # check OP_QEUALVERIFY
     self.assertEqual(result[23], int('88', 16))
     # check OP_CHECKSIG
     self.assertEqual(result[24], int('AC', 16))