def test_deploy_proxy_contract(self): s = 15 owners = [Account.create().address for _ in range(2)] threshold = 2 payment_token = None safe_creation_tx = Safe.build_safe_creation_tx( self.ethereum_client, self.safe_contract_V0_0_1_address, s, owners, threshold, self.gas_price, payment_token, payment_receiver=self.ethereum_test_account.address, ) # Send ether for safe deploying costs self.send_tx( {"to": safe_creation_tx.safe_address, "value": safe_creation_tx.payment}, self.ethereum_test_account, ) proxy_factory = ProxyFactory( self.proxy_factory_contract_address, self.ethereum_client ) ethereum_tx_sent = proxy_factory.deploy_proxy_contract( self.ethereum_test_account, safe_creation_tx.master_copy, safe_creation_tx.safe_setup_data, safe_creation_tx.gas, gas_price=self.gas_price, ) receipt = self.ethereum_client.get_transaction_receipt( ethereum_tx_sent.tx_hash, timeout=20 ) self.assertEqual(receipt.status, 1) safe = Safe(ethereum_tx_sent.contract_address, self.ethereum_client) self.assertEqual( safe.retrieve_master_copy_address(), safe_creation_tx.master_copy ) self.assertEqual(set(safe.retrieve_owners()), set(owners))
def create_safe_tx(self, s: int, owners: List[str], threshold: int, payment_token: Optional[str]) -> SafeCreation: """ Prepare creation tx for a new safe using classic CREATE method. Deprecated, it's recommended to use `create2_safe_tx` :param s: Random s value for ecdsa signature :param owners: Owners of the new Safe :param threshold: Minimum number of users required to operate the Safe :param payment_token: Address of the payment token, if ether is not used :rtype: SafeCreation :raises: InvalidPaymentToken """ payment_token = payment_token or NULL_ADDRESS payment_token_eth_value = self._get_token_eth_value_or_raise( payment_token) gas_price: int = self._get_configured_gas_price() current_block_number = self.ethereum_client.current_block_number logger.debug('Building safe creation tx with gas price %d' % gas_price) safe_creation_tx = Safe.build_safe_creation_tx( self.ethereum_client, self.safe_old_contract_address, s, owners, threshold, gas_price, payment_token, self.funder_account.address, payment_token_eth_value=payment_token_eth_value, fixed_creation_cost=self.safe_fixed_creation_cost) safe_contract = SafeContract.objects.create( address=safe_creation_tx.safe_address, master_copy=safe_creation_tx.master_copy) # Enable tx and erc20 tracing SafeTxStatus.objects.create(safe=safe_contract, initial_block_number=current_block_number, tx_block_number=current_block_number, erc_20_block_number=current_block_number) return SafeCreation.objects.create( deployer=safe_creation_tx.deployer_address, safe=safe_contract, master_copy=safe_creation_tx.master_copy, funder=safe_creation_tx.funder, owners=owners, threshold=threshold, payment=safe_creation_tx.payment, tx_hash=safe_creation_tx.tx_hash.hex(), gas=safe_creation_tx.gas, gas_price=safe_creation_tx.gas_price, payment_token=None if safe_creation_tx.payment_token == NULL_ADDRESS else safe_creation_tx.payment_token, value=safe_creation_tx.tx_pyethereum.value, v=safe_creation_tx.v, r=safe_creation_tx.r, s=safe_creation_tx.s, data=safe_creation_tx.tx_pyethereum.data, signed_tx=safe_creation_tx.tx_raw)