-
Notifications
You must be signed in to change notification settings - Fork 926
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
Enables transfers of balance proportions > 32 ETH #936
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ed28515
Enables transferes of BAL > 32 ETH
CarlBeek ae0afe3
Cleaner assertion
CarlBeek d118eb0
Merge branch 'dev' into carl-patch-1
djrtwo c783cdb
fix bug and add transfer tests
djrtwo 9c14900
Update 0_beacon-chain.md
JustinDrake d9afb67
Update 0_beacon-chain.md
JustinDrake 40a898f
Update 0_beacon-chain.md
JustinDrake 72f4e2d
Update 0_beacon-chain.md
JustinDrake 6975288
Merge branch 'dev' into carl-patch-1
JustinDrake d6e616d
Merge branch 'dev' into carl-patch-1
CarlBeek cb5c95b
Fixes tests
CarlBeek 26afa07
Resolves conflicts and merges in dev
CarlBeek 408ef7e
Merge branch 'dev' into carl-patch-1
hwwhww fe01b6f
Merges dev into carl-patch-1
CarlBeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
test_libs/pyspec/tests/block_processing/test_process_transfer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
from copy import deepcopy | ||
import pytest | ||
|
||
import eth2spec.phase0.spec as spec | ||
|
||
from eth2spec.phase0.spec import ( | ||
get_active_validator_indices, | ||
get_balance, | ||
get_beacon_proposer_index, | ||
get_current_epoch, | ||
process_transfer, | ||
set_balance, | ||
) | ||
from tests.helpers import ( | ||
get_valid_transfer, | ||
next_epoch, | ||
) | ||
|
||
|
||
# mark entire file as 'transfers' | ||
pytestmark = pytest.mark.transfers | ||
|
||
|
||
def run_transfer_processing(state, transfer, valid=True): | ||
""" | ||
Run ``process_transfer`` returning the pre and post state. | ||
If ``valid == False``, run expecting ``AssertionError`` | ||
""" | ||
post_state = deepcopy(state) | ||
|
||
if not valid: | ||
with pytest.raises(AssertionError): | ||
process_transfer(post_state, transfer) | ||
return state, None | ||
|
||
|
||
process_transfer(post_state, transfer) | ||
|
||
proposer_index = get_beacon_proposer_index(state) | ||
pre_transfer_sender_balance = state.balances[transfer.sender] | ||
pre_transfer_recipient_balance = state.balances[transfer.recipient] | ||
pre_transfer_proposer_balance = state.balances[proposer_index] | ||
sender_balance = post_state.balances[transfer.sender] | ||
recipient_balance = post_state.balances[transfer.recipient] | ||
assert sender_balance == pre_transfer_sender_balance - transfer.amount - transfer.fee | ||
assert recipient_balance == pre_transfer_recipient_balance + transfer.amount | ||
assert post_state.balances[proposer_index] == pre_transfer_proposer_balance + transfer.fee | ||
|
||
return state, post_state | ||
|
||
|
||
def test_success_non_activated(state): | ||
transfer = get_valid_transfer(state) | ||
# un-activate so validator can transfer | ||
state.validator_registry[transfer.sender].activation_eligibility_epoch = spec.FAR_FUTURE_EPOCH | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer) | ||
|
||
return pre_state, transfer, post_state | ||
|
||
|
||
def test_success_withdrawable(state): | ||
next_epoch(state) | ||
|
||
transfer = get_valid_transfer(state) | ||
|
||
# withdrawable_epoch in past so can transfer | ||
state.validator_registry[transfer.sender].withdrawable_epoch = get_current_epoch(state) - 1 | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer) | ||
|
||
return pre_state, transfer, post_state | ||
|
||
|
||
def test_success_active_above_max_effective(state): | ||
sender_index = get_active_validator_indices(state, get_current_epoch(state))[-1] | ||
amount = spec.MAX_EFFECTIVE_BALANCE // 32 | ||
set_balance(state, sender_index, spec.MAX_EFFECTIVE_BALANCE + amount) | ||
transfer = get_valid_transfer(state, sender_index=sender_index, amount=amount, fee=0) | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer) | ||
|
||
return pre_state, transfer, post_state | ||
|
||
|
||
def test_active_but_transfer_past_effective_balance(state): | ||
sender_index = get_active_validator_indices(state, get_current_epoch(state))[-1] | ||
amount = spec.MAX_EFFECTIVE_BALANCE // 32 | ||
set_balance(state, sender_index, spec.MAX_EFFECTIVE_BALANCE) | ||
transfer = get_valid_transfer(state, sender_index=sender_index, amount=amount, fee=0) | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer, False) | ||
|
||
return pre_state, transfer, post_state | ||
|
||
|
||
def test_incorrect_slot(state): | ||
transfer = get_valid_transfer(state, slot=state.slot+1) | ||
# un-activate so validator can transfer | ||
state.validator_registry[transfer.sender].activation_epoch = spec.FAR_FUTURE_EPOCH | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer, False) | ||
|
||
return pre_state, transfer, post_state | ||
|
||
|
||
def test_insufficient_balance(state): | ||
sender_index = get_active_validator_indices(state, get_current_epoch(state))[-1] | ||
amount = spec.MAX_EFFECTIVE_BALANCE | ||
set_balance(state, sender_index, spec.MAX_EFFECTIVE_BALANCE) | ||
transfer = get_valid_transfer(state, sender_index=sender_index, amount=amount + 1, fee=0) | ||
|
||
# un-activate so validator can transfer | ||
state.validator_registry[transfer.sender].activation_epoch = spec.FAR_FUTURE_EPOCH | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer, False) | ||
|
||
return pre_state, transfer, post_state | ||
|
||
|
||
def test_no_dust(state): | ||
sender_index = get_active_validator_indices(state, get_current_epoch(state))[-1] | ||
balance = state.balances[sender_index] | ||
transfer = get_valid_transfer(state, sender_index=sender_index, amount=balance - spec.MIN_DEPOSIT_AMOUNT + 1, fee=0) | ||
|
||
# un-activate so validator can transfer | ||
state.validator_registry[transfer.sender].activation_epoch = spec.FAR_FUTURE_EPOCH | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer, False) | ||
|
||
return pre_state, transfer, post_state | ||
|
||
|
||
def test_invalid_pubkey(state): | ||
transfer = get_valid_transfer(state) | ||
state.validator_registry[transfer.sender].withdrawal_credentials = spec.ZERO_HASH | ||
|
||
# un-activate so validator can transfer | ||
state.validator_registry[transfer.sender].activation_epoch = spec.FAR_FUTURE_EPOCH | ||
|
||
pre_state, post_state = run_transfer_processing(state, transfer, False) | ||
|
||
return pre_state, transfer, post_state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong. This line should go away.