def test_immutable_tx_creation_with_mutable_parts_specified(self): tx = CTransaction( vin=[CMutableTxIn(prevout=COutPoint(hash=b'a' * 32, n=0))], vout=[CMutableTxOut(nValue=1)], witness=CMutableTxWitness( [CMutableTxInWitness(CScriptWitness([CScript([0])]))])) def check_immutable_parts(tx): self.assertTrue(tx.vin[0].is_immutable()) self.assertTrue(tx.vin[0].is_immutable()) self.assertTrue(tx.vout[0].is_immutable()) self.assertTrue(tx.wit.is_immutable()) self.assertTrue(tx.wit.vtxinwit[0].is_immutable()) check_immutable_parts(tx) # Test that if we deserialize with CTransaction, # all the parts are immutable tx = CTransaction.deserialize(tx.serialize()) check_immutable_parts(tx) # Test some parts separately, because when created via # CMutableTransaction instantiation, they are created with from_* # methods, and not directly txin = CTxIn(prevout=CMutableOutPoint(hash=b'a' * 32, n=0)) self.assertTrue(txin.prevout.is_immutable()) wit = CTxWitness((CMutableTxInWitness(), )) self.assertTrue(wit.vtxinwit[0].is_immutable())
def test_repr(self): def T(txout, expected): actual = repr(txout) self.assertEqual(actual, expected) T( CMutableTxWitness([CTxInWitness(CScriptWitness([1]))]), "CBitcoinMutableTxWitness([CBitcoinMutableTxInWitness(CScriptWitness([x('01')]))])" )
def test_repr(self) -> None: def T(txwitness: CTxWitness, expected: str) -> None: actual = repr(txwitness) self.assertEqual(actual, expected) T( CMutableTxWitness([CTxInWitness(CScriptWitness([1]))]), "CBitcoinMutableTxWitness([CBitcoinMutableTxInWitness(CScriptWitness([x('01')]))])" )
def test_clone(self): wit = CMutableTxWitness([CTxInWitness(CScriptWitness([1]))]) self.assertEqual(wit.serialize(), wit.clone().serialize())