Skip to content

Commit ae65c40

Browse files
committed
Bugix: denoms.gwei != GWEI_PER_ETH
Define `GWEI_PER_ETH` in `eth/beacon/constants.py` and replace `denoms.gwei` with it.
1 parent 07df477 commit ae65c40

File tree

7 files changed

+41
-29
lines changed

7 files changed

+41
-29
lines changed

eth/beacon/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
RAND_MAX = 2 ** (RAND_BYTES * 8) - 1
1515

1616
EMPTY_SIGNATURE = BLSSignature((0, 0))
17+
GWEI_PER_ETH = 10**9

eth/beacon/helpers.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
TYPE_CHECKING,
66
)
77

8+
import functools
9+
810
from eth_utils import (
9-
denoms,
1011
to_tuple,
1112
ValidationError,
1213
)
13-
1414
from eth_typing import (
1515
Hash32,
1616
)
@@ -23,22 +23,23 @@
2323
from eth._utils.numeric import (
2424
clamp,
2525
)
26+
from eth.beacon._utils.random import (
27+
shuffle,
28+
split,
29+
)
2630

2731
from eth.beacon.block_committees_info import (
2832
BlockCommitteesInfo,
2933
)
34+
from eth.beacon.constants import (
35+
GWEI_PER_ETH,
36+
)
3037
from eth.beacon.enums import (
3138
SignatureDomain,
3239
)
3340
from eth.beacon.types.shard_committees import (
3441
ShardCommittee,
3542
)
36-
from eth.beacon._utils.random import (
37-
shuffle,
38-
split,
39-
)
40-
import functools
41-
4243
from eth.beacon.typing import (
4344
Bitfield,
4445
BLSPubkey,
@@ -387,7 +388,7 @@ def get_effective_balance(
387388
Return the effective balance (also known as "balance at stake") for a
388389
``validator`` with the given ``index``.
389390
"""
390-
return min(validator_balances[index], max_deposit * denoms.gwei)
391+
return min(validator_balances[index], Gwei(max_deposit * GWEI_PER_ETH))
391392

392393

393394
def get_fork_version(fork_data: 'ForkData',

tests/beacon/conftest.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import rlp
33

44
from eth_utils import (
5-
denoms,
65
to_tuple,
76
)
87

@@ -18,6 +17,9 @@
1817
from eth.beacon.aggregation import (
1918
aggregate_votes,
2019
)
20+
from eth.beacon.constants import (
21+
GWEI_PER_ETH,
22+
)
2123
from eth.beacon.enums import (
2224
SignatureDomain,
2325
)
@@ -384,7 +386,7 @@ def ten_validators_state(empty_beacon_state, max_deposit, far_future_slot):
384386
for pubkey in range(validator_count)
385387
),
386388
validator_balances=tuple(
387-
max_deposit * denoms.gwei
389+
max_deposit * GWEI_PER_ETH
388390
for _ in range(validator_count)
389391
)
390392
)
@@ -480,19 +482,21 @@ def deposit_contract_tree_depth():
480482
def min_deposit():
481483
return SERENITY_CONFIG.MIN_DEPOSIT
482484

483-
485+
@pytest.fixture
484486
def max_deposit():
485487
return SERENITY_CONFIG.MAX_DEPOSIT
486488

487-
489+
@pytest.fixture
488490
def genesis_fork_version():
489491
return SERENITY_CONFIG.GENESIS_FORK_VERSION
490492

491493

494+
@pytest.fixture
492495
def genesis_slot():
493496
return SERENITY_CONFIG.GENESIS_SLOT
494497

495498

499+
@pytest.fixture
496500
def far_future_slot():
497501
return SERENITY_CONFIG.FAR_FUTURE_SLOT
498502

@@ -652,7 +656,7 @@ def activated_genesis_validators(genesis_validators, genesis_slot, entry_exit_de
652656
@pytest.fixture
653657
def genesis_balances(init_validator_pubkeys, max_deposit):
654658
return tuple(
655-
max_deposit * denoms.gwei
659+
max_deposit * GWEI_PER_ETH
656660
for _ in init_validator_pubkeys
657661
)
658662

tests/beacon/state_machines/test_proposer_signature_validation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import pytest
22

33
from eth_utils import (
4-
denoms,
54
ValidationError,
65
)
76

87
from eth._utils import bls
98

9+
from eth.beacon.constants import (
10+
GWEI_PER_ETH,
11+
)
1012
from eth.beacon.enums import (
1113
SignatureDomain,
1214
)
@@ -56,7 +58,7 @@ def test_validate_serenity_proposer_signature(
5658
for _ in range(10)
5759
),
5860
validator_balances=tuple(
59-
max_deposit * denoms.gwei
61+
max_deposit * GWEI_PER_ETH
6062
for _ in range(10)
6163
),
6264
shard_committees_at_slots=get_sample_shard_committees_at_slots(

tests/beacon/test_deposit_helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import pytest
22

33
from eth_utils import (
4-
denoms,
54
ValidationError,
65
)
76

7+
from eth.beacon.constants import (
8+
GWEI_PER_ETH,
9+
)
810
from eth.beacon.deposit_helpers import (
911
add_pending_validator,
1012
process_deposit,
@@ -104,6 +106,7 @@ def test_validate_proof_of_possession(sample_beacon_state_params, pubkeys, privk
104106
def test_process_deposit(sample_beacon_state_params,
105107
privkeys,
106108
pubkeys,
109+
max_deposit,
107110
far_future_slot):
108111
state = BeaconState(**sample_beacon_state_params).copy(
109112
slot=1,
@@ -112,7 +115,7 @@ def test_process_deposit(sample_beacon_state_params,
112115

113116
privkey_1 = privkeys[0]
114117
pubkey_1 = pubkeys[0]
115-
amount = 32 * denoms.gwei
118+
amount = max_deposit * GWEI_PER_ETH
116119
withdrawal_credentials = b'\x34' * 32
117120
custody_commitment = b'\x11' * 32
118121
randao_commitment = b'\x56' * 32

tests/beacon/test_helpers.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
)
1010

1111
from eth_utils import (
12-
denoms,
1312
ValidationError,
1413
)
1514
from eth_utils.toolz import assoc
1615

1716
from eth.constants import (
1817
ZERO_HASH32,
1918
)
19+
from eth.beacon.constants import (
20+
GWEI_PER_ETH,
21+
)
2022
from eth.beacon.enums import (
2123
SignatureDomain,
2224
)
@@ -572,19 +574,19 @@ def mock_get_shard_committees_at_slot(state,
572574
),
573575
[
574576
(
575-
1 * denoms.gwei,
577+
1 * GWEI_PER_ETH,
576578
32,
577-
1 * denoms.gwei,
579+
1 * GWEI_PER_ETH,
578580
),
579581
(
580-
32 * denoms.gwei,
582+
32 * GWEI_PER_ETH,
581583
32,
582-
32 * denoms.gwei,
584+
32 * GWEI_PER_ETH,
583585
),
584586
(
585-
33 * denoms.gwei,
587+
33 * GWEI_PER_ETH,
586588
32,
587-
32 * denoms.gwei,
589+
32 * GWEI_PER_ETH,
588590
)
589591
]
590592
)

tests/beacon/types/test_states.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import rlp
44

5-
from eth_utils import (
6-
denoms,
5+
from eth.beacon.constants import (
6+
GWEI_PER_ETH,
77
)
8-
98
from eth.beacon.types.states import (
109
BeaconState,
1110
)
@@ -54,7 +53,7 @@ def test_num_validators(expected,
5453
for pubkey in range(expected)
5554
),
5655
validator_balances=tuple(
57-
max_deposit * denoms.gwei
56+
max_deposit * GWEI_PER_ETH
5857
for _ in range(expected)
5958
)
6059
)

0 commit comments

Comments
 (0)