mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
requested changes
This commit is contained in:
parent
411d1963bb
commit
1d99d6e8a8
@ -77,7 +77,7 @@ class Bigchain(object):
|
||||
federation = property(lambda self: set(self.nodes_except_me + [self.me]))
|
||||
""" Set of federation member public keys """
|
||||
|
||||
def write_transaction(self, signed_transaction, **kwargs):
|
||||
def write_transaction(self, signed_transaction):
|
||||
"""Write the transaction to bigchain.
|
||||
|
||||
When first writing a transaction to the bigchain the transaction will be kept in a backlog until
|
||||
|
@ -19,21 +19,21 @@ logger = logging.getLogger(__name__)
|
||||
TENDERMINT_HOST = getenv('TENDERMINT_HOST', 'localhost')
|
||||
TENDERMINT_PORT = getenv('TENDERMINT_PORT', '46657')
|
||||
ENDPOINT = 'http://{}:{}/'.format(TENDERMINT_HOST, TENDERMINT_PORT)
|
||||
MODE_LIST = ('broadcast_tx_async',
|
||||
'broadcast_tx_sync',
|
||||
'broadcast_tx_commit')
|
||||
|
||||
|
||||
class BigchainDB(Bigchain):
|
||||
|
||||
def post_transaction(self, transaction, mode):
|
||||
"""Submit a valid transaction to the mempool."""
|
||||
mode_list = ('broadcast_tx_async',
|
||||
'broadcast_tx_sync',
|
||||
'broadcast_tx_commit')
|
||||
if not mode or mode['mode'] not in mode_list:
|
||||
if not mode or mode not in MODE_LIST:
|
||||
raise ValidationError(('Mode must be one of the following {}.')
|
||||
.format(', '.join(mode_list)))
|
||||
.format(', '.join(MODE_LIST)))
|
||||
|
||||
payload = {
|
||||
'method': mode['mode'],
|
||||
'method': mode,
|
||||
'jsonrpc': '2.0',
|
||||
'params': [encode_transaction(transaction.to_dict())],
|
||||
'id': str(uuid4())
|
||||
@ -41,7 +41,7 @@ class BigchainDB(Bigchain):
|
||||
# TODO: handle connection errors!
|
||||
requests.post(ENDPOINT, json=payload)
|
||||
|
||||
def write_transaction(self, transaction, **mode):
|
||||
def write_transaction(self, transaction, mode):
|
||||
# This method offers backward compatibility with the Web API.
|
||||
"""Submit a valid transaction to the mempool."""
|
||||
self.post_transaction(transaction, mode)
|
||||
|
@ -59,6 +59,7 @@ class TransactionListApi(Resource):
|
||||
parser.add_argument('mode', type=parameters.valid_mode,
|
||||
default='broadcast_tx_async')
|
||||
args = parser.parse_args()
|
||||
mode = str(args['mode'])
|
||||
|
||||
pool = current_app.config['bigchain_pool']
|
||||
|
||||
@ -90,7 +91,7 @@ class TransactionListApi(Resource):
|
||||
'Invalid transaction ({}): {}'.format(type(e).__name__, e)
|
||||
)
|
||||
else:
|
||||
bigchain.write_transaction(tx_obj, **args)
|
||||
bigchain.write_transaction(tx_obj, mode)
|
||||
|
||||
response = jsonify(tx)
|
||||
response.status_code = 202
|
||||
|
@ -76,7 +76,7 @@ def test_write_and_post_transaction(mock_post, b):
|
||||
.sign([alice.private_key]).to_dict()
|
||||
|
||||
tx = b.validate_transaction(tx)
|
||||
b.write_transaction(tx, **{'mode': 'broadcast_tx_async'})
|
||||
b.write_transaction(tx, 'broadcast_tx_async')
|
||||
|
||||
assert mock_post.called
|
||||
args, kwargs = mock_post.call_args
|
||||
@ -87,9 +87,9 @@ def test_write_and_post_transaction(mock_post, b):
|
||||
|
||||
@patch('requests.post')
|
||||
@pytest.mark.parametrize('mode', [
|
||||
{'mode': 'broadcast_tx_async'},
|
||||
{'mode': 'broadcast_tx_sync'},
|
||||
{'mode': 'broadcast_tx_commit'}
|
||||
'broadcast_tx_async',
|
||||
'broadcast_tx_sync',
|
||||
'broadcast_tx_commit'
|
||||
])
|
||||
def test_post_transaction_valid_modes(mock_post, b, mode):
|
||||
from bigchaindb.models import Transaction
|
||||
@ -100,10 +100,10 @@ def test_post_transaction_valid_modes(mock_post, b, mode):
|
||||
asset=None) \
|
||||
.sign([alice.private_key]).to_dict()
|
||||
tx = b.validate_transaction(tx)
|
||||
b.write_transaction(tx, **mode)
|
||||
b.write_transaction(tx, mode)
|
||||
|
||||
args, kwargs = mock_post.call_args
|
||||
assert mode['mode'] == kwargs['json']['method']
|
||||
assert mode == kwargs['json']['method']
|
||||
|
||||
|
||||
def test_post_transaction_invalid_mode(b):
|
||||
@ -117,4 +117,4 @@ def test_post_transaction_invalid_mode(b):
|
||||
.sign([alice.private_key]).to_dict()
|
||||
tx = b.validate_transaction(tx)
|
||||
with pytest.raises(ValidationError):
|
||||
b.write_transaction(tx, **{'mode': 'nope'})
|
||||
b.write_transaction(tx, 'nope')
|
||||
|
Loading…
x
Reference in New Issue
Block a user