From f0cf3ab51a49651ef69061a9ccdc2c5c8a2e1a99 Mon Sep 17 00:00:00 2001 From: Nikita P Date: Fri, 8 Nov 2024 10:20:06 +0000 Subject: [PATCH 1/8] feat: added script + tests for Nov aragon --- scripts/vote_2024_11_26.py | 168 +++++++++++++++++++++++++++ tests/test_2024_11_26.py | 110 ++++++++++++++++++ utils/allowed_recipients_registry.py | 3 + 3 files changed, 281 insertions(+) create mode 100644 scripts/vote_2024_11_26.py create mode 100644 tests/test_2024_11_26.py diff --git a/scripts/vote_2024_11_26.py b/scripts/vote_2024_11_26.py new file mode 100644 index 00000000..e8568df1 --- /dev/null +++ b/scripts/vote_2024_11_26.py @@ -0,0 +1,168 @@ +""" +Voting 26/11/2024. + +I. Change the limits for ET on ATC & PML +1. ATC: increase from 1,5m per quarter to 7m USDC/USDT/DAI per quarter - set 7'000'000 limit on ATC registry `0xe07305F43B11F230EaA951002F6a55a16419B707` for 3 mos +2. PML: decrease from 6m per quarter to 4m USDC/USDT/DAI per quarter - set 4'000'000 limit on PML registry `0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB` for 3 mos + +II. TMC limits update +3. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` +4. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos + +III. Simply staking reward address change +5. Change staking reward address to `0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82` for node operator with id = 16 + +Vote passed & executed on XXX-XX-XXXX XX:XX:XX PM UTC, block #XXXXXXXX. +""" + +import time + +from typing import Dict, Tuple, Optional, List + +from brownie import interface +from brownie.network.transaction import TransactionReceipt +from utils.voting import bake_vote_items, confirm_vote_script, create_vote +from utils.easy_track import add_evmscript_factory, create_permissions +from utils.permission_parameters import Param, SpecialArgumentID, ArgumentValue, Op +from utils.ipfs import upload_vote_ipfs_description, calculate_vote_ipfs_description +from utils.node_operators import encode_set_node_operator_reward_address + +from utils.config import ( + get_deployer_account, + contracts, + get_is_live, + get_priority_fee, +) + +from utils.easy_track import ( + add_evmscript_factory, + create_permissions, + remove_evmscript_factory +) +from utils.allowed_recipients_registry import ( + set_limit_parameters, + update_spent_amount, + unsafe_set_spent_amount +) + +from utils.agent import agent_forward + +description = """ +I. Change the limits for ET on ATC & PML +1. ATC: increase from 1,5m per quarter to 7m USDC/USDT/DAI per quarter - set 7'000'000 limit on ATC registry `0xe07305F43B11F230EaA951002F6a55a16419B707` for 3 mos +2. PML: decrease from 6m per quarter to 4m USDC/USDT/DAI per quarter - set 4'000'000 limit on PML registry `0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB` for 3 mos + +II. TMC limits update +3. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos +4. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` + +III. Simply staking reward address change +5. Change staking reward address to `0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82` for node operator with id = 16 +""" + +def start_vote(tx_params: Dict[str, str], silent: bool) -> bool | list[int | TransactionReceipt | None]: + """Prepare and run voting.""" + + atc_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707") + pml_registry = interface.AllowedRecipientRegistry("0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB") + + tmc_registry = interface.AllowedRecipientRegistry("0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0") + + NO_registry = contracts.node_operators_registry + SimplyStaking_id = 16 + SimplyStaking_new_reward_address = "0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82" + + vote_desc_items, call_script_items = zip( + # + # I. Change the limits for ET on ATC & PML + # + ( + "1. Set 7'000'000 limit on ATC registry `0xe07305F43B11F230EaA951002F6a55a16419B707` for 3 mos", + agent_forward( + [ + set_limit_parameters( + registry_address=atc_registry, + limit=7_000_000 * 10 ** 18, + period_duration_months=3 + ), + ] + ), + ), + ( + "2. Set 4'000'000 limit on PML registry `0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB` for 3 mos", + agent_forward( + [ + set_limit_parameters( + registry_address=pml_registry, + limit=4_000_000 * 10 ** 18, + period_duration_months=3 + ), + ] + ), + ), + # + # II. TMC limits update + # + ( + "3. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos", + agent_forward( + [ + set_limit_parameters( + registry_address=tmc_registry, + limit=12_000 * 10 ** 18, + period_duration_months=6 + ), + ] + ), + ), + ( + "4. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0`", + agent_forward( + [ + unsafe_set_spent_amount( + spent_amount=0, + registry_address=tmc_registry + ), + ] + ), + ), + # + # III. Simply staking reward address change + # + ( + "5. Change staking reward address to `0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82` for node operator with id = 16", + agent_forward( + [ + encode_set_node_operator_reward_address( + SimplyStaking_id, + SimplyStaking_new_reward_address, + NO_registry + ), + ] + ), + ), + ) + + vote_items = bake_vote_items(list(vote_desc_items), list(call_script_items)) + + if silent: + desc_ipfs = calculate_vote_ipfs_description(description) + else: + desc_ipfs = upload_vote_ipfs_description(description) + + return confirm_vote_script(vote_items, silent, desc_ipfs) and list( + create_vote(vote_items, tx_params, desc_ipfs=desc_ipfs) + ) + + +def main(): + tx_params = {"from": get_deployer_account()} + + if get_is_live(): + tx_params["priority_fee"] = get_priority_fee() + + vote_id, _ = start_vote(tx_params=tx_params, silent=False) + + vote_id >= 0 and print(f"Vote created: {vote_id}.") + + time.sleep(5) # hack for waiting thread #2. \ No newline at end of file diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py new file mode 100644 index 00000000..338b747b --- /dev/null +++ b/tests/test_2024_11_26.py @@ -0,0 +1,110 @@ +""" +Tests for voting 26/11/2024. +""" + +from scripts.vote_2024_11_26 import start_vote +from brownie import interface, ZERO_ADDRESS, reverts, web3, accounts, convert +from utils.test.tx_tracing_helpers import * +from utils.voting import find_metadata_by_vote_id +from utils.ipfs import get_lido_vote_cid_from_str +from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS, network_name +from utils.easy_track import create_permissions +from utils.test.easy_track_helpers import create_and_enact_payment_motion, check_add_and_remove_recipient_with_voting +from utils.test.event_validators.easy_track import ( + validate_evmscript_factory_added_event, + EVMScriptFactoryAdded, + validate_evmscript_factory_removed_event, +) +from utils.test.event_validators.allowed_recipients_registry import ( + validate_set_limit_parameter_event +) +from configs.config_holesky import ( + DAI_TOKEN, + USDC_TOKEN, + USDT_TOKEN, +) + + +# STETH_TRANSFER_MAX_DELTA = 2 + +def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass_events_decoding): + + # NO's data indexes + activeIndex = 0 + nameIndex = 1 + rewardAddressIndex = 2 + stakingLimitIndex = 3 + stoppedValidatorsIndex = 4 + + nor = contracts.node_operators_registry + + # easy_track = interface.EasyTrack("0xF0211b7660680B49De1A7E9f25C65660F0a13Fea") + + atc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707") + pml_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB") + tmc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0") + #atc_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x1843Bc35d1fD15AbE1913b9f72852a79457C42Ab") + atc_multisig_acc = accounts.at("0x9B1cebF7616f2BC73b47D226f90b01a7c9F86956", force=True) + #atc_trusted_caller_acc = atc_multisig_acc + SimplyStakingId = 16 + SimplyStakingOldRewardAddress = "0xFEf3C7aa6956D03dbad8959c59155c4A465DCacd" + SimplyStakingNewRewardAddress = "0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82" + + # Item 1 + atcBudgetLimitBefore, atcPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() + assert atcBudgetLimitBefore == 1_500_000 * 10 ** 18 + assert atcPeriodDurationMonthsBefore == 3 + + # Item 2 + pmlBudgetLimitBefore, pmlPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() + assert pmlBudgetLimitBefore == 6_000_000 * 10 ** 18 + assert pmlPeriodDurationMonthsBefore == 3 + + # Item 3 + tmcBudgetLimitBefore, tmcPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() + assert tmcBudgetLimitBefore == 9_000 * 10 ** 18 + assert tmcPeriodDurationMonthsBefore == 6 + + # Item 4 + alreadySpentAmountBefore, spendableBalanceInPeriodBefore, periodStartTimestampBefore, periodEndTimestampBefore = tmc_allowed_recipients_registry.getPeriodState() + assert alreadySpentAmountBefore > 0 + + # Item 5 + SimplyStakingDataBefore = nor.getNodeOperator(SimplyStakingId, True) + assert SimplyStakingOldRewardAddress == SimplyStakingDataBefore[rewardAddressIndex] + + + # START VOTE + if len(vote_ids_from_env) > 0: + (vote_id,) = vote_ids_from_env + else: + tx_params = {"from": LDO_HOLDER_ADDRESS_FOR_TESTS} + vote_id, _ = start_vote(tx_params, silent=True) + + vote_tx = helpers.execute_vote(accounts, vote_id, contracts.voting) + + print(f"voteId = {vote_id}, gasUsed = {vote_tx.gas_used}") + + + # Item 1 + atcBudgetLimitAfter, atcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() + assert atcBudgetLimitAfter == 7_000_000 * 10 ** 18 + assert atcPeriodDurationMonthsAfter == 3 + + # Item 2 + pmlBudgetLimitAfter, pmlPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() + assert pmlBudgetLimitAfter == 4_000_000 * 10 ** 18 + assert pmlPeriodDurationMonthsAfter == 3 + + # Item 3 + tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() + assert tmcBudgetLimitAfter == 12_000 * 10 ** 18 + assert tmcPeriodDurationMonthsAfter == 6 + + # Item 4 + alreadySpentAmountAfter, spendableBalanceInPeriodAfter, periodStartTimestampAfter, periodEndTimestampAfter = tmc_allowed_recipients_registry.getPeriodState() + assert alreadySpentAmountAfter == 0 + + # Item 5 + SimplyStakingDataAfter = nor.getNodeOperator(SimplyStakingId, True) + assert SimplyStakingNewRewardAddress == SimplyStakingDataAfter[rewardAddressIndex] \ No newline at end of file diff --git a/utils/allowed_recipients_registry.py b/utils/allowed_recipients_registry.py index 40b11d86..3d4c5576 100644 --- a/utils/allowed_recipients_registry.py +++ b/utils/allowed_recipients_registry.py @@ -14,6 +14,9 @@ def update_spent_amount(registry_address: str, spent_amount: int) -> Tuple[str, registry = interface.AllowedRecipientRegistry(registry_address) return (registry.address, registry.updateSpentAmount.encode_input(spent_amount)) +def unsafe_set_spent_amount(registry_address: str, spent_amount: int) -> Tuple[str, str]: + registry = interface.AllowedRecipientRegistry(registry_address) + return (registry.address, registry.unsafeSetSpentAmount.encode_input(spent_amount)) def create_top_up_allowed_recipient_permission(registry_address: str) -> str: return ( From 006f1aa3951549e44c00f49fd416d115dbfb59a4 Mon Sep 17 00:00:00 2001 From: Nikita P Date: Fri, 8 Nov 2024 10:22:49 +0000 Subject: [PATCH 2/8] feat: update test desc --- scripts/vote_2024_11_26.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/vote_2024_11_26.py b/scripts/vote_2024_11_26.py index e8568df1..ef88875e 100644 --- a/scripts/vote_2024_11_26.py +++ b/scripts/vote_2024_11_26.py @@ -6,8 +6,8 @@ 2. PML: decrease from 6m per quarter to 4m USDC/USDT/DAI per quarter - set 4'000'000 limit on PML registry `0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB` for 3 mos II. TMC limits update -3. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` -4. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos +3. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos +4. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` III. Simply staking reward address change 5. Change staking reward address to `0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82` for node operator with id = 16 From 11caa2682544f9b600f52fbdcbd33b6c9657d0c1 Mon Sep 17 00:00:00 2001 From: Nikita P Date: Fri, 8 Nov 2024 16:44:06 +0000 Subject: [PATCH 3/8] feat: more tests --- tests/test_2024_11_26.py | 116 +++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 18 deletions(-) diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py index 338b747b..5c023f7d 100644 --- a/tests/test_2024_11_26.py +++ b/tests/test_2024_11_26.py @@ -9,6 +9,7 @@ from utils.ipfs import get_lido_vote_cid_from_str from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS, network_name from utils.easy_track import create_permissions +from utils.config import contracts from utils.test.easy_track_helpers import create_and_enact_payment_motion, check_add_and_remove_recipient_with_voting from utils.test.event_validators.easy_track import ( validate_evmscript_factory_added_event, @@ -18,38 +19,47 @@ from utils.test.event_validators.allowed_recipients_registry import ( validate_set_limit_parameter_event ) -from configs.config_holesky import ( +from configs.config_mainnet import ( DAI_TOKEN, USDC_TOKEN, USDT_TOKEN, ) -# STETH_TRANSFER_MAX_DELTA = 2 - def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass_events_decoding): - # NO's data indexes - activeIndex = 0 - nameIndex = 1 - rewardAddressIndex = 2 - stakingLimitIndex = 3 - stoppedValidatorsIndex = 4 + easy_track = interface.EasyTrack("0xF0211b7660680B49De1A7E9f25C65660F0a13Fea") nor = contracts.node_operators_registry - # easy_track = interface.EasyTrack("0xF0211b7660680B49De1A7E9f25C65660F0a13Fea") - + # Item 1 atc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707") + atc_multisig_acc = accounts.at("0x9B1cebF7616f2BC73b47D226f90b01a7c9F86956", force=True) + atc_trusted_caller_acc = atc_multisig_acc + atc_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x1843Bc35d1fD15AbE1913b9f72852a79457C42Ab") + atcBudgetLimitAfterExpected = 7_000_000 * 10**18 + atcSpendLimitAfterExpected = 5_500_000 * 10**18 + + # Item 2 pml_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB") + + # Item 3, 4 tmc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0") - #atc_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x1843Bc35d1fD15AbE1913b9f72852a79457C42Ab") - atc_multisig_acc = accounts.at("0x9B1cebF7616f2BC73b47D226f90b01a7c9F86956", force=True) - #atc_trusted_caller_acc = atc_multisig_acc + + # Item 5 + # NO's data indexes + activeIndex = 0 + nameIndex = 1 + rewardAddressIndex = 2 + stakingLimitIndex = 3 + stoppedValidatorsIndex = 4 + # Simply Staking params SimplyStakingId = 16 + SimplyStakingName = "Simply Staking" SimplyStakingOldRewardAddress = "0xFEf3C7aa6956D03dbad8959c59155c4A465DCacd" SimplyStakingNewRewardAddress = "0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82" + # Item 1 atcBudgetLimitBefore, atcPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() assert atcBudgetLimitBefore == 1_500_000 * 10 ** 18 @@ -72,6 +82,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass # Item 5 SimplyStakingDataBefore = nor.getNodeOperator(SimplyStakingId, True) assert SimplyStakingOldRewardAddress == SimplyStakingDataBefore[rewardAddressIndex] + assert SimplyStakingName == SimplyStakingDataBefore[nameIndex] # START VOTE @@ -80,31 +91,100 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass else: tx_params = {"from": LDO_HOLDER_ADDRESS_FOR_TESTS} vote_id, _ = start_vote(tx_params, silent=True) - vote_tx = helpers.execute_vote(accounts, vote_id, contracts.voting) - print(f"voteId = {vote_id}, gasUsed = {vote_tx.gas_used}") # Item 1 atcBudgetLimitAfter, atcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() - assert atcBudgetLimitAfter == 7_000_000 * 10 ** 18 + (already_spent, spend_limit, period_start, period_end) = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getPeriodState() + atcSpendableBalanceAfter = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).spendableBalance() + assert atcBudgetLimitAfter == atcBudgetLimitAfterExpected assert atcPeriodDurationMonthsAfter == 3 + assert spend_limit == atcSpendLimitAfterExpected + assert interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).isUnderSpendableBalance(atcSpendableBalanceAfter, 3) + assert atcSpendableBalanceAfter == atcSpendLimitAfterExpected + limit_test(easy_track, int(atcSpendableBalanceAfter / (10**18)), atc_trusted_caller_acc, atc_top_up_evm_script_factory, atc_multisig_acc, stranger) # Item 2 pmlBudgetLimitAfter, pmlPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() assert pmlBudgetLimitAfter == 4_000_000 * 10 ** 18 assert pmlPeriodDurationMonthsAfter == 3 + # TODO limit_test # Item 3 tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() assert tmcBudgetLimitAfter == 12_000 * 10 ** 18 assert tmcPeriodDurationMonthsAfter == 6 + # TODO limit_test # Item 4 alreadySpentAmountAfter, spendableBalanceInPeriodAfter, periodStartTimestampAfter, periodEndTimestampAfter = tmc_allowed_recipients_registry.getPeriodState() assert alreadySpentAmountAfter == 0 + # TODO limit_test # Item 5 SimplyStakingDataAfter = nor.getNodeOperator(SimplyStakingId, True) - assert SimplyStakingNewRewardAddress == SimplyStakingDataAfter[rewardAddressIndex] \ No newline at end of file + assert SimplyStakingNewRewardAddress == SimplyStakingDataAfter[rewardAddressIndex] + assert SimplyStakingDataBefore[nameIndex] == SimplyStakingDataAfter[nameIndex] + assert SimplyStakingDataBefore[activeIndex] == SimplyStakingDataAfter[activeIndex] + assert SimplyStakingDataBefore[stakingLimitIndex] == SimplyStakingDataAfter[stakingLimitIndex] + assert SimplyStakingDataBefore[stoppedValidatorsIndex] == SimplyStakingDataAfter[stoppedValidatorsIndex] + # TODO limit_test + + + # events + display_voting_events(vote_tx) + evs = group_voting_events(vote_tx) + + validate_set_limit_parameter_event( + evs[0], + limit=atcBudgetLimitAfterExpected, + period_duration_month=3, + period_start_timestamp=1727740800, + ) + # TODO more events + +def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger): + + # can't spend more than 2M USDC at once + max_usdc_spend_at_once = 2_000_000 * 10**6 + + to_spend_usdc = to_spend * 10**6 + + # check that there is no way to spend more USDC + with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): + create_and_enact_payment_motion( + easy_track, + trusted_caller_acc, + top_up_evm_script_factory, + interface.Usdc(USDC_TOKEN), + [multisig_acc], + [to_spend_usdc + 1], + stranger, + ) + + # spend all USDC step by step (at most 2M each time) + while to_spend_usdc > 0: + create_and_enact_payment_motion( + easy_track, + trusted_caller_acc, + top_up_evm_script_factory, + interface.Usdc(USDC_TOKEN), + [multisig_acc], + [min(max_usdc_spend_at_once, to_spend_usdc)], + stranger, + ) + to_spend_usdc -= min(max_usdc_spend_at_once, to_spend_usdc) + + # make sure there is nothing left so that you can't spend anymore + with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): + create_and_enact_payment_motion( + easy_track, + trusted_caller_acc, + top_up_evm_script_factory, + interface.Usdc(USDC_TOKEN), + [multisig_acc], + [1], + stranger, + ) From b8c7d2bdcc57f530d68b5c80fbc610afb019882f Mon Sep 17 00:00:00 2001 From: Nikita P Date: Sat, 9 Nov 2024 13:12:12 +0000 Subject: [PATCH 4/8] feat: more tests --- tests/test_2024_11_26.py | 122 ++++++++++++++---- .../allowed_recipients_registry.py | 13 ++ .../node_operators_registry.py | 2 +- 3 files changed, 110 insertions(+), 27 deletions(-) diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py index 5c023f7d..9026daa3 100644 --- a/tests/test_2024_11_26.py +++ b/tests/test_2024_11_26.py @@ -3,30 +3,23 @@ """ from scripts.vote_2024_11_26 import start_vote -from brownie import interface, ZERO_ADDRESS, reverts, web3, accounts, convert +from brownie import interface, reverts from utils.test.tx_tracing_helpers import * -from utils.voting import find_metadata_by_vote_id -from utils.ipfs import get_lido_vote_cid_from_str -from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS, network_name -from utils.easy_track import create_permissions +from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS from utils.config import contracts -from utils.test.easy_track_helpers import create_and_enact_payment_motion, check_add_and_remove_recipient_with_voting -from utils.test.event_validators.easy_track import ( - validate_evmscript_factory_added_event, - EVMScriptFactoryAdded, - validate_evmscript_factory_removed_event, -) +from utils.test.easy_track_helpers import create_and_enact_payment_motion from utils.test.event_validators.allowed_recipients_registry import ( - validate_set_limit_parameter_event + validate_set_limit_parameter_event, + validate_set_spent_amount_event, ) -from configs.config_mainnet import ( - DAI_TOKEN, - USDC_TOKEN, - USDT_TOKEN, +from utils.test.event_validators.node_operators_registry import ( + validate_node_operator_reward_address_set_event, + NodeOperatorRewardAddressSetItem ) +from configs.config_mainnet import ( USDC_TOKEN ) -def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass_events_decoding): +def test_vote(helpers, accounts, vote_ids_from_env, stranger): easy_track = interface.EasyTrack("0xF0211b7660680B49De1A7E9f25C65660F0a13Fea") @@ -42,9 +35,19 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass # Item 2 pml_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB") + pml_multisig_acc = accounts.at("0x17F6b2C738a63a8D3A113a228cfd0b373244633D", force=True) + pml_trusted_caller_acc = pml_multisig_acc + pml_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x92a27C4e5e35cFEa112ACaB53851Ec70e2D99a8D") + pmlBudgetLimitAfterExpected = 4_000_000 * 10**18 + pmlSpendLimitAfterExpected = 3_000_000 * 10**18 # Item 3, 4 tmc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0") + tmc_multisig = accounts.at("0xa02FC823cCE0D016bD7e17ac684c9abAb2d6D647", force=True) + tmc_trusted_caller = tmc_multisig + tmc_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x6e04aED774B7c89BB43721AcDD7D03C872a51B69") + stETH_token = interface.ERC20("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84") + stonks_steth_contract = accounts.at("0x3e2D251275A92a8169A3B17A2C49016e2de492a7", force=True) # Item 5 # NO's data indexes @@ -64,11 +67,13 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass atcBudgetLimitBefore, atcPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() assert atcBudgetLimitBefore == 1_500_000 * 10 ** 18 assert atcPeriodDurationMonthsBefore == 3 + assert 0 == interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).spendableBalance() # Item 2 pmlBudgetLimitBefore, pmlPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() assert pmlBudgetLimitBefore == 6_000_000 * 10 ** 18 assert pmlPeriodDurationMonthsBefore == 3 + assert 5_000_000 * 10**18 == interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).spendableBalance() # Item 3 tmcBudgetLimitBefore, tmcPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() @@ -97,31 +102,69 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass # Item 1 atcBudgetLimitAfter, atcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() - (already_spent, spend_limit, period_start, period_end) = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getPeriodState() + atc_spend_limit_after = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getPeriodState()[1] atcSpendableBalanceAfter = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).spendableBalance() assert atcBudgetLimitAfter == atcBudgetLimitAfterExpected assert atcPeriodDurationMonthsAfter == 3 - assert spend_limit == atcSpendLimitAfterExpected + assert atc_spend_limit_after == atcSpendLimitAfterExpected assert interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).isUnderSpendableBalance(atcSpendableBalanceAfter, 3) assert atcSpendableBalanceAfter == atcSpendLimitAfterExpected limit_test(easy_track, int(atcSpendableBalanceAfter / (10**18)), atc_trusted_caller_acc, atc_top_up_evm_script_factory, atc_multisig_acc, stranger) # Item 2 pmlBudgetLimitAfter, pmlPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() - assert pmlBudgetLimitAfter == 4_000_000 * 10 ** 18 + pml_spend_limit_after = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getPeriodState()[1] + pmlSpendableBalanceAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).spendableBalance() + assert pmlBudgetLimitAfter == pmlBudgetLimitAfterExpected assert pmlPeriodDurationMonthsAfter == 3 - # TODO limit_test + assert pml_spend_limit_after == pmlSpendLimitAfterExpected + assert interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).isUnderSpendableBalance(pmlSpendableBalanceAfter, 3) + assert pmlSpendableBalanceAfter == pmlSpendLimitAfterExpected + # TODO + #limit_test(easy_track, int(pmlSpendableBalanceAfter / (10**18)), pml_trusted_caller_acc, pml_top_up_evm_script_factory, pml_multisig_acc, stranger) # Item 3 tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() assert tmcBudgetLimitAfter == 12_000 * 10 ** 18 assert tmcPeriodDurationMonthsAfter == 6 - # TODO limit_test # Item 4 alreadySpentAmountAfter, spendableBalanceInPeriodAfter, periodStartTimestampAfter, periodEndTimestampAfter = tmc_allowed_recipients_registry.getPeriodState() assert alreadySpentAmountAfter == 0 - # TODO limit_test + tmcSpendableBalanceAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance() + assert tmcSpendableBalanceAfter == 12_000 * 10 ** 18 + with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): + create_and_enact_payment_motion( + easy_track, + tmc_trusted_caller, + tmc_top_up_evm_script_factory, + stETH_token, + [stonks_steth_contract], + [12_000 * 10 ** 18 + 1], + stranger, + ) + + for i in range (0, 12): + create_and_enact_payment_motion( + easy_track, + tmc_trusted_caller, + tmc_top_up_evm_script_factory, + stETH_token, + [stonks_steth_contract], + [1_000 * 10 ** 18], + stranger, + ) + + with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): + create_and_enact_payment_motion( + easy_track, + tmc_trusted_caller, + tmc_top_up_evm_script_factory, + stETH_token, + [stonks_steth_contract], + [1], + stranger, + ) # Item 5 SimplyStakingDataAfter = nor.getNodeOperator(SimplyStakingId, True) @@ -130,7 +173,6 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass assert SimplyStakingDataBefore[activeIndex] == SimplyStakingDataAfter[activeIndex] assert SimplyStakingDataBefore[stakingLimitIndex] == SimplyStakingDataAfter[stakingLimitIndex] assert SimplyStakingDataBefore[stoppedValidatorsIndex] == SimplyStakingDataAfter[stoppedValidatorsIndex] - # TODO limit_test # events @@ -143,7 +185,29 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass period_duration_month=3, period_start_timestamp=1727740800, ) - # TODO more events + validate_set_limit_parameter_event( + evs[1], + limit=pmlBudgetLimitAfterExpected, + period_duration_month=3, + period_start_timestamp=1727740800, + ) + validate_set_limit_parameter_event( + evs[2], + limit=12_000 * 10 ** 18, + period_duration_month=6, + period_start_timestamp=1719792000, + ) + validate_set_spent_amount_event( + evs[3], + new_spent_amount=0, + ) + validate_node_operator_reward_address_set_event( + evs[4], + NodeOperatorRewardAddressSetItem( + nodeOperatorId=SimplyStakingId, + reward_address=SimplyStakingNewRewardAddress + ) + ) def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger): @@ -162,7 +226,7 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto [multisig_acc], [to_spend_usdc + 1], stranger, - ) + ) # spend all USDC step by step (at most 2M each time) while to_spend_usdc > 0: @@ -175,8 +239,14 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto [min(max_usdc_spend_at_once, to_spend_usdc)], stranger, ) + print("HERE1") + print (max_usdc_spend_at_once) + print (to_spend_usdc) to_spend_usdc -= min(max_usdc_spend_at_once, to_spend_usdc) + + print ('NEXT') + # make sure there is nothing left so that you can't spend anymore with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): create_and_enact_payment_motion( diff --git a/utils/test/event_validators/allowed_recipients_registry.py b/utils/test/event_validators/allowed_recipients_registry.py index 4c3b709a..f51c0d71 100644 --- a/utils/test/event_validators/allowed_recipients_registry.py +++ b/utils/test/event_validators/allowed_recipients_registry.py @@ -49,3 +49,16 @@ def validate_update_spent_amount_event( assert event["SpendableAmountChanged"]["_spendableBalance"] == spendable_balance_in_period assert event["SpendableAmountChanged"]["_periodStartTimestamp"] == period_start_timestamp assert event["SpendableAmountChanged"]["_periodEndTimestamp"] == period_end_timestamp + +def validate_set_spent_amount_event( + event: EventDict, + new_spent_amount: int, +): + _events_chain = ( + ["LogScriptCall", "LogScriptCall", "SpentAmountChanged", "ScriptResult"] + ) + + validate_events_chain([e.name for e in event], _events_chain) + + assert event.count("SpentAmountChanged") == 1 + assert event["SpentAmountChanged"]["_newSpentAmount"] == new_spent_amount diff --git a/utils/test/event_validators/node_operators_registry.py b/utils/test/event_validators/node_operators_registry.py index 9dfcdbce..43a4c3be 100644 --- a/utils/test/event_validators/node_operators_registry.py +++ b/utils/test/event_validators/node_operators_registry.py @@ -72,7 +72,7 @@ def validate_node_operator_name_set_event( def validate_node_operator_reward_address_set_event( event: EventDict, node_operator_reward_address_item: NodeOperatorRewardAddressSetItem ): - _events_chain = ["LogScriptCall", "KeysOpIndexSet", "NodeOperatorRewardAddressSet"] + _events_chain = ["LogScriptCall", "LogScriptCall", "NodeOperatorRewardAddressSet", "ScriptResult"] validate_events_chain([e.name for e in event], _events_chain) From 5e91ebf26755c22feb8967915795663bf358740b Mon Sep 17 00:00:00 2001 From: Nikita P Date: Sat, 9 Nov 2024 13:19:43 +0000 Subject: [PATCH 5/8] feat: less literals --- tests/test_2024_11_26.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py index 9026daa3..760175a4 100644 --- a/tests/test_2024_11_26.py +++ b/tests/test_2024_11_26.py @@ -48,6 +48,8 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): tmc_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x6e04aED774B7c89BB43721AcDD7D03C872a51B69") stETH_token = interface.ERC20("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84") stonks_steth_contract = accounts.at("0x3e2D251275A92a8169A3B17A2C49016e2de492a7", force=True) + tmcBudgetAfterExpected = 12_000 * 10**18 + tmcNewSpentAmountExpected = 0 # Item 5 # NO's data indexes @@ -125,14 +127,14 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): # Item 3 tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() - assert tmcBudgetLimitAfter == 12_000 * 10 ** 18 + assert tmcBudgetLimitAfter == tmcBudgetAfterExpected assert tmcPeriodDurationMonthsAfter == 6 # Item 4 - alreadySpentAmountAfter, spendableBalanceInPeriodAfter, periodStartTimestampAfter, periodEndTimestampAfter = tmc_allowed_recipients_registry.getPeriodState() - assert alreadySpentAmountAfter == 0 + alreadySpentAmountAfter = tmc_allowed_recipients_registry.getPeriodState()[0] + assert alreadySpentAmountAfter == tmcNewSpentAmountExpected tmcSpendableBalanceAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance() - assert tmcSpendableBalanceAfter == 12_000 * 10 ** 18 + assert tmcSpendableBalanceAfter == tmcBudgetAfterExpected with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): create_and_enact_payment_motion( easy_track, @@ -140,7 +142,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): tmc_top_up_evm_script_factory, stETH_token, [stonks_steth_contract], - [12_000 * 10 ** 18 + 1], + [tmcBudgetAfterExpected + 1], stranger, ) @@ -193,13 +195,13 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): ) validate_set_limit_parameter_event( evs[2], - limit=12_000 * 10 ** 18, + limit=tmcBudgetAfterExpected, period_duration_month=6, period_start_timestamp=1719792000, ) validate_set_spent_amount_event( evs[3], - new_spent_amount=0, + new_spent_amount=tmcNewSpentAmountExpected, ) validate_node_operator_reward_address_set_event( evs[4], From cbfdc88247a1acd77a149255be5e108a0a2c66d5 Mon Sep 17 00:00:00 2001 From: Nikita P Date: Sat, 9 Nov 2024 14:11:36 +0000 Subject: [PATCH 6/8] feat: fixed comments --- tests/test_2024_11_26.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py index 760175a4..5f38091b 100644 --- a/tests/test_2024_11_26.py +++ b/tests/test_2024_11_26.py @@ -16,7 +16,7 @@ validate_node_operator_reward_address_set_event, NodeOperatorRewardAddressSetItem ) -from configs.config_mainnet import ( USDC_TOKEN ) +from configs.config_mainnet import ( USDC_TOKEN, USDT_TOKEN ) def test_vote(helpers, accounts, vote_ids_from_env, stranger): @@ -111,7 +111,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): assert atc_spend_limit_after == atcSpendLimitAfterExpected assert interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).isUnderSpendableBalance(atcSpendableBalanceAfter, 3) assert atcSpendableBalanceAfter == atcSpendLimitAfterExpected - limit_test(easy_track, int(atcSpendableBalanceAfter / (10**18)), atc_trusted_caller_acc, atc_top_up_evm_script_factory, atc_multisig_acc, stranger) + limit_test(easy_track, int(atcSpendableBalanceAfter / (10**18)), atc_trusted_caller_acc, atc_top_up_evm_script_factory, atc_multisig_acc, stranger, interface.Usdc(USDC_TOKEN)) # Item 2 pmlBudgetLimitAfter, pmlPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() @@ -122,8 +122,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): assert pml_spend_limit_after == pmlSpendLimitAfterExpected assert interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).isUnderSpendableBalance(pmlSpendableBalanceAfter, 3) assert pmlSpendableBalanceAfter == pmlSpendLimitAfterExpected - # TODO - #limit_test(easy_track, int(pmlSpendableBalanceAfter / (10**18)), pml_trusted_caller_acc, pml_top_up_evm_script_factory, pml_multisig_acc, stranger) + #limit_test(easy_track, int(pmlSpendableBalanceAfter / (10**18)), pml_trusted_caller_acc, pml_top_up_evm_script_factory, pml_multisig_acc, stranger, interface.Usdt(USDT_TOKEN)) # Item 3 tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() @@ -211,7 +210,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): ) ) -def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger): +def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger, token): # can't spend more than 2M USDC at once max_usdc_spend_at_once = 2_000_000 * 10**6 @@ -224,7 +223,7 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto easy_track, trusted_caller_acc, top_up_evm_script_factory, - interface.Usdc(USDC_TOKEN), + token, [multisig_acc], [to_spend_usdc + 1], stranger, @@ -236,26 +235,20 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto easy_track, trusted_caller_acc, top_up_evm_script_factory, - interface.Usdc(USDC_TOKEN), + token, [multisig_acc], [min(max_usdc_spend_at_once, to_spend_usdc)], stranger, ) - print("HERE1") - print (max_usdc_spend_at_once) - print (to_spend_usdc) to_spend_usdc -= min(max_usdc_spend_at_once, to_spend_usdc) - - print ('NEXT') - # make sure there is nothing left so that you can't spend anymore with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): create_and_enact_payment_motion( easy_track, trusted_caller_acc, top_up_evm_script_factory, - interface.Usdc(USDC_TOKEN), + token, [multisig_acc], [1], stranger, From 9f275f2a66c04609b9393711ec07672cfe1aaae5 Mon Sep 17 00:00:00 2001 From: Nikita P Date: Sat, 9 Nov 2024 15:35:33 +0000 Subject: [PATCH 7/8] feat: fixed usdc/usdt transfers --- tests/test_2024_11_26.py | 47 +++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py index 5f38091b..fc85cbd2 100644 --- a/tests/test_2024_11_26.py +++ b/tests/test_2024_11_26.py @@ -3,7 +3,7 @@ """ from scripts.vote_2024_11_26 import start_vote -from brownie import interface, reverts +from brownie import interface, reverts, accounts, ZERO_ADDRESS from utils.test.tx_tracing_helpers import * from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS from utils.config import contracts @@ -16,14 +16,16 @@ validate_node_operator_reward_address_set_event, NodeOperatorRewardAddressSetItem ) -from configs.config_mainnet import ( USDC_TOKEN, USDT_TOKEN ) +from configs.config_mainnet import ( USDC_TOKEN ) def test_vote(helpers, accounts, vote_ids_from_env, stranger): + # misc easy_track = interface.EasyTrack("0xF0211b7660680B49De1A7E9f25C65660F0a13Fea") - nor = contracts.node_operators_registry + prepare_agent_for_usdc_payment(2_000_000_000 * (10**6)) + prepare_agent_for_steth_payment(100_000 * 10**18) # Item 1 atc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707") @@ -111,7 +113,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): assert atc_spend_limit_after == atcSpendLimitAfterExpected assert interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).isUnderSpendableBalance(atcSpendableBalanceAfter, 3) assert atcSpendableBalanceAfter == atcSpendLimitAfterExpected - limit_test(easy_track, int(atcSpendableBalanceAfter / (10**18)), atc_trusted_caller_acc, atc_top_up_evm_script_factory, atc_multisig_acc, stranger, interface.Usdc(USDC_TOKEN)) + limit_test(easy_track, int(atcSpendableBalanceAfter / (10**18)), atc_trusted_caller_acc, atc_top_up_evm_script_factory, atc_multisig_acc, stranger) # Item 2 pmlBudgetLimitAfter, pmlPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() @@ -122,7 +124,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): assert pml_spend_limit_after == pmlSpendLimitAfterExpected assert interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).isUnderSpendableBalance(pmlSpendableBalanceAfter, 3) assert pmlSpendableBalanceAfter == pmlSpendLimitAfterExpected - #limit_test(easy_track, int(pmlSpendableBalanceAfter / (10**18)), pml_trusted_caller_acc, pml_top_up_evm_script_factory, pml_multisig_acc, stranger, interface.Usdt(USDT_TOKEN)) + #limit_test(easy_track, int(pmlSpendableBalanceAfter / (10**18)), pml_trusted_caller_acc, pml_top_up_evm_script_factory, pml_multisig_acc, stranger) # Item 3 tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() @@ -145,7 +147,8 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): stranger, ) - for i in range (0, 12): + print ('Spendable balance before 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) + for i in range (12): create_and_enact_payment_motion( easy_track, tmc_trusted_caller, @@ -155,7 +158,9 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): [1_000 * 10 ** 18], stranger, ) + print ('Spendable balance on 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) + print ('Spendable balance after 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): create_and_enact_payment_motion( easy_track, @@ -166,6 +171,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): [1], stranger, ) + print ('Spendable balance after-after 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) # Item 5 SimplyStakingDataAfter = nor.getNodeOperator(SimplyStakingId, True) @@ -210,7 +216,7 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): ) ) -def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger, token): +def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger): # can't spend more than 2M USDC at once max_usdc_spend_at_once = 2_000_000 * 10**6 @@ -223,7 +229,7 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto easy_track, trusted_caller_acc, top_up_evm_script_factory, - token, + interface.Usdc(USDC_TOKEN), [multisig_acc], [to_spend_usdc + 1], stranger, @@ -235,7 +241,7 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto easy_track, trusted_caller_acc, top_up_evm_script_factory, - token, + interface.Usdc(USDC_TOKEN), [multisig_acc], [min(max_usdc_spend_at_once, to_spend_usdc)], stranger, @@ -248,8 +254,29 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto easy_track, trusted_caller_acc, top_up_evm_script_factory, - token, + interface.Usdc(USDC_TOKEN), [multisig_acc], [1], stranger, ) + +STETH_TRANSFER_MAX_DELTA = 2 + +def prepare_agent_for_steth_payment(amount: int): + agent, steth = contracts.agent, contracts.lido + eth_whale = accounts.at("0x00000000219ab540356cBB839Cbe05303d7705Fa", force=True) + if steth.balanceOf(agent) < amount: + steth.submit(ZERO_ADDRESS, {"from": eth_whale, "value": amount + 2 * STETH_TRANSFER_MAX_DELTA}) + steth.transfer(agent, amount + STETH_TRANSFER_MAX_DELTA, {"from": eth_whale}) + assert steth.balanceOf(agent) >= amount, "Insufficient stETH balance" + +def prepare_agent_for_usdc_payment(amount: int): + agent, usdc = contracts.agent, interface.Usdc(USDC_TOKEN) + if usdc.balanceOf(agent) < amount: + usdc_minter = accounts.at("0x5B6122C109B78C6755486966148C1D70a50A47D7", force=True) + usdc_controller = accounts.at("0x79E0946e1C186E745f1352d7C21AB04700C99F71", force=True) + usdc_master_minter = interface.UsdcMasterMinter("0xE982615d461DD5cD06575BbeA87624fda4e3de17") + usdc_master_minter.incrementMinterAllowance(amount, {"from": usdc_controller}) + usdc.mint(agent, amount, {"from": usdc_minter}) + + assert usdc.balanceOf(agent) >= amount, "Insufficient USDC balance" \ No newline at end of file From 3ef12ca113a4a12831e2e1e4ab3a8b7335d7ca21 Mon Sep 17 00:00:00 2001 From: Nikita P Date: Sun, 10 Nov 2024 16:01:30 +0000 Subject: [PATCH 8/8] feat: fixed tests --- tests/test_2024_11_26.py | 105 ++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 57 deletions(-) diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py index fc85cbd2..92c34a96 100644 --- a/tests/test_2024_11_26.py +++ b/tests/test_2024_11_26.py @@ -3,7 +3,7 @@ """ from scripts.vote_2024_11_26 import start_vote -from brownie import interface, reverts, accounts, ZERO_ADDRESS +from brownie import interface, reverts, accounts, ZERO_ADDRESS, chain, web3 from utils.test.tx_tracing_helpers import * from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS from utils.config import contracts @@ -18,14 +18,15 @@ ) from configs.config_mainnet import ( USDC_TOKEN ) +STETH_TRANSFER_MAX_DELTA = 2 def test_vote(helpers, accounts, vote_ids_from_env, stranger): # misc easy_track = interface.EasyTrack("0xF0211b7660680B49De1A7E9f25C65660F0a13Fea") nor = contracts.node_operators_registry - prepare_agent_for_usdc_payment(2_000_000_000 * (10**6)) - prepare_agent_for_steth_payment(100_000 * 10**18) + prepare_agent_for_usdc_payment(15_000_000 * (10**6)) + prepare_agent_for_steth_payment(20_000 * 10**18) # Item 1 atc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707") @@ -113,7 +114,15 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): assert atc_spend_limit_after == atcSpendLimitAfterExpected assert interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).isUnderSpendableBalance(atcSpendableBalanceAfter, 3) assert atcSpendableBalanceAfter == atcSpendLimitAfterExpected - limit_test(easy_track, int(atcSpendableBalanceAfter / (10**18)), atc_trusted_caller_acc, atc_top_up_evm_script_factory, atc_multisig_acc, stranger) + limit_test(easy_track, + int(atcSpendableBalanceAfter / (10**18)) * 10**6, + atc_trusted_caller_acc, + atc_top_up_evm_script_factory, + atc_multisig_acc, + stranger, + interface.Usdc(USDC_TOKEN), + 2_000_000 * 10**6 + ) # Item 2 pmlBudgetLimitAfter, pmlPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() @@ -124,7 +133,15 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): assert pml_spend_limit_after == pmlSpendLimitAfterExpected assert interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).isUnderSpendableBalance(pmlSpendableBalanceAfter, 3) assert pmlSpendableBalanceAfter == pmlSpendLimitAfterExpected - #limit_test(easy_track, int(pmlSpendableBalanceAfter / (10**18)), pml_trusted_caller_acc, pml_top_up_evm_script_factory, pml_multisig_acc, stranger) + limit_test(easy_track, + int(pmlSpendableBalanceAfter / (10**18)) * 10**6, + pml_trusted_caller_acc, + pml_top_up_evm_script_factory, + pml_multisig_acc, + stranger, + interface.Usdc(USDC_TOKEN), + 2_000_000 * 10**6 + ) # Item 3 tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() @@ -136,42 +153,15 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): assert alreadySpentAmountAfter == tmcNewSpentAmountExpected tmcSpendableBalanceAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance() assert tmcSpendableBalanceAfter == tmcBudgetAfterExpected - with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): - create_and_enact_payment_motion( - easy_track, - tmc_trusted_caller, - tmc_top_up_evm_script_factory, - stETH_token, - [stonks_steth_contract], - [tmcBudgetAfterExpected + 1], - stranger, - ) - - print ('Spendable balance before 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) - for i in range (12): - create_and_enact_payment_motion( - easy_track, - tmc_trusted_caller, - tmc_top_up_evm_script_factory, - stETH_token, - [stonks_steth_contract], - [1_000 * 10 ** 18], - stranger, - ) - print ('Spendable balance on 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) - - print ('Spendable balance after 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) - with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): - create_and_enact_payment_motion( - easy_track, - tmc_trusted_caller, - tmc_top_up_evm_script_factory, - stETH_token, - [stonks_steth_contract], - [1], - stranger, - ) - print ('Spendable balance after-after 12 * 1000 stETH transfer ', interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance()) + limit_test(easy_track, + tmcSpendableBalanceAfter, + tmc_trusted_caller, + tmc_top_up_evm_script_factory, + stonks_steth_contract, + stranger, + stETH_token, + 1_000 * 10 ** 18 + ) # Item 5 SimplyStakingDataAfter = nor.getNodeOperator(SimplyStakingId, True) @@ -216,37 +206,34 @@ def test_vote(helpers, accounts, vote_ids_from_env, stranger): ) ) -def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger): - - # can't spend more than 2M USDC at once - max_usdc_spend_at_once = 2_000_000 * 10**6 +def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger, token, max_spend_at_once): - to_spend_usdc = to_spend * 10**6 + chain.snapshot() - # check that there is no way to spend more USDC + # check that there is no way to spend more then expected with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): create_and_enact_payment_motion( easy_track, trusted_caller_acc, top_up_evm_script_factory, - interface.Usdc(USDC_TOKEN), + token, [multisig_acc], - [to_spend_usdc + 1], + [to_spend + 1], stranger, ) - # spend all USDC step by step (at most 2M each time) - while to_spend_usdc > 0: + # spend all step by step + while to_spend > 0: create_and_enact_payment_motion( easy_track, trusted_caller_acc, top_up_evm_script_factory, - interface.Usdc(USDC_TOKEN), + token, [multisig_acc], - [min(max_usdc_spend_at_once, to_spend_usdc)], + [min(max_spend_at_once, to_spend)], stranger, ) - to_spend_usdc -= min(max_usdc_spend_at_once, to_spend_usdc) + to_spend -= min(max_spend_at_once, to_spend) # make sure there is nothing left so that you can't spend anymore with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): @@ -254,13 +241,13 @@ def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_facto easy_track, trusted_caller_acc, top_up_evm_script_factory, - interface.Usdc(USDC_TOKEN), + token, [multisig_acc], [1], stranger, ) -STETH_TRANSFER_MAX_DELTA = 2 + chain.revert() def prepare_agent_for_steth_payment(amount: int): agent, steth = contracts.agent, contracts.lido @@ -276,7 +263,11 @@ def prepare_agent_for_usdc_payment(amount: int): usdc_minter = accounts.at("0x5B6122C109B78C6755486966148C1D70a50A47D7", force=True) usdc_controller = accounts.at("0x79E0946e1C186E745f1352d7C21AB04700C99F71", force=True) usdc_master_minter = interface.UsdcMasterMinter("0xE982615d461DD5cD06575BbeA87624fda4e3de17") + + web3.provider.make_request("evm_setAccountBalance", [usdc_controller.address, hex(100_000 * 10**18)]) + assert usdc_controller.balance() >= 100_000 * 10**18 + usdc_master_minter.incrementMinterAllowance(amount, {"from": usdc_controller}) usdc.mint(agent, amount, {"from": usdc_minter}) - assert usdc.balanceOf(agent) >= amount, "Insufficient USDC balance" \ No newline at end of file + assert usdc.balanceOf(agent) >= amount, "Insufficient USDC balance"