Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/epoch length #114

Merged
merged 5 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions casper/contracts/simple_casper.v.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def __init__(
base_interest_factor: decimal, base_penalty_factor: decimal,
min_deposit_size: wei_value):

assert epoch_length > 0 and epoch_length < 256

self.EPOCH_LENGTH = epoch_length
self.WITHDRAWAL_DELAY = withdrawal_delay
self.DYNASTY_LOGOUT_DELAY = dynasty_logout_delay
Expand Down
78 changes: 65 additions & 13 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@
BASE_PENALTY_FACTOR = 0.002
MIN_DEPOSIT_SIZE = 1000 * 10**18 # 1000 ether

CASPER_CONFIG = {
"epoch_length": EPOCH_LENGTH, # in blocks
"withdrawal_delay": WITHDRAWAL_DELAY, # in epochs
"dynasty_logout_delay": DYNASTY_LOGOUT_DELAY, # in dynasties
"owner": OWNER, # Backdoor address
"base_interest_factor": BASE_INTEREST_FACTOR,
"base_penalty_factor": BASE_PENALTY_FACTOR,
"min_deposit_size": MIN_DEPOSIT_SIZE
}

FUNDED_PRIVKEYS = [tester.k1, tester.k2, tester.k3, tester.k4, tester.k5]
DEPOSIT_AMOUNTS = [
2000 * 10**18,
Expand Down Expand Up @@ -105,8 +95,52 @@ def purity_checker_ct():


@pytest.fixture
def casper_config():
return CASPER_CONFIG
def epoch_length():
return EPOCH_LENGTH


@pytest.fixture
def withdrawal_delay():
return WITHDRAWAL_DELAY


@pytest.fixture
def dynasty_logout_delay():
return DYNASTY_LOGOUT_DELAY


@pytest.fixture
def owner():
return OWNER


@pytest.fixture
def base_interest_factor():
return BASE_INTEREST_FACTOR


@pytest.fixture
def base_penalty_factor():
return BASE_PENALTY_FACTOR


@pytest.fixture
def min_deposit_size():
return MIN_DEPOSIT_SIZE


@pytest.fixture
def casper_config(epoch_length, withdrawal_delay, dynasty_logout_delay,
owner, base_interest_factor, base_penalty_factor, min_deposit_size):
return {
"epoch_length": epoch_length, # in blocks
"withdrawal_delay": withdrawal_delay, # in epochs
"dynasty_logout_delay": dynasty_logout_delay, # in dynasties
"owner": owner, # Backdoor address
"base_interest_factor": base_interest_factor,
"base_penalty_factor": base_penalty_factor,
"min_deposit_size": min_deposit_size
}


@pytest.fixture
Expand Down Expand Up @@ -244,6 +278,24 @@ def casper_chain(
return test_chain


@pytest.fixture
def deploy_casper_contract(
test_chain,
casper_code,
casper_ct,
dependency_transactions,
sig_hasher_address,
purity_checker_address,
base_sender_privkey):
def deploy_casper_contract(contract_args):
casper_chain(
test_chain, contract_args, casper_code, casper_ct,
dependency_transactions, sig_hasher_address, purity_checker_address,
base_sender_privkey
)
return deploy_casper_contract


def get_dirs(path):
abs_contract_path = os.path.realpath(os.path.join(OWN_DIR, '..', 'casper', 'contracts'))
sub_dirs = [x[0] for x in os.walk(abs_contract_path)]
Expand Down Expand Up @@ -405,7 +457,7 @@ def induct_validators(privkeys, values):


@pytest.fixture
def assert_failed(casper_chain):
def assert_failed():
def assert_failed(function_to_test, exception):
with pytest.raises(exception):
function_to_test()
Expand Down
28 changes: 28 additions & 0 deletions tests/test_chain_initialization.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import pytest

from ethereum import utils
from ethereum.tools.tester import TransactionFailed
from conftest import casper_chain


def test_rlp_decoding_is_pure(
Expand Down Expand Up @@ -43,3 +47,27 @@ def test_init_first_epoch(casper, new_epoch):
assert casper.dynasty() == 0
assert casper.next_validator_index() == 1
assert casper.current_epoch() == 1


@pytest.mark.parametrize(
'epoch_length, success',
[
(-1, False),
(0, False),
(10, True),
(250, True),
(256, False),
(500, False),
]
)
def test_epoch_length(epoch_length, success, casper_args,
deploy_casper_contract, assert_failed):
# Note: cannot use assert_tx_failed because requires casper_chain
if not success:
assert_failed(
lambda: deploy_casper_contract(casper_args),
TransactionFailed
)
return

deploy_casper_contract(casper_args)