Relocate keystore constants to test.constants

pull/1989/head
Kieran R. Prasch 2020-05-13 18:31:48 -07:00 committed by Kieran Prasch
parent 61cdcb9dd7
commit 8bb790d91a
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
3 changed files with 39 additions and 29 deletions

View File

@ -16,11 +16,10 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import json
import secrets
import pytest
import secrets
from eth_account import Account
from pathlib import Path
from nucypher.blockchain.eth.signers import KeystoreSigner
from nucypher.blockchain.eth.token import StakeList
@ -29,18 +28,15 @@ from nucypher.config.characters import UrsulaConfiguration
from nucypher.config.constants import (
NUCYPHER_ENVVAR_KEYRING_PASSWORD,
NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD,
TEMPORARY_DOMAIN,
)
from tests.constants import (
MOCK_IP_ADDRESS,
TEST_PROVIDER_URI
TEMPORARY_DOMAIN
)
from tests.constants import MOCK_IP_ADDRESS, TEST_PROVIDER_URI
from tests.utils.ursula import MOCK_URSULA_STARTING_PORT
@pytest.fixture(scope='module')
def mock_account_password_keystore(tmp_path_factory):
'''Generate a random keypair & password and create a local keystore'''
"""Generate a random keypair & password and create a local keystore"""
keystore = tmp_path_factory.mktemp('keystore', numbered=True)
password = secrets.token_urlsafe(12)
account = Account.create()

View File

@ -24,16 +24,9 @@ from nucypher.blockchain.eth.actors import Bidder
from nucypher.blockchain.eth.interfaces import BlockchainInterface
from nucypher.blockchain.eth.token import NU
from nucypher.cli.commands.worklock import worklock
from nucypher.config.constants import TEMPORARY_DOMAIN
from tests.constants import CLI_TEST_ENV, MOCK_PROVIDER_URI, YES
from tests.mock.agents import FAKE_RECEIPT, MockWorkLockAgent
from tests.constants import (MOCK_PROVIDER_URI, YES)
from nucypher.config.constants import (
NUCYPHER_ENVVAR_KEYRING_PASSWORD,
NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD,
TEMPORARY_DOMAIN,
)
CLI_ENV={}
@pytest.fixture(scope='function')
@ -92,7 +85,7 @@ def test_bid_too_soon(click_runner,
a_month_too_soon = now-(3600*30)
mocker.patch.object(BlockchainInterface, 'get_blocktime', return_value=a_month_too_soon)
with pytest.raises(Bidder.BiddingIsClosed):
result = click_runner.invoke(worklock, bidding_command, catch_exceptions=False, input=YES, env=CLI_ENV)
result = click_runner.invoke(worklock, bidding_command, catch_exceptions=False, input=YES, env=CLI_TEST_ENV)
assert result.exit_code != 0
@ -110,7 +103,7 @@ def test_bid_too_late(click_runner,
a_month_too_late = now+(3600*30)
mocker.patch.object(BlockchainInterface, 'get_blocktime', return_value=a_month_too_late)
with pytest.raises(Bidder.BiddingIsClosed):
result = click_runner.invoke(worklock, bidding_command, catch_exceptions=False, input=YES, env=CLI_ENV)
result = click_runner.invoke(worklock, bidding_command, catch_exceptions=False, input=YES, env=CLI_TEST_ENV)
assert result.exit_code != 0
@ -140,7 +133,7 @@ def test_valid_bid(click_runner,
'--network', TEMPORARY_DOMAIN,
'--force')
result = click_runner.invoke(worklock, command, catch_exceptions=False, input=YES, env=CLI_ENV)
result = click_runner.invoke(worklock, command, catch_exceptions=False, input=YES, env=CLI_TEST_ENV)
assert result.exit_code == 0
# OK - Let's see what happened
@ -175,7 +168,7 @@ def test_cancel_bid(click_runner,
'--provider', MOCK_PROVIDER_URI,
'--network', TEMPORARY_DOMAIN,
'--force')
result = click_runner.invoke(worklock, command, input=YES, env=CLI_ENV, catch_exceptions=False)
result = click_runner.invoke(worklock, command, input=YES, env=CLI_TEST_ENV, catch_exceptions=False)
assert result.exit_code == 0
# Bidder
@ -208,7 +201,7 @@ def test_post_initialization(click_runner,
'--network', TEMPORARY_DOMAIN,
'--gas-limit', 100000)
result = click_runner.invoke(worklock, command, input=YES, env=CLI_ENV, catch_exceptions=False)
result = click_runner.invoke(worklock, command, input=YES, env=CLI_TEST_ENV, catch_exceptions=False)
assert result.exit_code == 0
# Bidder
@ -246,7 +239,7 @@ def test_initial_claim(click_runner,
'--network', TEMPORARY_DOMAIN,
'--force')
result = click_runner.invoke(worklock, command, input=YES, env=CLI_ENV, catch_exceptions=False)
result = click_runner.invoke(worklock, command, input=YES, env=CLI_TEST_ENV, catch_exceptions=False)
assert result.exit_code == 0
mock_worklock_agent.assert_transaction(name='claim', checksum_address=surrogate_bidder.checksum_address)
@ -291,7 +284,7 @@ def test_already_claimed(click_runner,
'--network', TEMPORARY_DOMAIN,
'--force')
result = click_runner.invoke(worklock, command, input=YES, env=CLI_ENV, catch_exceptions=False)
result = click_runner.invoke(worklock, command, input=YES, env=CLI_TEST_ENV, catch_exceptions=False)
assert result.exit_code == 0
# Bidder
@ -346,7 +339,7 @@ def test_refund(click_runner,
'--network', TEMPORARY_DOMAIN,
'--force')
result = click_runner.invoke(worklock, command, input=YES, env=CLI_ENV, catch_exceptions=False)
result = click_runner.invoke(worklock, command, input=YES, env=CLI_TEST_ENV, catch_exceptions=False)
assert result.exit_code == 0
# Bidder

View File

@ -16,17 +16,16 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import string
from pathlib import Path
from random import SystemRandom
import tempfile
import time
from datetime import datetime
from pathlib import Path
from web3 import Web3
from nucypher.blockchain.eth.token import NU
from nucypher.config.constants import BASE_DIR, NUCYPHER_ENVVAR_KEYRING_PASSWORD
from nucypher.config.constants import BASE_DIR, NUCYPHER_ENVVAR_KEYRING_PASSWORD, NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD
#
# Ursula
@ -41,6 +40,18 @@ NUMBER_OF_ETH_TEST_ACCOUNTS = NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS + NUMBER_OF_
NUMBER_OF_URSULAS_IN_DEVELOPMENT_NETWORK = NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS
#
# Local Signer Keystore
#
KEYFILE_NAME_TEMPLATE = 'UTC--2020-{month}-21T03-42-07.869432648Z--{address}'
MOCK_KEYSTORE_PATH = '/home/fakeMcfakeson/.ethereum/llamanet/keystore/'
MOCK_SIGNER_URI = f'keystore://{MOCK_KEYSTORE_PATH}'
NUMBER_OF_MOCK_ACCOUNTS = 3
#
# Testerchain
@ -112,6 +123,9 @@ MOCK_IP_ADDRESS_2 = '203.0.113.20'
MOCK_URSULA_DB_FILEPATH = ':memory:'
FEE_RATE_RANGE = (5, 10, 15)
#
# Gas
#
@ -120,10 +134,17 @@ TEST_GAS_LIMIT = 8_000_000 # gas
PYEVM_GAS_LIMIT = TEST_GAS_LIMIT # TODO: move elsewhere (used to set pyevm gas limit in tests)?
#
# CLI
#
YES = 'Y\n'
NO = 'N\n'
CLI_TEST_ENV = {NUCYPHER_ENVVAR_KEYRING_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}
FEE_RATE_RANGE = (5, 10, 15)
CLI_ENV = {NUCYPHER_ENVVAR_KEYRING_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD,
NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD: INSECURE_DEVELOPMENT_PASSWORD}