-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add tests for easytracks + dvt happy path
- Loading branch information
Showing
8 changed files
with
502 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; export DEPLOYER=<brownie_wallet_name> | ||
; export ETHERSCAN_TOKEN=W45UFQTEAJSYT7C4EUNVIVNJRR526CI5GX | ||
; export WEB3_STORAGE_TOKEN=<web3_storage_api_key> | ||
; export OMNIBUS_BYPASS_EVENTS_DECODING=1 | ||
; export OMNIBUS_VOTE_IDS=156 | ||
; export WEB3_INFURA_PROJECT_ID=5b8765f0a27146839a26b4cfee98ae04 | ||
; export ENV_PARSE_EVENTS_FROM_LOCAL_ABI=1 | ||
; export REPORT_AFTER_VOTE=1 | ||
|
||
WEB3_ALCHEMY_PROJECT_ID=7_iiMwbpORmyzwTvn-5vcUXgTnPmbQXe | ||
WEB3_INFURA_PROJECT_ID=5b8765f0a27146839a26b4cfee98ae04 | ||
ENV_PARSE_EVENTS_FROM_LOCAL_ABI=1 | ||
REPORT_AFTER_VOTE=1 | ||
ETHERSCAN_TOKEN=W45UFQTEAJSYT7C4EUNVIVNJRR526CI5GX |
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 |
---|---|---|
|
@@ -6,6 +6,8 @@ __pycache__ | |
build/ | ||
reports/ | ||
dist/ | ||
.env | ||
_ganache | ||
|
||
# PyCharm | ||
.idea | ||
|
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,318 @@ | ||
import random | ||
|
||
from brownie import interface, accounts, chain | ||
from brownie.exceptions import VirtualMachineError | ||
|
||
from configs.config_mainnet import * | ||
from utils.config import contracts | ||
from utils.test.easy_track_helpers import _encode_calldata | ||
from utils.test.simple_dvt_helpers import MANAGERS | ||
|
||
|
||
NODE_OPERATORS = [ | ||
{ | ||
'address': f'0x000000000000000000000000000000000000{i:04}', | ||
'manager': f'0x000000000000000000000000000000000001{i:04}', | ||
'name': f'Node operator {i}', | ||
} | ||
for i in range(1, 11) | ||
] | ||
|
||
|
||
def easy_track_executor(creator, factory, calldata): | ||
tx = contracts.easy_track.createMotion( | ||
factory, | ||
calldata, | ||
{'from': creator}, | ||
) | ||
|
||
motions = contracts.easy_track.getMotions() | ||
|
||
chain.sleep(60 * 60 * 24 * 3) | ||
chain.mine() | ||
|
||
contracts.easy_track.enactMotion( | ||
motions[-1][0], | ||
tx.events['MotionCreated']['_evmScriptCallData'], | ||
{'from': accounts[4]}, | ||
) | ||
|
||
|
||
def add_node_operators(operators): | ||
calldata = _encode_calldata( | ||
'(uint256,(string,address,address)[])', | ||
[ | ||
contracts.simple_dvt.getNodeOperatorsCount(), | ||
[ | ||
(no['name'], no['address'], no['manager']) | ||
for no in NODE_OPERATORS | ||
], | ||
] | ||
) | ||
|
||
factory = interface.AddNodeOperators(EASYTRACK_SIMPLE_DVT_ADD_NODE_OPERATORS_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def activate_node_operators(operators): | ||
calldata = _encode_calldata( | ||
'((uint256,address)[])', | ||
[[(no['id'], no['manager']) for no in operators]], | ||
) | ||
|
||
factory = interface.ActivateNodeOperators(EASYTRACK_SIMPLE_DVT_ACTIVATE_NODE_OPERATORS_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def deactivate_node_operator(operators): | ||
calldata = _encode_calldata( | ||
'((uint256,address)[])', | ||
[[(no['id'], no['manager']) for no in operators]], | ||
) | ||
|
||
factory = interface.DeactivateNodeOperators(EASYTRACK_SIMPLE_DVT_DEACTIVATE_NODE_OPERATORS_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def set_vetted_validators_limits(operators): | ||
calldata = _encode_calldata( | ||
'((uint256,uint256)[])', | ||
[[(no['id'], no['staking_limit']) for no in operators]] | ||
) | ||
|
||
factory = interface.SetVettedValidatorsLimits(EASYTRACK_SIMPLE_DVT_SET_VETTED_VALIDATORS_LIMITS_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def set_node_operators_names(operators): | ||
calldata = _encode_calldata( | ||
'((uint256,string)[])', | ||
[[(no['id'], no['name']) for no in operators]], | ||
) | ||
|
||
factory = interface.SetNodeOperatorNames(EASYTRACK_SIMPLE_DVT_SET_NODE_OPERATOR_NAMES_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def set_node_operator_reward_addresses(operators): | ||
calldata = _encode_calldata( | ||
'((uint256,address)[])', | ||
[[(no['id'], no['address']) for no in operators]], | ||
) | ||
|
||
factory = interface.SetNodeOperatorRewardAddresses(EASYTRACK_SIMPLE_DVT_SET_NODE_OPERATOR_REWARD_ADDRESSES_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def update_target_validators_limits(operators): | ||
calldata = _encode_calldata( | ||
'((uint256,bool,uint256)[])', | ||
[[(no['id'], no['is_target_limit_active'], no['target_limit']) for no in operators]], | ||
) | ||
|
||
factory = interface.UpdateTargetValidatorLimits(EASYTRACK_SIMPLE_DVT_UPDATE_TARGET_VALIDATOR_LIMITS_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def change_node_operator_managers(operators): | ||
calldata = _encode_calldata( | ||
'((uint256,address,address)[])', | ||
[[(no['id'], no['old_manager'], no['manager']) for no in operators]], | ||
) | ||
|
||
factory = interface.ChangeNodeOperatorManagers(EASYTRACK_SIMPLE_DVT_CHANGE_NODE_OPERATOR_MANAGERS_FACTORY) | ||
|
||
easy_track_executor( | ||
factory.trustedCaller(), | ||
factory, | ||
calldata, | ||
) | ||
|
||
|
||
def test_add_node_operators(): | ||
# AddNodeOperators | ||
node_operators_count = contracts.simple_dvt.getNodeOperatorsCount() | ||
|
||
add_node_operators(NODE_OPERATORS) | ||
|
||
no_ids = list(contracts.simple_dvt.getNodeOperatorIds(1, 100))[node_operators_count - 1:] | ||
|
||
for no_id, no in zip(no_ids, NODE_OPERATORS): | ||
no_in_contract = contracts.simple_dvt.getNodeOperator(no_id, True) | ||
|
||
assert no_in_contract[0] | ||
assert no_in_contract[1] == no['name'] | ||
assert no_in_contract[2] == no['address'] | ||
|
||
assert node_operators_count + len(NODE_OPERATORS) == contracts.simple_dvt.getNodeOperatorsCount() | ||
|
||
|
||
def test_node_operators_activations(): | ||
assert contracts.simple_dvt.getNodeOperator(1, True)[0] | ||
assert contracts.simple_dvt.getNodeOperator(2, True)[0] | ||
|
||
deactivate_node_operator([{ | ||
'id': 1, | ||
'manager': MANAGERS[1], | ||
}, { | ||
'id': 2, | ||
'manager': MANAGERS[2], | ||
}]) | ||
|
||
assert not contracts.simple_dvt.getNodeOperator(1, True)[0] | ||
assert not contracts.simple_dvt.getNodeOperator(2, True)[0] | ||
|
||
# ActivateNodeOperators | ||
activate_node_operators([{ | ||
'id': 1, | ||
'manager': MANAGERS[1], | ||
}, { | ||
'id': 2, | ||
'manager': MANAGERS[2], | ||
}]) | ||
|
||
assert contracts.simple_dvt.getNodeOperator(1, True)[0] | ||
assert contracts.simple_dvt.getNodeOperator(2, True)[0] | ||
|
||
|
||
def test_set_vetted_validators_limits(): | ||
op_1 = contracts.simple_dvt.getNodeOperator(1, True) | ||
op_2 = contracts.simple_dvt.getNodeOperator(2, True) | ||
|
||
new_vetted_keys_1 = random.randint(0, op_1[5]) | ||
new_vetted_keys_2 = random.randint(0, op_2[5]) | ||
|
||
set_vetted_validators_limits([{ | ||
'id': 1, | ||
'staking_limit': new_vetted_keys_1, | ||
}, { | ||
'id': 2, | ||
'staking_limit': new_vetted_keys_2, | ||
}]) | ||
|
||
assert contracts.simple_dvt.getNodeOperator(1, True)[3] == new_vetted_keys_1 | ||
assert contracts.simple_dvt.getNodeOperator(2, True)[3] == new_vetted_keys_2 | ||
|
||
|
||
def test_set_node_operator_names(): | ||
op_1 = contracts.simple_dvt.getNodeOperator(1, True) | ||
op_2 = contracts.simple_dvt.getNodeOperator(2, True) | ||
|
||
new_name_1 = op_1[1] + ' new 1' | ||
new_name_2 = op_2[1] + ' new 2' | ||
|
||
# SetNodeOperatorNames | ||
set_node_operators_names([{ | ||
'id': 1, | ||
'name': new_name_1, | ||
}, { | ||
'id': 2, | ||
'name': new_name_2, | ||
}]) | ||
|
||
assert contracts.simple_dvt.getNodeOperator(1, True)[1] == new_name_1 | ||
assert contracts.simple_dvt.getNodeOperator(2, True)[1] == new_name_2 | ||
|
||
|
||
def test_set_node_operator_reward_addresses(): | ||
address_1 = '0x0000000000000000000000000000000000001333' | ||
address_2 = '0x0000000000000000000000000000000000001999' | ||
|
||
# SetNodeOperatorRewardAddresses | ||
set_node_operator_reward_addresses([{ | ||
'id': 1, | ||
'address': address_1, | ||
}, { | ||
'id': 2, | ||
'address': address_2, | ||
}]) | ||
|
||
assert contracts.simple_dvt.getNodeOperator(1, True)[2] == address_1 | ||
assert contracts.simple_dvt.getNodeOperator(2, True)[2] == address_2 | ||
|
||
|
||
def test_update_target_validator_limits(): | ||
# UpdateTargetValidatorLimits | ||
update_target_validators_limits([{ | ||
'id': 1, | ||
'is_target_limit_active': True, | ||
'target_limit': 800, | ||
}, { | ||
'id': 2, | ||
'is_target_limit_active': False, | ||
'target_limit': 900, | ||
}]) | ||
|
||
# assert contracts.simple_dvt.getNodeOperator(1, True)[1] == address_1 | ||
# assert contracts.simple_dvt.getNodeOperator(2, True)[2] == address_2 | ||
|
||
|
||
def test_transfer_node_operator_manager(): | ||
# TransferNodeOperatorManager | ||
change_node_operator_managers([{ | ||
'id': 1, | ||
'old_manager': MANAGERS[1], | ||
'manager': '0x0000000000000000000000000000000000000222' | ||
}, { | ||
'id': 2, | ||
'old_manager': MANAGERS[2], | ||
'manager': '0x0000000000000000000000000000000000000888' | ||
}]) | ||
|
||
change_node_operator_managers([{ | ||
'id': 1, | ||
'old_manager': '0x0000000000000000000000000000000000000222', | ||
'manager': MANAGERS[1] | ||
}, { | ||
'id': 2, | ||
'old_manager': '0x0000000000000000000000000000000000000888', | ||
'manager': MANAGERS[2] | ||
}]) | ||
|
||
try: | ||
change_node_operator_managers([{ | ||
'id': 1, | ||
'old_manager': '0x0000000000000000000000000000000000000222', | ||
'manager': MANAGERS[1] | ||
}, { | ||
'id': 2, | ||
'old_manager': '0x0000000000000000000000000000000000000888', | ||
'manager': MANAGERS[2] | ||
}]) | ||
except VirtualMachineError as error: | ||
assert 'OLD_MANAGER_HAS_NO_ROLE' in error.message |
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
Oops, something went wrong.