Skip to content

Commit

Permalink
Merge branch 'master' of github.com:summa-tx/riemann
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Jun 15, 2018
2 parents 220986c + 2e05db2 commit 785d01c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
5 changes: 2 additions & 3 deletions riemann/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ def empty_outpoint():
tree=b'\x00')


def unsigned_input(outpoint, redeem_script=b'', sequence=None):
def unsigned_input(outpoint, redeem_script=None, sequence=None):
'''
Outpoint, byte-like, int -> TxIn
'''
if redeem_script != b'' and sequence is None:
if redeem_script is not None and sequence is None:
sequence = guess_sequence(redeem_script)
redeem_script = script_ser.serialize(redeem_script)
if sequence is None:
sequence = 0xFFFFFFFE
return tb.make_legacy_input(
Expand Down
30 changes: 28 additions & 2 deletions riemann/tests/tx/test_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ def test_everything(self):

self.assertEqual(res, helpers.RAW_P2SH_TO_P2PKH)

# TODO: Break up this monstrosity
def test_create_tx(self):
# TODO: Break up this monstrosity (further)
def test_tx_witness(self):
t = tx.Tx(self.version, self.none_flag, self.tx_ins, self.tx_outs,
self.none_witnesses, self.lock_time)

Expand Down Expand Up @@ -595,6 +595,12 @@ def test_create_tx(self):
'Invalid InputWitness. Expected instance of InputWitness.',
str(context.exception))

def test_tx_inandout(self):
t = tx.Tx(self.version, self.none_flag, self.tx_ins, self.tx_outs,
self.none_witnesses, self.lock_time)

self.assertEqual(t, helpers.P2PKH1['ser']['tx']['signed'])

with self.assertRaises(ValueError) as context:
tx_ins = [self.tx_ins[0] for _ in range(257)]
tx.Tx(self.version, self.none_flag, tx_ins, self.tx_outs,
Expand Down Expand Up @@ -647,6 +653,16 @@ def test_create_tx(self):
'Tx is too large. Expect less than 100kB. Got: ',
str(context.exception))

def test_tx_inout_mutation(self):
t = tx.Tx(self.version, self.none_flag, self.tx_ins, self.tx_outs,
self.none_witnesses, self.lock_time)

with self.assertRaises(TypeError, msg='That\'s immutable, honey'):
t.tx_ins = t.tx_ins + (1,)

with self.assertRaises(TypeError, msg='That\'s immutable, honey'):
t.tx_outs = t.tx_outs + (1,)

def test_tx_id(self):
t = tx.Tx(self.version, self.none_flag, self.tx_ins, self.tx_outs,
self.none_witnesses, self.lock_time)
Expand Down Expand Up @@ -724,6 +740,16 @@ def test_copy(self):
self.assertEqual(t, t_copy)
self.assertIsNot(t, t_copy)

def test_is_witness(self):
t = tx.Tx(self.version, self.none_flag, self.tx_ins, self.tx_outs,
self.none_witnesses, self.lock_time)

self.assertFalse(t.is_witness())

t = tx.Tx.from_bytes(helpers.P2WSH['ser']['tx']['signed'])

self.assertTrue(t.is_witness())

def test_sighash_all(self):
t = tx.Tx(self.version, self.none_flag, self.tx_ins, self.tx_outs,
self.none_witnesses, self.lock_time)
Expand Down
3 changes: 3 additions & 0 deletions riemann/tx/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ def no_witness(self):
tx += self.lock_time
return bytes(tx)

def is_witness(self):
return self.flag is not None

def calculate_fee(self, input_values):
'''
Tx, list(int) -> int
Expand Down

0 comments on commit 785d01c

Please sign in to comment.