Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce usage of auto in line with new recommendation #9

Open
wants to merge 17 commits into
base: 2018-01-auto-devnotes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[test] Serialize CTransaction with witness by default
  • Loading branch information
sipa committed Jan 9, 2018
commit 57273f2b302949d4ca3511f703627b5d717be40c
7 changes: 5 additions & 2 deletions test/functional/p2p-fullblocktest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ def initialize(self, base_block):
self.vtx = copy.deepcopy(base_block.vtx)
self.hashMerkleRoot = self.calc_merkle_root()

def serialize(self):
def serialize(self, with_witness=False):
r = b""
r += super(CBlock, self).serialize()
r += struct.pack("<BQ", 255, len(self.vtx))
for tx in self.vtx:
r += tx.serialize()
if with_witness:
r += tx.serialize_with_witness()
else:
r += tx.serialize_without_witness()
return r

def normal_serialize(self):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/p2p-segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Calculate the virtual size of a witness block:
# (base + witness/4)
def get_virtual_size(witness_block):
base_size = len(witness_block.serialize())
base_size = len(witness_block.serialize(with_witness=False))
total_size = len(witness_block.serialize(with_witness=True))
# the "+3" is so we round up
vsize = int((3*base_size + total_size + 3)/4)
Expand Down
25 changes: 14 additions & 11 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ def serialize_with_witness(self):
r += struct.pack("<I", self.nLockTime)
return r

# Regular serialization is without witness -- must explicitly
# call serialize_with_witness to include witness data.
# Regular serialization is with witness -- must explicitly
# call serialize_without_witness to exclude witness data.
def serialize(self):
return self.serialize_without_witness()
return self.serialize_with_witness()

# Recalculate the txid (transaction hash without witness)
def rehash(self):
Expand All @@ -471,7 +471,7 @@ def calc_sha256(self, with_witness=False):

if self.sha256 is None:
self.sha256 = uint256_from_str(hash256(self.serialize_without_witness()))
self.hash = encode(hash256(self.serialize())[::-1], 'hex_codec').decode('ascii')
self.hash = encode(hash256(self.serialize_without_witness())[::-1], 'hex_codec').decode('ascii')

def is_valid(self):
self.calc_sha256()
Expand Down Expand Up @@ -568,7 +568,7 @@ def serialize(self, with_witness=False):
if with_witness:
r += ser_vector(self.vtx, "serialize_with_witness")
else:
r += ser_vector(self.vtx)
r += ser_vector(self.vtx, "serialize_without_witness")
return r

# Calculate the merkle root given a vector of transaction hashes
Expand Down Expand Up @@ -635,7 +635,7 @@ def deserialize(self, f):
self.tx = CTransaction()
self.tx.deserialize(f)

def serialize(self, with_witness=False):
def serialize(self, with_witness=True):
r = b""
r += ser_compact_size(self.index)
if with_witness:
Expand All @@ -644,6 +644,9 @@ def serialize(self, with_witness=False):
r += self.tx.serialize_without_witness()
return r

def serialize_without_witness(self):
return self.serialize(with_witness=False)

def serialize_with_witness(self):
return self.serialize(with_witness=True)

Expand Down Expand Up @@ -683,7 +686,7 @@ def serialize(self, with_witness=False):
if with_witness:
r += ser_vector(self.prefilled_txn, "serialize_with_witness")
else:
r += ser_vector(self.prefilled_txn)
r += ser_vector(self.prefilled_txn, "serialize_without_witness")
return r

def __repr__(self):
Expand Down Expand Up @@ -814,13 +817,13 @@ def deserialize(self, f):
self.blockhash = deser_uint256(f)
self.transactions = deser_vector(f, CTransaction)

def serialize(self, with_witness=False):
def serialize(self, with_witness=True):
r = b""
r += ser_uint256(self.blockhash)
if with_witness:
r += ser_vector(self.transactions, "serialize_with_witness")
else:
r += ser_vector(self.transactions)
r += ser_vector(self.transactions, "serialize_without_witness")
return r

def __repr__(self):
Expand Down Expand Up @@ -1020,7 +1023,7 @@ def deserialize(self, f):
self.block.deserialize(f)

def serialize(self):
return self.block.serialize()
return self.block.serialize(with_witness=False)

def __repr__(self):
return "msg_block(block=%s)" % (repr(self.block))
Expand Down Expand Up @@ -1291,7 +1294,7 @@ def deserialize(self, f):

def serialize(self):
r = b""
r += self.block_transactions.serialize()
r += self.block_transactions.serialize(with_witness=False)
return r

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test_framework/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def SignatureHash(script, txTo, inIdx, hashtype):
txtmp.vin = []
txtmp.vin.append(tmp)

s = txtmp.serialize()
s = txtmp.serialize_without_witness()
s += struct.pack(b"<I", hashtype)

hash = hash256(s)
Expand Down