Skip to content

Commit

Permalink
Updates event checks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Aug 7, 2023
1 parent 5251e07 commit f10f308
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 383 deletions.
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ distlib==0.3.6
eip712==0.2.1 ; python_version >= '3.8' and python_version < '4'
eth-abi==4.0.0 ; python_version >= '3.7' and python_version < '4'
eth-account==0.8.0 ; python_version >= '3.6' and python_version < '4'
eth-ape==0.6.9
eth-ape==0.6.13
eth-bloom==2.0.0 ; python_version >= '3.7' and python_version < '4'
eth-hash[pycryptodome]==0.5.1 ; python_version >= '3.7' and python_version < '4'
eth-keyfile==0.6.1
Expand All @@ -40,7 +40,7 @@ eth-rlp==0.3.0 ; python_version >= '3.7' and python_version < '4'
eth-tester[py-evm]==0.9.0b1
eth-typing==3.3.0 ; python_full_version >= '3.7.2' and python_version < '4'
eth-utils==2.1.0 ; python_version >= '3.7' and python_version < '4'
ethpm-types==0.5.1 ; python_version >= '3.8' and python_version < '4'
ethpm-types==0.5.3 ; python_version >= '3.8' and python_version < '4'
evm-trace==0.1.0a20 ; python_version >= '3.8' and python_version < '4'
exceptiongroup==1.1.1 ; python_version < '3.11'
executing==1.2.0
Expand Down Expand Up @@ -88,7 +88,7 @@ pure-eval==0.2.2
py-cid==0.3.0
py-ecc==6.0.0 ; python_version >= '3.6' and python_version < '4'
py-evm==0.7.0a2
py-geth==3.12.0 ; python_version >= '3'
py-geth==3.13.0 ; python_version >= '3'
py-multibase==1.0.3
py-multicodec==0.2.1
py-multihash==0.2.3
Expand Down Expand Up @@ -134,7 +134,7 @@ varint==1.0.2
virtualenv==20.23.0 ; python_version >= '3.7'
watchdog==2.3.1 ; python_version >= '3.6'
wcwidth==0.2.6
web3[tester]==6.4.0 ; python_full_version >= '3.7.2'
web3[tester]==6.5.0 ; python_full_version >= '3.7.2'
websockets==11.0.3 ; python_version >= '3.7'
wrapt==1.15.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
yarl==1.9.2 ; python_version >= '3.7'
Expand Down
190 changes: 95 additions & 95 deletions tests/application/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def test_authorization_increase(accounts, threshold_staking, taco_application, s

# Check that all events are emitted
events = taco_application.AuthorizationIncreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == 0
assert event["toAmount"] == value
assert events == [
taco_application.AuthorizationIncreased(
stakingProvider=staking_provider, fromAmount=0, toAmount=value
)
]

# Decrease and try to increase again
threshold_staking.involuntaryAuthorizationDecrease(
Expand All @@ -90,11 +90,11 @@ def test_authorization_increase(accounts, threshold_staking, taco_application, s
assert taco_application.isAuthorized(staking_provider)

events = taco_application.AuthorizationIncreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value // 2
assert event["toAmount"] == value
assert events == [
taco_application.AuthorizationIncreased(
stakingProvider=staking_provider, fromAmount=value // 2, toAmount=value
)
]

# Confirm operator address and try to increase authorization again
taco_application.bondOperator(staking_provider, staking_provider, sender=staking_provider)
Expand All @@ -113,11 +113,11 @@ def test_authorization_increase(accounts, threshold_staking, taco_application, s
assert taco_application.isAuthorized(staking_provider)

events = taco_application.AuthorizationIncreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == authorization
assert events == [
taco_application.AuthorizationIncreased(
stakingProvider=staking_provider, fromAmount=value, toAmount=authorization
)
]

# Emulate slash and desync by sending smaller fromAmount
tx = threshold_staking.authorizationIncreased(
Expand All @@ -130,11 +130,11 @@ def test_authorization_increase(accounts, threshold_staking, taco_application, s
assert taco_application.isAuthorized(staking_provider)

events = taco_application.AuthorizationIncreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value // 2
assert event["toAmount"] == value
assert events == [
taco_application.AuthorizationIncreased(
stakingProvider=staking_provider, fromAmount=value // 2, toAmount=value
)
]

# Increase again without syncing with StakeInfo
taco_application.setUpdatableStakeInfo(ZERO_ADDRESS, sender=creator)
Expand Down Expand Up @@ -181,11 +181,11 @@ def test_involuntary_authorization_decrease(
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == ZERO_ADDRESS

events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == authorization
assert events == [
taco_application.AuthorizationInvoluntaryDecreased(
stakingProvider=staking_provider, fromAmount=value, toAmount=authorization
)
]

# Prepare request to decrease before involuntary decrease
threshold_staking.authorizationDecreaseRequested(
Expand All @@ -210,11 +210,11 @@ def test_involuntary_authorization_decrease(
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == ZERO_ADDRESS

events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value // 2
assert event["toAmount"] == authorization
assert events == [
taco_application.AuthorizationInvoluntaryDecreased(
stakingProvider=staking_provider, fromAmount=value // 2, toAmount=authorization
)
]

# Confirm operator address and decrease again
taco_application.bondOperator(staking_provider, staking_provider, sender=staking_provider)
Expand All @@ -240,11 +240,11 @@ def test_involuntary_authorization_decrease(
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == staking_provider

events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value // 4
assert event["toAmount"] == authorization
assert events == [
taco_application.AuthorizationInvoluntaryDecreased(
stakingProvider=staking_provider, fromAmount=value // 4, toAmount=authorization
)
]

# Decrease everything
tx = threshold_staking.involuntaryAuthorizationDecrease(
Expand All @@ -263,11 +263,11 @@ def test_involuntary_authorization_decrease(
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == ZERO_ADDRESS

events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == authorization
assert event["toAmount"] == 0
assert events == [
taco_application.AuthorizationInvoluntaryDecreased(
stakingProvider=staking_provider, fromAmount=authorization, toAmount=0
)
]

# Emulate slash and desync by sending smaller fromAmount
threshold_staking.authorizationIncreased(staking_provider, 0, 2 * value, sender=creator)
Expand All @@ -286,11 +286,11 @@ def test_involuntary_authorization_decrease(
assert stake_info.authorizedStake(staking_provider) == authorization

events = taco_application.AuthorizationInvoluntaryDecreased.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == authorization
assert events == [
taco_application.AuthorizationInvoluntaryDecreased(
stakingProvider=staking_provider, fromAmount=value, toAmount=authorization
)
]

# Decrease everything again without syncing with StakeInfo
taco_application.setUpdatableStakeInfo(ZERO_ADDRESS, sender=creator)
Expand Down Expand Up @@ -352,11 +352,11 @@ def test_authorization_decrease_request(
assert taco_application.isAuthorized(staking_provider)

events = taco_application.AuthorizationDecreaseRequested.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == minimum_authorization
assert events == [
taco_application.AuthorizationDecreaseRequested(
stakingProvider=staking_provider, fromAmount=value, toAmount=minimum_authorization
)
]

# Confirm operator address and request full decrease
taco_application.bondOperator(staking_provider, staking_provider, sender=staking_provider)
Expand All @@ -379,11 +379,11 @@ def test_authorization_decrease_request(
assert taco_application.isAuthorized(staking_provider)

events = taco_application.AuthorizationDecreaseRequested.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == 0
assert events == [
taco_application.AuthorizationDecreaseRequested(
stakingProvider=staking_provider, fromAmount=value, toAmount=0
)
]

# Emulate slash and desync by sending smaller fromAmount
tx = threshold_staking.authorizationDecreaseRequested(
Expand All @@ -396,11 +396,11 @@ def test_authorization_decrease_request(
assert stake_info.authorizedStake(staking_provider) == 0

events = taco_application.AuthorizationDecreaseRequested.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value // 2
assert event["toAmount"] == 0
assert events == [
taco_application.AuthorizationDecreaseRequested(
stakingProvider=staking_provider, fromAmount=value // 2, toAmount=0
)
]

# Request decrease without syncing with StakeInfo
taco_application.setUpdatableStakeInfo(ZERO_ADDRESS, sender=creator)
Expand Down Expand Up @@ -453,11 +453,11 @@ def test_finish_authorization_decrease(
)

events = taco_application.AuthorizationDecreaseApproved.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == new_value
assert events == [
taco_application.AuthorizationDecreaseApproved(
stakingProvider=staking_provider, fromAmount=value, toAmount=new_value
)
]

# Confirm operator, request again then desync values and finish decrease
value = new_value
Expand Down Expand Up @@ -488,11 +488,11 @@ def test_finish_authorization_decrease(
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == staking_provider

events = taco_application.AuthorizationDecreaseApproved.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == new_value
assert events == [
taco_application.AuthorizationDecreaseApproved(
stakingProvider=staking_provider, fromAmount=value, toAmount=new_value
)
]

# Decrease everything
value = new_value
Expand All @@ -515,11 +515,11 @@ def test_finish_authorization_decrease(
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == ZERO_ADDRESS

events = taco_application.AuthorizationDecreaseApproved.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == 0
assert events == [
taco_application.AuthorizationDecreaseApproved(
stakingProvider=staking_provider, fromAmount=value, toAmount=0
)
]

# Decrease everything again without syncing with StakeInfo
value = minimum_authorization
Expand Down Expand Up @@ -570,11 +570,11 @@ def test_resync(accounts, threshold_staking, taco_application, stake_info):
assert taco_application.isAuthorized(staking_provider)

events = taco_application.AuthorizationReSynchronized.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == new_value
assert events == [
taco_application.AuthorizationReSynchronized(
stakingProvider=staking_provider, fromAmount=value, toAmount=new_value
)
]

# Confirm operator and change authorized amount again
value = new_value
Expand All @@ -597,11 +597,11 @@ def test_resync(accounts, threshold_staking, taco_application, stake_info):
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == staking_provider

events = taco_application.AuthorizationReSynchronized.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == new_value
assert events == [
taco_application.AuthorizationReSynchronized(
stakingProvider=staking_provider, fromAmount=value, toAmount=new_value
)
]

# Request decrease and change authorized amount again
value = new_value
Expand All @@ -623,11 +623,11 @@ def test_resync(accounts, threshold_staking, taco_application, stake_info):
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == staking_provider

events = taco_application.AuthorizationReSynchronized.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == new_value
assert events == [
taco_application.AuthorizationReSynchronized(
stakingProvider=staking_provider, fromAmount=value, toAmount=new_value
)
]

# Set authorized amount to zero and resync again
value = new_value
Expand All @@ -647,11 +647,11 @@ def test_resync(accounts, threshold_staking, taco_application, stake_info):
assert stake_info.stakes(staking_provider)[STAKE_INFO_OPERATOR_SLOT] == ZERO_ADDRESS

events = taco_application.AuthorizationReSynchronized.from_receipt(tx)
assert len(events) == 1
event = events[0]
assert event["stakingProvider"] == staking_provider
assert event["fromAmount"] == value
assert event["toAmount"] == 0
assert events == [
taco_application.AuthorizationReSynchronized(
stakingProvider=staking_provider, fromAmount=value, toAmount=0
)
]

# Resync again without syncing with StakeInfo
value = minimum_authorization
Expand Down
Loading

0 comments on commit f10f308

Please sign in to comment.