-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3998 from jtraglia/exclude-empty-requests
Exclude empty requests in requests list
- Loading branch information
Showing
7 changed files
with
234 additions
and
29 deletions.
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
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
119 changes: 119 additions & 0 deletions
119
tests/core/pyspec/eth2spec/test/electra/unittests/test_execution_requests.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,119 @@ | ||
from eth2spec.test.context import ( | ||
single_phase, | ||
spec_test, | ||
with_electra_and_later, | ||
) | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_serialization_round_trip__empty(spec): | ||
execution_requests = spec.ExecutionRequests() | ||
serialized_execution_requests = spec.get_execution_requests_list(execution_requests) | ||
deserialized_execution_requests = spec.get_execution_requests(serialized_execution_requests) | ||
assert deserialized_execution_requests == execution_requests | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_serialization_round_trip__one_request(spec): | ||
execution_requests = spec.ExecutionRequests( | ||
deposits=[spec.DepositRequest()], | ||
) | ||
serialized_execution_requests = spec.get_execution_requests_list(execution_requests) | ||
deserialized_execution_requests = spec.get_execution_requests(serialized_execution_requests) | ||
assert deserialized_execution_requests == execution_requests | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_serialization_round_trip__multiple_requests(spec): | ||
execution_requests = spec.ExecutionRequests( | ||
deposits=[spec.DepositRequest()], | ||
withdrawals=[spec.WithdrawalRequest()], | ||
consolidations=[spec.ConsolidationRequest()], | ||
) | ||
serialized_execution_requests = spec.get_execution_requests_list(execution_requests) | ||
deserialized_execution_requests = spec.get_execution_requests(serialized_execution_requests) | ||
assert deserialized_execution_requests == execution_requests | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_serialization_round_trip__one_request_with_real_data(spec): | ||
execution_requests = spec.ExecutionRequests( | ||
deposits=[ | ||
spec.DepositRequest( | ||
pubkey=spec.BLSPubkey(48 * "aa"), | ||
withdrawal_credentials=spec.Bytes32(32 * "bb"), | ||
amount=spec.Gwei(11111111), | ||
signature=spec.BLSSignature(96 * "cc"), | ||
index=spec.uint64(22222222), | ||
), | ||
] | ||
) | ||
serialized_execution_requests = spec.get_execution_requests_list(execution_requests) | ||
deserialized_execution_requests = spec.get_execution_requests(serialized_execution_requests) | ||
assert deserialized_execution_requests == execution_requests | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_deserialize__reject_duplicate_request(spec): | ||
serialized_withdrawal = 76 * b"\x0a" | ||
serialized_execution_requests = [ | ||
spec.WITHDRAWAL_REQUEST_TYPE + serialized_withdrawal, | ||
spec.WITHDRAWAL_REQUEST_TYPE + serialized_withdrawal, | ||
] | ||
try: | ||
spec.get_execution_requests(serialized_execution_requests) | ||
assert False, "expected exception" | ||
except Exception: | ||
pass | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_deserialize__reject_out_of_order_requests(spec): | ||
serialized_execution_requests = [ | ||
spec.WITHDRAWAL_REQUEST_TYPE + 76 * b"\x0a", | ||
spec.DEPOSIT_REQUEST_TYPE + 192 * b"\x0b", | ||
] | ||
assert int(serialized_execution_requests[0][0]) > int(serialized_execution_requests[1][0]) | ||
try: | ||
spec.get_execution_requests(serialized_execution_requests) | ||
assert False, "expected exception" | ||
except Exception: | ||
pass | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_deserialize__reject_empty_request(spec): | ||
serialized_execution_requests = [b"\x01"] | ||
try: | ||
spec.get_execution_requests(serialized_execution_requests) | ||
assert False, "expected exception" | ||
except Exception: | ||
pass | ||
|
||
|
||
@with_electra_and_later | ||
@spec_test | ||
@single_phase | ||
def test_requests_deserialize__reject_unexpected_request_type(spec): | ||
serialized_execution_requests = [ | ||
b"\x03\xff\xff\xff", | ||
] | ||
try: | ||
spec.get_execution_requests(serialized_execution_requests) | ||
assert False, "expected exception" | ||
except Exception: | ||
pass |
Oops, something went wrong.