Skip to content

Commit

Permalink
Fix not working tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Sep 28, 2023
1 parent 1408401 commit df01e2c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ prompt_toolkit==3.0.39
pyfiglet==1.0.0
pygments==2.16.1
requests==2.31.0
safe-eth-py==6.0.0a1
safe-eth-py==6.0.0b2
tabulate==0.9.0
web3==6.10.0
1 change: 0 additions & 1 deletion safe_cli/operators/safe_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ def change_guard(self, guard: str) -> bool:
return True

def change_master_copy(self, new_master_copy: str) -> bool:
# TODO Check that master copy is valid
if new_master_copy == self.safe_cli_info.master_copy:
raise SameMasterCopyException(new_master_copy)
else:
Expand Down
6 changes: 5 additions & 1 deletion tests/safe_cli_test_case_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
class SafeCliTestCaseMixin(SafeTestCaseMixin):
def setup_operator(self, number_owners: int = 1, version="1.4.1") -> SafeOperator:
assert number_owners >= 1, "Number of owners cannot be less than 1!"
if version == "1.1.1":
if version == "1.0.0":
safe = self.deploy_test_safe_v1_0_0(
owners=[self.ethereum_test_account.address]
)
elif version == "1.1.1":
safe = self.deploy_test_safe_v1_1_1(
owners=[self.ethereum_test_account.address]
)
Expand Down
36 changes: 15 additions & 21 deletions tests/test_safe_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ def test_change_fallback_handler(self):
safe_operator.change_fallback_handler(current_fallback_handler)

new_fallback_handler = Account.create().address
with self.assertRaises(
InvalidFallbackHandlerException
): # Contract does not exist
with self.assertRaises(InvalidFallbackHandlerException):
# Contract does not exist
self.assertTrue(safe_operator.change_fallback_handler(new_fallback_handler))

with mock.patch.object(
Expand All @@ -158,9 +157,10 @@ def test_change_fallback_handler(self):
)
self.assertEqual(safe.retrieve_fallback_handler(), new_fallback_handler)

safe_operator.change_master_copy(self.safe_contract_V1_1_1.address)
# Safes < 1.1.0 don't support the fallback handler
safe_operator_v1_0_0 = self.setup_operator(version="1.0.0")
with self.assertRaises(FallbackHandlerNotSupportedException):
safe_operator.change_fallback_handler(Account.create().address)
safe_operator_v1_0_0.change_fallback_handler(Account.create().address)

def test_change_guard(self):
safe_operator = self.setup_operator(version="1.1.1")
Expand All @@ -173,37 +173,31 @@ def test_change_guard(self):
with self.assertRaises(SameGuardException):
safe_operator.change_guard(current_guard)

new_guard = Account.create().address
not_valid_guard = Account.create().address
with self.assertRaises(InvalidGuardException): # Contract does not exist
self.assertTrue(safe_operator.change_guard(new_guard))
self.assertTrue(safe_operator.change_guard(not_valid_guard))

with mock.patch.object(
EthereumClient, "is_contract", autospec=True, return_value=True
):
self.assertTrue(safe_operator.change_guard(new_guard))
new_guard = self.deploy_example_guard()
self.assertTrue(safe_operator.change_guard(new_guard))
self.assertEqual(safe_operator.safe_cli_info.guard, new_guard)
self.assertEqual(safe.retrieve_guard(), new_guard)

def test_change_master_copy(self):
safe_operator = self.setup_operator()
safe_operator = self.setup_operator(version="1.1.1")
safe = Safe(safe_operator.address, self.ethereum_client)
current_master_copy = safe.retrieve_master_copy_address()
self.assertEqual(current_master_copy, self.safe_contract_V1_1_1.address)
with self.assertRaises(SameMasterCopyException):
safe_operator.change_master_copy(current_master_copy)

random_address = Account.create().address
with self.assertRaises(InvalidMasterCopyException):
safe_operator.change_master_copy(random_address)

self.assertTrue(
safe_operator.change_master_copy(self.safe_contract_V1_1_1.address)
)
self.assertEqual(
safe_operator.safe_cli_info.master_copy, self.safe_contract_V1_1_1.address
)
self.assertEqual(
safe.retrieve_master_copy_address(), self.safe_contract_V1_1_1.address
)
new_master_copy = self.safe_contract_V1_3_0.address
self.assertTrue(safe_operator.change_master_copy(new_master_copy))
self.assertEqual(safe_operator.safe_cli_info.master_copy, new_master_copy)
self.assertEqual(safe.retrieve_master_copy_address(), new_master_copy)

def test_send_ether(self):
safe_operator = self.setup_operator()
Expand Down

0 comments on commit df01e2c

Please sign in to comment.