Add block_info fixture to global conftest (#1584)

This commit is contained in:
Jonathan Zernik 2021-10-12 19:00:44 -07:00 committed by GitHub
parent 8a317baabd
commit dd927036a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 58 deletions

View file

@ -23,7 +23,6 @@ import json
import mock
import pytest
from bitcoin.core import CBlockHeader
from requests import HTTPError
from requests.exceptions import ConnectionError
from requests.exceptions import RequestException
@ -66,47 +65,6 @@ def bitcoin_core_client(bitcoin_host, bitcoin_port, bitcoin_user, bitcoin_pass):
)
@pytest.fixture
def block_count():
yield 555
@pytest.fixture
def block_hash_str():
# Block hash of block at height 555
yield '00000000edade40797e3c4bf27edeb65733d1884beaa8c502a89d50a54111e1c'
@pytest.fixture
def block_hash(block_hash_str):
yield bytes.fromhex(block_hash_str)
@pytest.fixture
def block_header_str():
# Block header of block at height 555
yield '0100000079c30d2c23727a1e9f5feda4e7feb8ea0bda2ab98e23e7f6a9cf594f00000000b0de897e42fa7a3b5c3a6bfb8e797acf4ffbc16169394b03ad93296524ed633dcfef6e49ffff001d36d19a6c'
@pytest.fixture
def block_header_bytes(block_header_str):
yield bytes.fromhex(block_header_str)
@pytest.fixture
def block_header(block_header_bytes):
yield CBlockHeader.deserialize(block_header_bytes)
@pytest.fixture
def block_info(block_count, block_hash, block_header):
yield BlockInfo(
block_height=block_count,
block_hash=block_hash,
block_header=block_header,
)
class MockResponse:
def json(self):

View file

@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest
from bitcoin.core import CoreMainParams
from bitcoin.core import CBlockHeader
from squeak.core.signing import CSigningKey
from squeak.core.signing import CSqueakAddress
@ -49,11 +49,43 @@ def address_str(address):
@pytest.fixture
def genesis_block_info():
def block_count():
yield 555
@pytest.fixture
def block_hash_str():
# Block hash of block at height 555
yield '00000000edade40797e3c4bf27edeb65733d1884beaa8c502a89d50a54111e1c'
@pytest.fixture
def block_hash(block_hash_str):
yield bytes.fromhex(block_hash_str)
@pytest.fixture
def block_header_str():
# Block header of block at height 555
yield '0100000079c30d2c23727a1e9f5feda4e7feb8ea0bda2ab98e23e7f6a9cf594f00000000b0de897e42fa7a3b5c3a6bfb8e797acf4ffbc16169394b03ad93296524ed633dcfef6e49ffff001d36d19a6c'
@pytest.fixture
def block_header_bytes(block_header_str):
yield bytes.fromhex(block_header_str)
@pytest.fixture
def block_header(block_header_bytes):
yield CBlockHeader.deserialize(block_header_bytes)
@pytest.fixture
def block_info(block_count, block_hash, block_header):
yield BlockInfo(
block_height=0,
block_hash=CoreMainParams.GENESIS_BLOCK.GetHash(),
block_header=CoreMainParams.GENESIS_BLOCK.get_header().serialize(),
block_height=block_count,
block_hash=block_hash,
block_header=block_header,
)
@ -63,12 +95,12 @@ def squeak_content():
@pytest.fixture
def squeak_and_secret_key(signing_key, squeak_content, genesis_block_info):
def squeak_and_secret_key(signing_key, squeak_content, block_info):
yield make_squeak_with_block(
signing_key,
squeak_content,
genesis_block_info.block_height,
genesis_block_info.block_hash,
block_info.block_height,
block_info.block_hash,
)

View file

@ -217,8 +217,8 @@ class MockLightningClient(LightningClient):
@pytest.fixture
def bitcoin_client(genesis_block_info):
return MockBitcoinClient(genesis_block_info)
def bitcoin_client(block_info):
return MockBitcoinClient(block_info)
@pytest.fixture
@ -312,11 +312,11 @@ def test_make_squeak_with_contact_profile(
def test_get_block_header(
squeak_core,
squeak,
genesis_block_info,
block_info,
):
block_header = squeak_core.get_block_header(squeak)
assert block_header == genesis_block_info.block_header
assert block_header == block_info.block_header
def test_get_block_header_invalid_block_hash(
@ -332,10 +332,10 @@ def test_check_squeak(squeak_core, squeak):
squeak_core.check_squeak(squeak)
def test_get_best_block_height(squeak_core, genesis_block_info):
def test_get_best_block_height(squeak_core, block_info):
best_block_height = squeak_core.get_best_block_height()
assert best_block_height == genesis_block_info.block_height
assert best_block_height == block_info.block_height
def test_create_offer(squeak_core, squeak, secret_key, peer_address, price_msat):

View file

@ -24,8 +24,8 @@ from squeaknode.core.squeaks import get_decrypted_content
from squeaknode.core.squeaks import get_payment_point_of_secret_key
def test_make_squeak(squeak):
assert squeak.nBlockHeight == 0
def test_make_squeak(squeak, block_count):
assert squeak.nBlockHeight == block_count
def test_check_squeak(squeak):