Skip to content

Commit

Permalink
Support Safe Singleton Factory
Browse files Browse the repository at this point in the history
- Add deterministic contract deployment

Optimizes testing:
- Speed up tests, as it's easy to check if contracts are deployed
- Less confusing, as contract addresses will be the same to production environments
  • Loading branch information
Uxio0 committed Oct 10, 2023
1 parent 069bf48 commit 310fbef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions gnosis/eth/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

NULL_ADDRESS: ChecksumAddress = ChecksumAddress("0x" + "0" * 40)
SENTINEL_ADDRESS: ChecksumAddress = ChecksumAddress("0x" + "0" * 39 + "1")
SAFE_SINGLETON_FACTORY_DEPLOYER_ADDRESS: ChecksumAddress = ChecksumAddress(
"0xE1CB04A0fA36DdD16a06ea828007E35e1a3cBC37"
)
SAFE_SINGLETON_FACTORY_ADDRESS: ChecksumAddress = ChecksumAddress(
"0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7"
)

# keccak('Transfer(address,address,uint256)')
ERC20_721_TRANSFER_TOPIC: str = (
Expand Down
31 changes: 30 additions & 1 deletion gnosis/safe/tests/safe_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from web3.contract import Contract
from web3.types import Wei

from gnosis.eth.constants import NULL_ADDRESS
from gnosis.eth.constants import (
NULL_ADDRESS,
SAFE_SINGLETON_FACTORY_ADDRESS,
SAFE_SINGLETON_FACTORY_DEPLOYER_ADDRESS,
)
from gnosis.eth.contracts import (
get_compatibility_fallback_handler_contract,
get_multi_send_contract,
Expand Down Expand Up @@ -70,6 +74,8 @@ def safe_contract(self):
def setUpClass(cls):
super().setUpClass()

cls.deploy_safe_singleton_factory(cls)

if not _contract_addresses:
# First time mixin is called, deploy Safe contracts
for key, function in cls.contract_deployers.items():
Expand Down Expand Up @@ -161,6 +167,29 @@ def configure_envvars(self):
"simulate_tx_accessor_V1_4_1"
]

def deploy_safe_singleton_factory(self) -> bool:
"""
Deploy Safe Singleton Factory for deterministic deployments and speeding up tests,
due to being able to check quickly if contracts are deployed in their expected addresses
Singleton factory with `1337` chainId is used
Deployer address: 0xE1CB04A0fA36DdD16a06ea828007E35e1a3cBC37
Expected factory address: 0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7
:return: `True` if deployed, `False` otherwise
"""
if self.ethereum_client.is_contract(SAFE_SINGLETON_FACTORY_ADDRESS):
return False

raw_tx = HexBytes(
"0xf8a78085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3820a96a0460c6ea9b8f791e5d9e67fbf2c70aba92bf88591c39ac3747ea1bedc2ef1750ca04b08a4b5cea15a56276513da7a0c0b34f16e89811d5dd911efba5f8625a921cc"
)
self.send_ether(SAFE_SINGLETON_FACTORY_DEPLOYER_ADDRESS, 10000000000000000)
tx_hash = self.ethereum_client.send_raw_transaction(raw_tx)
tx_receipt = self.ethereum_client.get_transaction_receipt(tx_hash, timeout=30)
assert tx_receipt["status"] == 1
return True

def deploy_test_safe(self, *args, **kwargs) -> Safe:
"""
:param args:
Expand Down

0 comments on commit 310fbef

Please sign in to comment.