diff --git a/tests/root_gauge_factory_proxy/test_root_gauge_factory_proxy_admin.py b/tests/root_gauge_factory_proxy/test_root_gauge_factory_proxy_admin.py index 7d428cf..390bec4 100644 --- a/tests/root_gauge_factory_proxy/test_root_gauge_factory_proxy_admin.py +++ b/tests/root_gauge_factory_proxy/test_root_gauge_factory_proxy_admin.py @@ -66,58 +66,53 @@ def test_transfer_proxy_admins(root_gauge_factory_proxy, alice, bob, charlie): def test_transfer_ownership( - alice, bob, charlie, chain, root_gauge_factory, child_gauge_factory, root_gauge_factory_proxy + alice, bob, charlie, chain, root_gauge_factory, root_gauge_factory_proxy ): default_ownership_admin = root_gauge_factory_proxy.ownership_admin() default_emergency_admin = root_gauge_factory_proxy.emergency_admin() - # transfer ownership for both root gauge factory and child gauge factory - for gauge_factory in [root_gauge_factory, child_gauge_factory]: - - # --- - # commit transfer ownership: set gauge proxy as future factory owner - - assert gauge_factory.owner() == alice # alice is the owner - # since proxy contract is not an owner yet, this will revert: - for acct in [ - default_ownership_admin, - default_emergency_admin, - bob, - charlie, - root_gauge_factory_proxy, - ]: - with brownie.reverts(): - root_gauge_factory_proxy.commit_transfer_ownership( - gauge_factory, root_gauge_factory_proxy, {"from": acct} - ) - - # set proxy as future owner: only factory owner can do this - gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) - assert gauge_factory.future_owner() == root_gauge_factory_proxy - assert gauge_factory.owner() == alice # alice is still the owner - - # --- - # accept transfer ownership: only proxy (root_gauge_factory.future_owner) can accept - # this is callable by anyone through the proxy - - # unauthorised accounts cannot complete ownership transfer through the factory - for acct in [default_ownership_admin, default_emergency_admin, alice, bob, charlie]: - with brownie.reverts(): - gauge_factory.accept_transfer_ownership({"from": acct}) - - # completing transfer can be only be done through the root gauge factory proxy now - for acct in [alice, bob, charlie]: - root_gauge_factory_proxy.accept_transfer_ownership(gauge_factory, {"from": acct}) - assert gauge_factory.owner() == root_gauge_factory_proxy - chain.undo() + # --- + # commit transfer ownership: set gauge proxy as future factory owner + + assert root_gauge_factory.owner() == alice # alice is the owner + # since proxy contract is not an owner yet, this will revert: + for acct in [ + default_ownership_admin, + default_emergency_admin, + bob, + charlie, + root_gauge_factory_proxy, + ]: + with brownie.reverts(): + root_gauge_factory_proxy.commit_transfer_ownership( + root_gauge_factory, root_gauge_factory_proxy, {"from": acct} + ) + + # set proxy as future owner: only factory owner can do this + root_gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) + assert root_gauge_factory.future_owner() == root_gauge_factory_proxy + assert root_gauge_factory.owner() == alice # alice is still the owner + + # --- + # accept transfer ownership: only proxy (root_gauge_factory.future_owner) can accept + # this is callable by anyone through the proxy + + # unauthorised accounts cannot complete ownership transfer through the factory + for acct in [default_ownership_admin, default_emergency_admin, alice, bob, charlie]: + with brownie.reverts(): + root_gauge_factory.accept_transfer_ownership({"from": acct}) + + # completing transfer can be only be done through the root gauge factory proxy now + for acct in [alice, bob, charlie]: + root_gauge_factory_proxy.accept_transfer_ownership(root_gauge_factory, {"from": acct}) + assert root_gauge_factory.owner() == root_gauge_factory_proxy + chain.undo() def test_set_killed( root_gauge, - child_gauge, root_gauge_factory, - child_gauge_factory, root_gauge_factory_proxy, alice, bob, @@ -128,45 +123,40 @@ def test_set_killed( default_ownership_admin = root_gauge_factory_proxy.ownership_admin() default_emergency_admin = root_gauge_factory_proxy.emergency_admin() - # testing `set_killed` for root and child gauges - gauge_mapping = {root_gauge_factory: root_gauge, child_gauge_factory: child_gauge} + # alice deployed the factory and set herself as the owner of the factory contract + assert root_gauge_factory.owner() == alice + + # alice is the only one who can kill gauges + root_gauge.set_killed(True, {"from": alice}) + assert root_gauge.is_killed() + assert root_gauge.inflation_params()[0] == 0 # inflation rate of root gauge should be 0 + chain.undo() + + # proxy cannot kill gauges yet, and neither can alice do it through the proxy: + for unauthorised_admins in [ + default_emergency_admin, + default_ownership_admin, + alice, + ]: + with brownie.reverts(): + root_gauge_factory_proxy.set_killed(root_gauge, True, {"from": unauthorised_admins}) - for gauge_factory, gauge in gauge_mapping.items(): - # alice deployed the factory and set herself as the owner of the factory contract - assert gauge_factory.owner() == alice + # so transfer root gauge factory ownership to proxy: + root_gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) + root_gauge_factory_proxy.accept_transfer_ownership(root_gauge_factory, {"from": bob}) - # alice is the only one who can kill gauges - gauge.set_killed(True, {"from": alice}) - assert gauge.is_killed() - if gauge == root_gauge: - assert gauge.inflation_params()[0] == 0 # inflation rate of root gauge should be 0 + # only proxy admins can kill a gauge: + for authorised_admin in [default_emergency_admin, default_ownership_admin]: + root_gauge_factory_proxy.set_killed(root_gauge, True, {"from": authorised_admin}) + assert root_gauge.is_killed() + if root_gauge == root_gauge: + assert root_gauge.inflation_params()[0] == 0 # inflation rate of root gauge should be 0 chain.undo() - # proxy cannot kill gauges yet, and neither can alice do it through the proxy: - for unauthorised_admins in [ - default_emergency_admin, - default_ownership_admin, - alice, - ]: - with brownie.reverts(): - root_gauge_factory_proxy.set_killed(gauge, True, {"from": unauthorised_admins}) - - # so transfer root gauge factory ownership to proxy: - gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) - root_gauge_factory_proxy.accept_transfer_ownership(gauge_factory, {"from": bob}) - - # only proxy admins can kill a gauge: - for authorised_admin in [default_emergency_admin, default_ownership_admin]: - root_gauge_factory_proxy.set_killed(gauge, True, {"from": authorised_admin}) - assert gauge.is_killed() - if gauge == root_gauge: - assert gauge.inflation_params()[0] == 0 # inflation rate of root gauge should be 0 - chain.undo() - - # unauthorised accounts cannot do so: - for unauthorised_acct in [alice, bob, charlie]: - with brownie.reverts(): - root_gauge_factory_proxy.set_killed(gauge, True, {"from": unauthorised_acct}) + # unauthorised accounts cannot do so: + for unauthorised_acct in [alice, bob, charlie]: + with brownie.reverts(): + root_gauge_factory_proxy.set_killed(root_gauge, True, {"from": unauthorised_acct}) def test_set_bridger(root_gauge_factory, root_gauge_factory_proxy, alice, bob, chain): @@ -208,91 +198,78 @@ def test_set_bridger(root_gauge_factory, root_gauge_factory_proxy, alice, bob, c assert root_gauge_factory.get_bridger(chain.id) == ETH_ADDRESS -def test_set_implementation( - root_gauge_factory, child_gauge_factory, root_gauge_factory_proxy, alice, bob, chain -): +def test_set_implementation(root_gauge_factory, root_gauge_factory_proxy, alice, bob, chain): default_ownership_admin = root_gauge_factory_proxy.ownership_admin() default_emergency_admin = root_gauge_factory_proxy.emergency_admin() - for gauge_factory in [root_gauge_factory, child_gauge_factory]: - print(f"\ngauge factory {gauge_factory} owner {gauge_factory.owner()}\n") - assert gauge_factory.owner() == alice - print(f"assertion that alice is the owner passed for {gauge_factory}") - manager = root_gauge_factory_proxy.manager() - # proxy cannot set gauge implementation contract yet: - for admin in [manager, default_ownership_admin]: - with brownie.reverts(): - root_gauge_factory_proxy.set_implementation( - gauge_factory, ETH_ADDRESS, {"from": admin} - ) - - # so transfer root gauge factory ownership to proxy: - gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) - root_gauge_factory_proxy.accept_transfer_ownership(gauge_factory, {"from": bob}) - - for admin in [manager, default_ownership_admin]: - root_gauge_factory_proxy.set_implementation(gauge_factory, ETH_ADDRESS, {"from": admin}) - assert gauge_factory.get_implementation() == ETH_ADDRESS - chain.undo() - - # emergency admin cannot set gauge implementation: + assert root_gauge_factory.owner() == alice + manager = root_gauge_factory_proxy.manager() + # proxy cannot set gauge implementation contract yet: + for admin in [manager, default_ownership_admin]: with brownie.reverts(): root_gauge_factory_proxy.set_implementation( - gauge_factory, ETH_ADDRESS, {"from": default_emergency_admin} + root_gauge_factory, ETH_ADDRESS, {"from": admin} ) - # but emergency admin can set itself (or anyone) as manager and change implementation: - chain.snapshot() # cache state so we can revert back later to repeat the test - root_gauge_factory_proxy.set_manager( - default_emergency_admin, {"from": default_emergency_admin} + # so transfer root gauge factory ownership to proxy: + root_gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) + root_gauge_factory_proxy.accept_transfer_ownership(root_gauge_factory, {"from": bob}) + + for admin in [manager, default_ownership_admin]: + root_gauge_factory_proxy.set_implementation( + root_gauge_factory, ETH_ADDRESS, {"from": admin} ) + assert root_gauge_factory.get_implementation() == ETH_ADDRESS + chain.undo() + + # emergency admin cannot set gauge implementation: + with brownie.reverts(): root_gauge_factory_proxy.set_implementation( - gauge_factory, ETH_ADDRESS, {"from": default_emergency_admin} + root_gauge_factory, ETH_ADDRESS, {"from": default_emergency_admin} ) - assert gauge_factory.get_implementation() == ETH_ADDRESS - chain.revert() # revert back to cached state + # but emergency admin can set itself (or anyone) as manager and change implementation: + root_gauge_factory_proxy.set_manager(default_emergency_admin, {"from": default_emergency_admin}) + root_gauge_factory_proxy.set_implementation( + root_gauge_factory, ETH_ADDRESS, {"from": default_emergency_admin} + ) + assert root_gauge_factory.get_implementation() == ETH_ADDRESS -def test_set_call_proxy( - root_gauge_factory, child_gauge_factory, root_gauge_factory_proxy, alice, bob, chain -): + +def test_set_call_proxy(root_gauge_factory, root_gauge_factory_proxy, alice, bob, chain): default_ownership_admin = root_gauge_factory_proxy.ownership_admin() default_emergency_admin = root_gauge_factory_proxy.emergency_admin() - for gauge_factory in [root_gauge_factory, child_gauge_factory]: - print(f"\ngauge factory {gauge_factory} owner {gauge_factory.owner()}\n") - assert gauge_factory.owner() == alice - print(f"assertion that alice is the owner passed for {gauge_factory}") - manager = root_gauge_factory_proxy.manager() - # proxy cannot set call proxy yet (only possible by factory owner): - for admin in [manager, default_ownership_admin]: - with brownie.reverts(): - root_gauge_factory_proxy.set_call_proxy(gauge_factory, ETH_ADDRESS, {"from": admin}) - - # so transfer root gauge factory ownership to proxy: - gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) - root_gauge_factory_proxy.accept_transfer_ownership(gauge_factory, {"from": bob}) - - for admin in [manager, default_ownership_admin]: - root_gauge_factory_proxy.set_call_proxy(gauge_factory, ETH_ADDRESS, {"from": admin}) - assert gauge_factory.call_proxy() == ETH_ADDRESS - chain.undo() - - # emergency admin cannot set call proxy: + assert root_gauge_factory.owner() == alice + manager = root_gauge_factory_proxy.manager() + # proxy cannot set call proxy yet (only possible by factory owner): + for admin in [manager, default_ownership_admin]: with brownie.reverts(): root_gauge_factory_proxy.set_call_proxy( - root_gauge_factory, ETH_ADDRESS, {"from": default_emergency_admin} + root_gauge_factory, ETH_ADDRESS, {"from": admin} ) - # but emergency admin can set itself (or anyone) as manager and change the gauge factory's call proxy - chain.snapshot() # cache state so we can revert back later to repeat the test - root_gauge_factory_proxy.set_manager( - default_emergency_admin, {"from": default_emergency_admin} - ) + # so transfer root gauge factory ownership to proxy: + root_gauge_factory.commit_transfer_ownership(root_gauge_factory_proxy, {"from": alice}) + root_gauge_factory_proxy.accept_transfer_ownership(root_gauge_factory, {"from": bob}) + + for admin in [manager, default_ownership_admin]: + root_gauge_factory_proxy.set_call_proxy(root_gauge_factory, ETH_ADDRESS, {"from": admin}) + assert root_gauge_factory.call_proxy() == ETH_ADDRESS + chain.undo() + + # emergency admin cannot set call proxy: + with brownie.reverts(): root_gauge_factory_proxy.set_call_proxy( root_gauge_factory, ETH_ADDRESS, {"from": default_emergency_admin} ) - assert gauge_factory.call_proxy() == ETH_ADDRESS - chain.revert() # revert back to cached state + + # but emergency admin can set itself (or anyone) as manager and + # change the gauge factory's call proxy + root_gauge_factory_proxy.set_manager(default_emergency_admin, {"from": default_emergency_admin}) + root_gauge_factory_proxy.set_call_proxy( + root_gauge_factory, ETH_ADDRESS, {"from": default_emergency_admin} + ) + assert root_gauge_factory.call_proxy() == ETH_ADDRESS