Skip to content

Commit

Permalink
add snowflakes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Jun 23, 2018
1 parent d1dccfd commit d24a5b6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
7 changes: 6 additions & 1 deletion riemann/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ def guess_version(redeem_script):
We want to signal nSequence if we're using OP_CSV.
Unless we're in zcash.
'''
if 'zcash' in riemann.get_current_network_name():
n = riemann.get_current_network_name()
if 'sprout' in n:
return 1
if 'overwinter' in n:
return 3
if 'sapling' in n:
return 4
try:
script_array = redeem_script.split()
script_array.index('OP_CHECKSEQUENCEVERIFY')
Expand Down
10 changes: 10 additions & 0 deletions riemann/tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def test_guess_version(self):
simple.guess_version('OP_IF'),
1)

riemann.select_network('zcash_overwinter_main')
self.assertEqual(
simple.guess_version('OP_IF'),
3)

riemann.select_network('zcash_sapling_main')
self.assertEqual(
simple.guess_version('OP_IF'),
4)

def test_guess_sequence(self):
self.assertEqual(
simple.guess_sequence('OP_IF'),
Expand Down
23 changes: 21 additions & 2 deletions riemann/tests/tx/test_tx_builder.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest
import riemann
from .. import helpers
from ...tx import tx_builder as tb
from unittest import mock
from riemann.tests import helpers
from riemann.tx import tx_builder as tb


class TestTxBuilder(unittest.TestCase):
Expand Down Expand Up @@ -279,3 +280,21 @@ def test_length_prepend(self):
self.assertEqual(
tb.length_prepend(b'\x00' * 256),
b'\xfd\x00\x01' + b'\x00' * 256)

@mock.patch('riemann.tx.tx_builder.tx')
def test_sprout_snowflake(self, mock_tx):
# TODO: Improve
riemann.select_network('zcash_sprout_main')
mock_tx.SproutTx.return_value = 0
self.assertEqual(
tb.make_tx(0, 0, 0, 0, tx_joinsplits=[]),
0)

@mock.patch('riemann.tx.tx_builder.tx')
def test_overwinter_snowflake(self, mock_tx):
# TODO: Improve
riemann.select_network('zcash_overwinter_main')
mock_tx.OverwinterTx.return_value = 0
self.assertEqual(
tb.make_tx(0, 0, 0, 0, expiry=0),
0)
38 changes: 29 additions & 9 deletions riemann/tx/tx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,38 @@ def make_witness_input_and_witness(outpoint, sequence,


def make_tx(version, tx_ins, tx_outs, lock_time,
expiry=None, tx_witnesses=None):

expiry=None, tx_witnesses=None,
tx_joinsplits=None, joinsplit_pubkey=None, joinsplit_sig=None):
'''
int, list(TxIn), list(TxOut), int, list(InputWitness) -> Tx
'''
if 'decred' in riemann.get_current_network_name():
return tx.DecredTx(version=utils.i2le_padded(version, 4),
tx_ins=tx_ins,
tx_outs=tx_outs,
lock_time=utils.i2le_padded(lock_time, 4),
expiry=utils.i2le_padded(expiry, 4),
tx_witnesses=[tx_witnesses])
n = riemann.get_current_network_name()
if 'decred' in n:
return tx.DecredTx(
version=utils.i2le_padded(version, 4),
tx_ins=tx_ins,
tx_outs=tx_outs,
lock_time=utils.i2le_padded(lock_time, 4),
expiry=utils.i2le_padded(expiry, 4),
tx_witnesses=[tx_witnesses])
if 'sprout' in n and tx_joinsplits is not None:
return tx.SproutTx(
version=version,
tx_ins=tx_ins,
tx_outs=tx_outs,
lock_time=utils.i2le_padded(lock_time, 4),
tx_joinsplits=tx_joinsplits,
joinsplit_pubkey=joinsplit_pubkey,
joinsplit_sig=joinsplit_sig)
if 'overwinter' in n:
return tx.OverwinterTx(
tx_ins=tx_ins,
tx_outs=tx_outs,
lock_time=utils.i2le_padded(lock_time, 4),
expiry_height=utils.i2le_padded(expiry, 4),
tx_joinsplits=tx_joinsplits,
joinsplit_pubkey=joinsplit_pubkey,
joinsplit_sig=joinsplit_sig)
flag = riemann.network.SEGWIT_TX_FLAG \
if tx_witnesses is not None else None
return tx.Tx(version=utils.i2le_padded(version, 4),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='riemann-tx',
version='0.10.3',
version='1.0.0',
description=('Transaction creation library for Bitcoin-like coins'),
url='https://github.com/summa-tx/riemann',
author='James Prestwich',
Expand Down

0 comments on commit d24a5b6

Please sign in to comment.