mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Move last methods to util
This commit is contained in:
@@ -510,28 +510,3 @@ class Bigchain(object):
|
||||
|
||||
return unvoted
|
||||
|
||||
|
||||
@staticmethod
|
||||
def deserialize(data):
|
||||
"""Static method used to deserialize a JSON formatted string into a dict.
|
||||
|
||||
Args:
|
||||
data (str): JSON formatted string.
|
||||
|
||||
Returns:
|
||||
dict: dict resulting from the serialization of a JSON formatted string.
|
||||
"""
|
||||
|
||||
return json.loads(data, encoding="utf-8")
|
||||
|
||||
@staticmethod
|
||||
def generate_keys():
|
||||
"""Generates a key pair.
|
||||
|
||||
Returns:
|
||||
tuple: `(private_key, public_key)`. ECDSA key pair using the secp256k1 curve encoded
|
||||
in base58.
|
||||
"""
|
||||
|
||||
# generates and returns the keys serialized in hex
|
||||
return crypto.generate_key_pair()
|
||||
|
||||
@@ -32,7 +32,7 @@ class ProcessGroup(object):
|
||||
|
||||
|
||||
def serialize(data):
|
||||
"""Function used to serialize a dict into a JSON formatted string.
|
||||
"""Serialize a dict into a JSON formatted string.
|
||||
|
||||
This function enforces rules like the separator and order of keys. This ensures that all dicts
|
||||
are serialized in the same way.
|
||||
@@ -52,8 +52,21 @@ def serialize(data):
|
||||
separators=(',', ':'), sort_keys=True)
|
||||
|
||||
|
||||
def deserialize(data):
|
||||
"""Deserialize a JSON formatted string into a dict.
|
||||
|
||||
Args:
|
||||
data (str): JSON formatted string.
|
||||
|
||||
Returns:
|
||||
dict: dict resulting from the serialization of a JSON formatted string.
|
||||
"""
|
||||
|
||||
return json.loads(data, encoding="utf-8")
|
||||
|
||||
|
||||
def timestamp():
|
||||
"""Function to calculate a UTC timestamp with microsecond precision.
|
||||
"""Calculate a UTC timestamp with microsecond precision.
|
||||
|
||||
Returns:
|
||||
str: UTC timestamp.
|
||||
|
||||
@@ -52,7 +52,7 @@ class TestBigchainApi(object):
|
||||
# assert tx_hash == tx_calculated_hash
|
||||
|
||||
def test_transaction_signature(self, b):
|
||||
sk, vk = b.generate_keys()
|
||||
sk, vk = generate_key_pair()
|
||||
tx = b.create_transaction(vk, 'b', 'c', 'd')
|
||||
tx_signed = b.sign_transaction(tx, sk)
|
||||
|
||||
@@ -61,7 +61,7 @@ class TestBigchainApi(object):
|
||||
|
||||
def test_serializer(self, b):
|
||||
tx = b.create_transaction('a', 'b', 'c', 'd')
|
||||
assert b.deserialize(util.serialize(tx)) == tx
|
||||
assert util.deserialize(util.serialize(tx)) == tx
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_write_transaction(self, b, user_public_key, user_private_key):
|
||||
@@ -108,7 +108,7 @@ class TestBigchainApi(object):
|
||||
def test_assign_transaction_multiple_nodes(self, b, user_public_key, user_private_key):
|
||||
# create 5 federation nodes
|
||||
for _ in range(5):
|
||||
b.federation_nodes.append(b.generate_keys()[1])
|
||||
b.federation_nodes.append(generate_key_pair()[1])
|
||||
|
||||
# test assignee for several transactions
|
||||
for _ in range(20):
|
||||
|
||||
@@ -3,11 +3,10 @@ import time
|
||||
import rethinkdb as r
|
||||
import multiprocessing as mp
|
||||
|
||||
from bigchaindb import Bigchain
|
||||
from bigchaindb import util
|
||||
|
||||
from bigchaindb.voter import Voter, BlockStream
|
||||
from bigchaindb.crypto import PublicKey
|
||||
from bigchaindb.crypto import PublicKey, generate_key_pair
|
||||
|
||||
|
||||
class TestBigchainVoter(object):
|
||||
@@ -54,7 +53,7 @@ class TestBigchainVoter(object):
|
||||
genesis = b.create_genesis_block()
|
||||
|
||||
# create a `CREATE` transaction
|
||||
test_user_priv, test_user_pub = b.generate_keys()
|
||||
test_user_priv, test_user_pub = generate_key_pair()
|
||||
tx = b.create_transaction(b.me, test_user_pub, None, 'CREATE')
|
||||
tx_signed = b.sign_transaction(tx, b.me_private)
|
||||
assert b.is_valid_transaction(tx_signed)
|
||||
@@ -96,7 +95,7 @@ class TestBigchainVoter(object):
|
||||
b.create_genesis_block()
|
||||
|
||||
# create a `CREATE` transaction
|
||||
test_user_priv, test_user_pub = b.generate_keys()
|
||||
test_user_priv, test_user_pub = generate_key_pair()
|
||||
tx = b.create_transaction(b.me, test_user_pub, None, 'CREATE')
|
||||
tx_signed = b.sign_transaction(tx, b.me_private)
|
||||
assert b.is_valid_transaction(tx_signed)
|
||||
@@ -125,7 +124,7 @@ class TestBigchainVoter(object):
|
||||
assert len(blocks[1]['votes']) == 1
|
||||
|
||||
# create a `TRANSFER` transaction
|
||||
test_user2_priv, test_user2_pub = b.generate_keys()
|
||||
test_user2_priv, test_user2_pub = generate_key_pair()
|
||||
tx2 = b.create_transaction(test_user_pub, test_user2_pub, tx['id'], 'TRANSFER')
|
||||
tx2_signed = b.sign_transaction(tx2, test_user_priv)
|
||||
assert b.is_valid_transaction(tx2_signed)
|
||||
@@ -302,7 +301,7 @@ class TestBlockStream(object):
|
||||
|
||||
def test_if_federation_size_is_greater_than_one_ignore_past_blocks(self, b):
|
||||
for _ in range(5):
|
||||
b.federation_nodes.append(b.generate_keys()[1])
|
||||
b.federation_nodes.append(generate_key_pair()[1])
|
||||
new_blocks = mp.Queue()
|
||||
bs = BlockStream(new_blocks)
|
||||
block_1 = b.create_block([])
|
||||
|
||||
Reference in New Issue
Block a user