squeaknode/tests/conftest.py
2021-10-12 19:00:44 -07:00

151 lines
3.9 KiB
Python

# MIT License
#
# Copyright (c) 2020 Jonathan Zernik
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest
from bitcoin.core import CBlockHeader
from squeak.core.signing import CSigningKey
from squeak.core.signing import CSqueakAddress
from squeaknode.bitcoin.block_info import BlockInfo
from squeaknode.core.peer_address import Network
from squeaknode.core.peer_address import PeerAddress
from squeaknode.core.squeaks import make_squeak_with_block
from tests.utils import gen_contact_profile
from tests.utils import gen_signing_profile
@pytest.fixture
def signing_key():
yield CSigningKey.generate()
@pytest.fixture
def address(signing_key):
verifying_key = signing_key.get_verifying_key()
yield CSqueakAddress.from_verifying_key(verifying_key)
@pytest.fixture
def address_str(address):
yield str(address)
@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,
)
@pytest.fixture
def squeak_content():
yield "hello!"
@pytest.fixture
def squeak_and_secret_key(signing_key, squeak_content, block_info):
yield make_squeak_with_block(
signing_key,
squeak_content,
block_info.block_height,
block_info.block_hash,
)
@pytest.fixture
def squeak(squeak_and_secret_key):
squeak, _ = squeak_and_secret_key
yield squeak
@pytest.fixture
def secret_key(squeak_and_secret_key):
_, secret_key = squeak_and_secret_key
yield secret_key
@pytest.fixture
def peer_address():
yield PeerAddress(
network=Network.IPV4,
host="fake_host",
port=8765,
)
@pytest.fixture
def signing_profile_name():
yield "fake_signing_profile_name"
@pytest.fixture
def contact_profile_name():
yield "fake_contact_profile_name"
@pytest.fixture
def signing_profile(signing_profile_name, signing_key):
yield gen_signing_profile(
signing_profile_name,
str(signing_key),
)
@pytest.fixture
def contact_profile(contact_profile_name, address):
yield gen_contact_profile(
contact_profile_name,
str(address),
)