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 testPPrintPyOutPoint(self): # No return value - Should just print 0s outpoint = PyOutPoint().unserialize(BinaryUnpacker(ALL_ZERO_OUTPOINT)) print "PyOutPoint PPrint Test. Expect all 0s: " outpoint.pprint()
def testCopyPyOutPoint(self): outpoint = PyOutPoint().unserialize(BinaryUnpacker(ALL_ZERO_OUTPOINT)) outpointCopy = outpoint.copy() self.assertEqual(outpoint.txHash, outpointCopy.txHash) self.assertEqual(outpoint.txOutIndex, outpointCopy.txOutIndex)
def testUnpackUnserializePyOutPoint(self): outpoint = PyOutPoint().unserialize(BinaryUnpacker(ALL_ZERO_OUTPOINT)) self.assertEqual(outpoint.txHash, hex_to_binary('00' * 32)) self.assertEqual(outpoint.txOutIndex, 0)