Skip to content

Commit

Permalink
Add named keys in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Jan 2, 2025
1 parent 21cb059 commit 735a93a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
64 changes: 36 additions & 28 deletions src/test_fixtures/hashi_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,62 @@

import pytest
from aioresponses import CallbackResult, aioresponses
from sw_utils.tests import faker
from web3 import Web3


@pytest.fixture
def hashi_vault_url() -> str:
return 'http://vault:8200'


class HashiVaultStub:
bundled_pk_1 = faker.validator_public_key()
bundled_sk_1 = Web3.to_hex(faker.private_key())

bundled_pk_2 = faker.validator_public_key()
bundled_sk_2 = Web3.to_hex(faker.private_key())

bundled_pk_3 = faker.validator_public_key()
bundled_sk_3 = Web3.to_hex(faker.private_key())

bundled_pk_4 = faker.validator_public_key()
bundled_sk_4 = Web3.to_hex(faker.private_key())

prefixed_pk_1 = faker.validator_public_key()
prefixed_sk_1 = Web3.to_hex(faker.private_key())

prefixed_pk_2 = faker.validator_public_key()
prefixed_sk_2 = Web3.to_hex(faker.private_key())

prefixed_pk_3 = faker.validator_public_key()
prefixed_sk_3 = Web3.to_hex(faker.private_key())

prefixed_pk_4 = faker.validator_public_key()
prefixed_sk_4 = Web3.to_hex(faker.private_key())


@pytest.fixture
def mocked_hashi_vault(
hashi_vault_url: str,
) -> Generator:
# Generated via
# eth-staking-smith existing-mnemonic \
# --chain holesky \
# --num_validators 2 \
# --mnemonic 'provide iron update bronze session immense garage want round enhance artefact position make wash analyst skirt float jealous trend spread ginger rapid express tool'
_hashi_vault_pk_sk_mapping_1 = {
'b05e93c4501233eeb7f1e7b0ee400caaa04608249c4aab61c18e04c675aaf2a0f03808d533c877fbbd57b04927c01ce0': '3eeedd7a6679d2e2036682b6f03ef16105a847321303aec163548aa3fa5e9eeb',
'aa84894836cb3d897a1a11344920c41c472ed67667fd8a3453e557214442370ffc1d007ae7af67120de00afa068349be': '236f33410e6972a2db36ba3736099396768219b327e18eae49392f153007d468',
HashiVaultStub.bundled_pk_1: HashiVaultStub.bundled_sk_1,
HashiVaultStub.bundled_pk_2: HashiVaultStub.bundled_sk_2,
}
# Generated via
# eth-staking-smith existing-mnemonic \
# --chain holesky \
# --num_validators 2 \
# --mnemonic 'wheel treat brand feel motion atom card impose achieve rough shove bless glory wheel gold ensure maid despair turtle carry recall best outer fuel'
_hashi_vault_pk_sk_mapping_2 = {
'9548e46c8e3b11d686b11fe5c4aea53a6ffd6cef622920fe8d73b4b7bff71938d2a0652b607fa6d757e840f3ddc2d7a4': '2c7310981a6e12bef7f444860b450c70235acd3e9f74e0a3ee82da3fdbc657a5',
'8bc90a3110cf2b1ebaf8f5367bbfec1066797fca1f71ddbbf4f8f37ef74064404a78c31284c571656b7cb6efa29445ab': '56336628453e51cb9158da0651ea27dcb297eacdbd5cffdf0ea9d65fa154c327',
HashiVaultStub.bundled_pk_3: HashiVaultStub.bundled_sk_3,
HashiVaultStub.bundled_pk_4: HashiVaultStub.bundled_sk_4,
}

# Generated via
# eth-staking-smith existing-mnemonic \
# --chain holesky \
# --num_validators 2 \
# --mnemonic 'route flight verb churn work creek crane hole obscure young shaft area bird border refuse usage flash engage burden retreat drama bamboo profit sense'
_hashi_vault_prefixed_pk_sk_mapping1 = {
'8b09379ca969e8283a42a09285f430e8bd58c70bb33b44397ae81dac01b1403d0f631f156d211b6931a1c6284e2e469c': '5d88e114821bf871f321399d99fe58cb24d6434b416f112e8e46077e05399dc0',
'8979806d4e5d841758868b208df0dd961c12a0cf044e2de1d18e269ca0ad0308672be2f71d3d5606834764fe5b1d0bc4': '01352aec5cadb78eba6f716570d28b40f24b96c522dac535bc81375ceb54bf0b',
HashiVaultStub.prefixed_pk_1: HashiVaultStub.prefixed_sk_1,
HashiVaultStub.prefixed_pk_2: HashiVaultStub.prefixed_sk_2,
}

# Generated via
# eth-staking-smith existing-mnemonic \
# --chain holesky \
# --num_validators 2 \
# --mnemonic 'lion toilet tooth guess excuse wise amateur evolve moment damage curtain image zebra dress drill circle luggage seminar similar symptom happy floor govern gravity'
_hashi_vault_prefixed_pk_sk_mapping2 = {
'859f3fc64e32a1e95aadc7a7ec35207f6305951e7dafacf9252aaa9edef3d1edf74d268041cb59ca64e703ba064890be': '17dd0ad25bd239092bfa47b53c94d7eec2f3621a99ffafc28cd3c6b25a72d7f9',
'a60dcf78a344afc297b4917f76b5b387924153182390361d5199c3455299d67fbb932b77943ffe5477150304f3cb600f': '4f768f0b9589fdff6e8371dd268d8d78b97bf968f6fc469657332cff48b1dea4',
HashiVaultStub.prefixed_pk_3: HashiVaultStub.prefixed_sk_3,
HashiVaultStub.prefixed_pk_4: HashiVaultStub.prefixed_sk_4,
}

def _mocked_secret_path(data, url, **kwargs) -> CallbackResult:
Expand Down
25 changes: 25 additions & 0 deletions src/validators/keystores/tests/test_hashi_vault.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from src.config.settings import settings
from src.test_fixtures.hashi_vault import HashiVaultStub
from src.validators.keystores.hashi_vault import (
HashiVaultConfiguration,
HashiVaultKeystore,
Expand All @@ -23,6 +24,8 @@ async def test_hashi_vault_bundled_keystores_loading(
keystore = await HashiVaultKeystore.load()

assert len(keystore) == 2
assert HashiVaultStub.bundled_pk_1 in keystore
assert HashiVaultStub.bundled_pk_2 in keystore

@pytest.mark.usefixtures('mocked_hashi_vault')
async def test_hashi_vault_keystores_not_configured(
Expand Down Expand Up @@ -73,6 +76,10 @@ async def test_hashi_vault_bundled_keystores_parallel(
keystore = await HashiVaultKeystore.load()

assert len(keystore) == 4
assert HashiVaultStub.bundled_pk_1 in keystore
assert HashiVaultStub.bundled_pk_2 in keystore
assert HashiVaultStub.bundled_pk_3 in keystore
assert HashiVaultStub.bundled_pk_4 in keystore

@pytest.mark.usefixtures('mocked_hashi_vault')
async def test_hashi_vault_bundled_keystores_sequential(
Expand All @@ -91,6 +98,10 @@ async def test_hashi_vault_bundled_keystores_sequential(
keystore = await HashiVaultKeystore.load()

assert len(keystore) == 4
assert HashiVaultStub.bundled_pk_1 in keystore
assert HashiVaultStub.bundled_pk_2 in keystore
assert HashiVaultStub.bundled_pk_3 in keystore
assert HashiVaultStub.bundled_pk_4 in keystore

@pytest.mark.usefixtures('mocked_hashi_vault')
async def test_hashi_vault_duplicates_parallel(
Expand Down Expand Up @@ -123,6 +134,8 @@ async def test_hashi_vault_keystores_loading_custom_engine_name(
keystore = await HashiVaultKeystore.load()

assert len(keystore) == 2
assert HashiVaultStub.bundled_pk_1 in keystore
assert HashiVaultStub.bundled_pk_2 in keystore

@pytest.mark.usefixtures('mocked_hashi_vault')
async def test_hashi_vault_keystores_prefixed_loader(
Expand All @@ -139,6 +152,8 @@ async def test_hashi_vault_keystores_prefixed_loader(
keystore = await HashiVaultKeystore.load()

assert len(keystore) == 2
assert HashiVaultStub.prefixed_pk_1 in keystore
assert HashiVaultStub.prefixed_pk_2 in keystore

@pytest.mark.usefixtures('mocked_hashi_vault')
async def test_hashi_vault_load_bundled_and_prefixed(
Expand All @@ -161,3 +176,13 @@ async def test_hashi_vault_load_bundled_and_prefixed(
keystore = await HashiVaultKeystore.load()

assert len(keystore) == 8

assert HashiVaultStub.bundled_pk_1 in keystore
assert HashiVaultStub.bundled_pk_2 in keystore
assert HashiVaultStub.bundled_pk_3 in keystore
assert HashiVaultStub.bundled_pk_4 in keystore

assert HashiVaultStub.prefixed_pk_1 in keystore
assert HashiVaultStub.prefixed_pk_2 in keystore
assert HashiVaultStub.prefixed_pk_3 in keystore
assert HashiVaultStub.prefixed_pk_4 in keystore

0 comments on commit 735a93a

Please sign in to comment.