Fix Rand.u8() to return unsigned integers
Existing test vector generators are adjusted to use Rand.i8() so they generate the same test vectors. We should evaluate these later to determine whether they should actually use Rand.u8() (and update the test vectors across the ecosystem).
This commit is contained in:
parent
10bdd6c5f8
commit
c6cd47a5dd
|
@ -155,7 +155,7 @@ RAND_OPCODES = [
|
|||
class Script(object):
|
||||
def __init__(self, rand):
|
||||
self._script = bytes([
|
||||
rand.a(RAND_OPCODES) for i in range(rand.u8() % 10)
|
||||
rand.a(RAND_OPCODES) for i in range(rand.i8() % 10)
|
||||
])
|
||||
|
||||
def raw(self):
|
||||
|
@ -212,11 +212,11 @@ class Transaction(object):
|
|||
self.nVersion = rand.u32() & ((1 << 31) - 1)
|
||||
|
||||
self.vin = []
|
||||
for i in range(rand.u8() % 3):
|
||||
for i in range(rand.i8() % 3):
|
||||
self.vin.append(TxIn(rand))
|
||||
|
||||
self.vout = []
|
||||
for i in range(rand.u8() % 3):
|
||||
for i in range(rand.i8() % 3):
|
||||
self.vout.append(TxOut(rand))
|
||||
|
||||
self.nLockTime = rand.u32()
|
||||
|
@ -227,14 +227,14 @@ class Transaction(object):
|
|||
self.vShieldedSpends = []
|
||||
self.vShieldedOutputs = []
|
||||
if self.nVersion >= SAPLING_TX_VERSION:
|
||||
for _ in range(rand.u8() % 5):
|
||||
for _ in range(rand.i8() % 5):
|
||||
self.vShieldedSpends.append(SpendDescription(rand))
|
||||
for _ in range(rand.u8() % 5):
|
||||
for _ in range(rand.i8() % 5):
|
||||
self.vShieldedOutputs.append(OutputDescription(rand))
|
||||
|
||||
self.vJoinSplit = []
|
||||
if self.nVersion >= 2:
|
||||
for i in range(rand.u8() % 3):
|
||||
for i in range(rand.i8() % 3):
|
||||
self.vJoinSplit.append(JoinSplit(rand, self.fOverwintered and self.nVersion >= SAPLING_TX_VERSION))
|
||||
if len(self.vJoinSplit) > 0:
|
||||
self.joinSplitPubKey = rand.b(32) # Potentially invalid
|
||||
|
|
|
@ -12,9 +12,12 @@ class Rand(object):
|
|||
def v(self, l, f):
|
||||
return struct.unpack(f, self.b(l))[0]
|
||||
|
||||
def u8(self):
|
||||
def i8(self):
|
||||
return self.v(1, 'b')
|
||||
|
||||
def u8(self):
|
||||
return self.v(1, 'B')
|
||||
|
||||
def u32(self):
|
||||
return self.v(4, '<I')
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ def main():
|
|||
for i in range(10):
|
||||
tx = Transaction(rand, OVERWINTER_TX_VERSION)
|
||||
scriptCode = Script(rand)
|
||||
nIn = rand.u8() % (len(tx.vin) + 1)
|
||||
nIn = rand.i8() % (len(tx.vin) + 1)
|
||||
if nIn == len(tx.vin):
|
||||
nIn = NOT_AN_INPUT
|
||||
nHashType = SIGHASH_ALL if nIn == NOT_AN_INPUT else rand.a([
|
||||
|
|
|
@ -120,7 +120,7 @@ def main():
|
|||
for _ in range(10):
|
||||
tx = Transaction(rand, SAPLING_TX_VERSION)
|
||||
scriptCode = Script(rand)
|
||||
nIn = rand.u8() % (len(tx.vin) + 1)
|
||||
nIn = rand.i8() % (len(tx.vin) + 1)
|
||||
if nIn == len(tx.vin):
|
||||
nIn = NOT_AN_INPUT
|
||||
nHashType = SIGHASH_ALL if nIn == NOT_AN_INPUT else rand.a([
|
||||
|
|
Loading…
Reference in New Issue