hypothesis validation for devdoc regex. Finish test split.

pull/2439/head
Kieran R. Prasch 2020-05-31 11:01:22 -07:00 committed by vzotova
parent d3e7d70faf
commit 7b0896f121
5 changed files with 81 additions and 13 deletions

View File

@ -248,7 +248,7 @@ def sign(general_config, blockchain_options, multisig_options, proposal):
proxy_contract = blockchain.client.w3.eth.contract(abi=abi,
address=address,
version=version,
ContractFactoryClass=blockchain._contract_factory)
ContractFactoryClass=blockchain._CONTRACT_FACTORY)
paint_multisig_proposed_transaction(emitter, proposal, proxy_contract)
click.confirm(PROMPT_CONFIRM_MULTISIG_SIGNATURE, abort=True)
@ -290,7 +290,7 @@ def execute(general_config, blockchain_options, multisig_options, proposal):
proxy_contract = blockchain.client.w3.eth.contract(abi=abi,
address=address,
version=version,
ContractFactoryClass=blockchain._contract_factory)
ContractFactoryClass=blockchain._CONTRACT_FACTORY)
paint_multisig_proposed_transaction(emitter, proposal, proxy_contract)
trustee = multisig_options.create_trustee(registry)

View File

@ -26,10 +26,9 @@ from nucypher.blockchain.eth.sol.compile import compile_nucypher
from nucypher.crypto.powers import TransactingPower
from tests.constants import (
DEVELOPMENT_ETH_AIRDROP_AMOUNT,
INSECURE_DEVELOPMENT_PASSWORD,
NUMBER_OF_ETH_TEST_ACCOUNTS,
NUMBER_OF_STAKERS_IN_BLOCKCHAIN_TESTS,
NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS
NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS, INSECURE_DEVELOPMENT_PASSWORD
)
# Prevents TesterBlockchain to be picked up by py.test as a test class
from tests.utils.blockchain import TesterBlockchain as _TesterBlockchain, free_gas_price_strategy

View File

@ -57,7 +57,6 @@ NUMBER_OF_MOCK_KEYSTORE_ACCOUNTS = NUMBER_OF_ETH_TEST_ACCOUNTS
# Testerchain
#
TEST_CONTRACTS_DIR = Path(BASE_DIR) / 'tests' / 'contracts' / 'contracts'
ONE_YEAR_IN_SECONDS = ((60 * 60) * 24) * 365

View File

@ -0,0 +1,66 @@
"""
This file is part of nucypher.
nucypher is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
nucypher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import re
import pytest
from datetime import timedelta
from nucypher.blockchain.eth.sol.compile import DEFAULT_CONTRACT_VERSION, DEVDOC_VERSION_PATTERN
from hypothesis import given, example, settings
from hypothesis import strategies
# @settings(deadline=None)
# @given(strategies.text())
# @example("")
# def test_match_devdoc_version_string(string):
# matches = VERSION_PATTERN.fullmatch(string=string)
# assert matches is None
@example('|v1.2.3|')
@example('|v99.99.99|')
@example(f'|{DEFAULT_CONTRACT_VERSION}|')
@given(strategies.from_regex(DEVDOC_VERSION_PATTERN, fullmatch=True))
@settings(max_examples=5000)
def test_devdoc_regex_pattern(full_match):
# Not empty
assert full_match
# Anchors
assert full_match.startswith('|') # start with version starting anchor
assert full_match.endswith('|')
# Max Size
numbers_only = re.sub("[^0-9]", "", full_match)
assert len(numbers_only) <= 6 # I mean really... who has a version with more than 6 numbers (v99.99.99)
# "v"
version_string = full_match[1:-1]
assert version_string.startswith('v') # start with version starting anchor
assert version_string.count('v') == 1 # only one version indicator
# 3 version parts
assert version_string.count('.') == 2 # only two version part delimiters
parts = version_string[1:]
version_parts = parts.split('.')
assert len(version_parts) == 3
# Parts are numbers
assert all(p.isdigit() for p in version_parts)

View File

@ -16,14 +16,17 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import maya
import os
from pathlib import Path
from typing import List, Tuple, Union
import maya
from eth_tester.exceptions import TransactionFailed
from eth_utils import to_canonical_address
from hexbytes import HexBytes
from typing import List, Tuple, Union
from web3 import Web3
import tests
from nucypher.blockchain.economics import BaseEconomics, StandardTokenEconomics
from nucypher.blockchain.eth.actors import ContractAdministrator
from nucypher.blockchain.eth.interfaces import BlockchainDeployerInterface, BlockchainInterfaceFactory
@ -39,8 +42,7 @@ from tests.constants import (
INSECURE_DEVELOPMENT_PASSWORD,
NUMBER_OF_ETH_TEST_ACCOUNTS,
NUMBER_OF_STAKERS_IN_BLOCKCHAIN_TESTS,
NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS,
TEST_CONTRACTS_DIR
NUMBER_OF_URSULAS_IN_BLOCKCHAIN_TESTS
)
@ -75,6 +77,12 @@ class TesterBlockchain(BlockchainDeployerInterface):
_instance = None
TEST_CONTRACTS_DIR = Path(tests.__file__).parent / 'contracts' / 'contracts'
SOURCES: List[str] = [
*BlockchainDeployerInterface.SOURCES,
str(TEST_CONTRACTS_DIR.resolve(strict=True))
]
GAS_STRATEGIES = {**BlockchainDeployerInterface.GAS_STRATEGIES,
'free': free_gas_price_strategy}
DEFAULT_GAS_STRATEGY = 'free'
@ -117,7 +125,6 @@ class TesterBlockchain(BlockchainDeployerInterface):
provider_process=None,
poa=poa,
light=light,
dry_run=mock_backend,
*args, **kwargs)
self.log = Logger("test-blockchain")
@ -134,9 +141,6 @@ class TesterBlockchain(BlockchainDeployerInterface):
if eth_airdrop is True: # ETH for everyone!
self.ether_airdrop(amount=DEVELOPMENT_ETH_AIRDROP_AMOUNT)
def connect(self):
return super().connect(test_contracts=True)
def attach_middleware(self):
if self.free_transactions:
self.w3.eth.setGasPriceStrategy(free_gas_price_strategy)