Пример #1
0
    def testCreateTx(self):
        addrA = PyBtcAddress().createFromPrivateKey(hex_to_int('aa' * 32))
        addrB = PyBtcAddress().createFromPrivateKey(hex_to_int('bb' * 32))

        # This TxIn will be completely ignored, so it can contain garbage
        txinA = PyTxIn()
        txinA.outpoint = PyOutPoint().unserialize(hex_to_binary('00' * 36))
        txinA.binScript = hex_to_binary('99' * 4)
        txinA.intSeq = hex_to_int('ff' * 4)
        # test binary unpacker in unserialize
        testTxIn = PyTxIn().unserialize(txinA.serialize())
        self.assertEqual(txinA.getScript(), testTxIn.getScript())
        self.assertEqual(txinA.intSeq, testTxIn.intSeq)
        self.assertEqual(txinA.outpoint.txHash, testTxIn.outpoint.txHash)
        txoutA = PyTxOut()
        txoutA.value = 50 * ONE_BTC
        txoutA.binScript = '\x76\xa9\x14' + addrA.getAddr160() + '\x88\xac'
        # Test pprint
        print '\nTest pretty print PyTxIn, expect PrevTXHash all 0s'
        testTxIn.pprint()

        # test binary unpacker in unserialize
        testTxOut = PyTxOut().unserialize(txoutA.serialize())
        self.assertEqual(txoutA.getScript(), testTxOut.getScript())
        self.assertEqual(txoutA.value, testTxOut.getValue())
        # Test pprint
        print '\nTest pretty print PyTxOut'
        testTxOut.pprint()

        tx1 = PyTx()
        tx1.version = 1
        tx1.numInputs = 1
        tx1.inputs = [txinA]
        tx1.numOutputs = 1
        tx1.outputs = [txoutA]
        tx1.locktime = 0
        tx1hash = tx1.getHash()
        recipientList = tx1.makeRecipientsList()
        self.assertEqual(len(recipientList), 1)
        self.assertEqual(recipientList[0][0], 0)
        self.assertEqual(recipientList[0][1], 50 * ONE_BTC)

        self.assertEqual(tx1.getHashHex(), binary_to_hex(tx1hash))
        # Creating transaction to send coins from A to B
        tx2 = PyCreateAndSignTx_old([[addrA, tx1, 0]], [[addrB, 50 * ONE_BTC]])
        psp = PyScriptProcessor()
        psp.setTxObjects(tx1, tx2, 0)
        self.assertTrue(psp.verifyTransactionValid())
Пример #2
0
   def testCreateTx(self):
      addrA = PyBtcAddress().createFromPrivateKey(hex_to_int('aa' * 32))
      addrB = PyBtcAddress().createFromPrivateKey(hex_to_int('bb' * 32)) 

      # This TxIn will be completely ignored, so it can contain garbage
      txinA = PyTxIn()
      txinA.outpoint  = PyOutPoint().unserialize(hex_to_binary('00'*36))
      txinA.binScript = hex_to_binary('99'*4)
      txinA.intSeq  = hex_to_int('ff'*4)
      # test binary unpacker in unserialize
      testTxIn = PyTxIn().unserialize(txinA.serialize())
      self.assertEqual(txinA.getScript(), testTxIn.getScript())
      self.assertEqual(txinA.intSeq, testTxIn.intSeq)
      self.assertEqual(txinA.outpoint.txHash, testTxIn.outpoint.txHash)
      txoutA = PyTxOut()
      txoutA.value = 50 * ONE_BTC
      txoutA.binScript = '\x76\xa9\x14' + addrA.getAddr160() + '\x88\xac'
      # Test pprint
      print '\nTest pretty print PyTxIn, expect PrevTXHash all 0s'
      testTxIn.pprint()
   
      # test binary unpacker in unserialize
      testTxOut = PyTxOut().unserialize(txoutA.serialize())
      self.assertEqual(txoutA.getScript(), testTxOut.getScript())
      self.assertEqual(txoutA.value, testTxOut.getValue())
      # Test pprint
      print '\nTest pretty print PyTxOut'
      testTxOut.pprint()
      
      tx1 = PyTx()
      tx1.version    = 1
      tx1.numInputs  = 1
      tx1.inputs     = [txinA]
      tx1.numOutputs = 1
      tx1.outputs    = [txoutA]
      tx1.locktime   = 0
      tx1hash = tx1.getHash()
      recipientList = tx1.makeRecipientsList()
      self.assertEqual(len(recipientList), 1)
      self.assertEqual(recipientList[0][0], 0)
      self.assertEqual(recipientList[0][1], 50 * ONE_BTC)
      
      self.assertEqual(tx1.getHashHex(), binary_to_hex(tx1hash))
      # Creating transaction to send coins from A to B
      tx2 = PyCreateAndSignTx_old( [[ addrA, tx1, 0 ]],  [[addrB, 50*ONE_BTC]])
      psp = PyScriptProcessor()
      psp.setTxObjects(tx1, tx2, 0)
      self.assertTrue(psp.verifyTransactionValid())
 def testGetrawtransaction(self):
    actualRawTx = self.jsonServer.jsonrpc_getrawtransaction(TX_ID1)
    pyTx = PyTx().unserialize(hex_to_binary(actualRawTx))
    self.assertEquals(TX_ID1, binary_to_hex(pyTx.getHash(), BIGENDIAN))
Пример #4
0
 def testGetrawtransaction(self):
     actualRawTx = self.jsonServer.jsonrpc_getrawtransaction(TX_ID1)
     pyTx = PyTx().unserialize(hex_to_binary(actualRawTx))
     self.assertEquals(TX_ID1, binary_to_hex(pyTx.getHash(), BIGENDIAN))