mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Updates tests with external bitcoind mock
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
import random
|
import random
|
||||||
import requests
|
import requests
|
||||||
@@ -17,9 +18,10 @@ from pisa.tools import bitcoin_cli
|
|||||||
from pisa.db_manager import DBManager
|
from pisa.db_manager import DBManager
|
||||||
from common.appointment import Appointment
|
from common.appointment import Appointment
|
||||||
|
|
||||||
from test.simulator.utils import sha256d
|
from bitcoind_mock.utils import sha256d
|
||||||
from test.simulator.transaction import TX
|
from bitcoind_mock.transaction import TX
|
||||||
from test.simulator.bitcoind_sim import run_simulator, HOST, PORT
|
from bitcoind_mock.bitcoind import BitcoindMock
|
||||||
|
from bitcoind_mock.conf import BTC_RPC_HOST, BTC_RPC_PORT
|
||||||
|
|
||||||
from common.constants import LOCATOR_LEN_HEX
|
from common.constants import LOCATOR_LEN_HEX
|
||||||
from common.cryptographer import Cryptographer
|
from common.cryptographer import Cryptographer
|
||||||
@@ -27,7 +29,7 @@ from common.cryptographer import Cryptographer
|
|||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def run_bitcoind():
|
def run_bitcoind():
|
||||||
bitcoind_thread = Thread(target=run_simulator, kwargs={"mode": "event", "verbose": False})
|
bitcoind_thread = Thread(target=BitcoindMock().run, kwargs={"mode": "event", "verbose": True})
|
||||||
bitcoind_thread.daemon = True
|
bitcoind_thread.daemon = True
|
||||||
bitcoind_thread.start()
|
bitcoind_thread.start()
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ def get_random_value_hex(nbytes):
|
|||||||
|
|
||||||
|
|
||||||
def generate_block():
|
def generate_block():
|
||||||
requests.post(url="http://{}:{}/generate".format(HOST, PORT), timeout=5)
|
requests.post(url="http://{}:{}/generate".format(BTC_RPC_HOST, BTC_RPC_PORT), timeout=5)
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
|
|
||||||
|
|
||||||
@@ -72,6 +74,11 @@ def generate_blocks(n):
|
|||||||
generate_block()
|
generate_block()
|
||||||
|
|
||||||
|
|
||||||
|
def fork(block_hash):
|
||||||
|
fork_endpoint = "http://{}:{}/fork".format(BTC_RPC_HOST, BTC_RPC_PORT)
|
||||||
|
requests.post(fork_endpoint, json={"parent": block_hash})
|
||||||
|
|
||||||
|
|
||||||
def generate_dummy_appointment_data(real_height=True, start_time_offset=5, end_time_offset=30):
|
def generate_dummy_appointment_data(real_height=True, start_time_offset=5, end_time_offset=30):
|
||||||
if real_height:
|
if real_height:
|
||||||
current_height = bitcoin_cli().getblockcount()
|
current_height = bitcoin_cli().getblockcount()
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pisa.carrier import Carrier
|
from pisa.carrier import Carrier
|
||||||
from test.simulator.utils import sha256d
|
from bitcoind_mock.utils import sha256d
|
||||||
from test.simulator.transaction import TX
|
from bitcoind_mock.transaction import TX
|
||||||
from test.pisa.unit.conftest import generate_blocks, get_random_value_hex
|
from test.pisa.unit.conftest import generate_blocks, get_random_value_hex
|
||||||
from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
|
from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ from pisa.tools import bitcoin_cli
|
|||||||
from common.constants import LOCATOR_LEN_HEX
|
from common.constants import LOCATOR_LEN_HEX
|
||||||
from common.tools import check_sha256_hex_format
|
from common.tools import check_sha256_hex_format
|
||||||
|
|
||||||
from test.simulator.utils import sha256d
|
from bitcoind_mock.utils import sha256d
|
||||||
from test.simulator.bitcoind_sim import TX
|
from bitcoind_mock.transaction import TX
|
||||||
from test.pisa.unit.conftest import generate_block, generate_blocks, get_random_value_hex
|
from test.pisa.unit.conftest import generate_block, generate_blocks, get_random_value_hex
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user