def test_fund_account_source_destination_already_has_enough( self, transfer_mock, get_balance_mock): get_balance_mock.side_effect = [0, int(10e18)] w3 = MagicMock() deploy.fund_account_if_needed(w3, 'lol', 'fake') transfer_mock.assert_not_called()
def test_fund_account_if_needed_happy_case(self, transfer_mock, get_balance_mock): get_balance_mock.side_effect = [int(10e18), 0] w3 = MagicMock() deploy.fund_account_if_needed(w3, 'lol', 'fake') transfer_mock.assert_called_once_with(w3, 'lol', 'fake', int(1e18))
def test_fund_account_source_doesnt_have_enough(self, transfer_mock, get_balance_mock): get_balance_mock.side_effect = [0, 0] w3 = MagicMock() with self.assertRaisesRegex(deploy.TransferError, 'does not have enough'): deploy.fund_account_if_needed(w3, 'lol', 'fake') transfer_mock.assert_not_called()
from django_celery_beat.models import PeriodicTask, IntervalSchedule from backend.server.models import Project, Wallet MERGE_PR_BEAT_NAME = "Detect Merge Events" w3 = deploy.get_w3() # If no wallet exists in the db create it. If one exists, treat the one with # the lowest ID as the main wallet of this application if not Wallet.objects.filter(): account = w3.eth.account.create('') private_key = account.privateKey.hex() Wallet.objects.create(private_key=private_key, address=account.address) # if the wallet isn't funded, fund it main_wallet = Wallet.objects.first() deploy.fund_account_if_needed(w3, settings.ethereum_private_key(), main_wallet.private_key) # TODO remove this when we no longer need to deploy the mycro contract on init # maybe we should hide this behind an env variable because this is useful for testing mycro_project = Project.objects.filter(is_mycro_dao=True) if len(mycro_project) == 0: compiler = ContractCompiler() _, mycro_contract, mycro_address, mycro_instance = deploy.deploy( compiler.get_contract_interface('mycro.sol', 'MycroCoin'), private_key=main_wallet.private_key, timeout=None) Project.create_mycro_dao(mycro_address, symbol=mycro_instance.symbol(), decimals=mycro_instance.decimals()) elif len(mycro_project) > 1: raise ValueError("Shit there are two mycro DAOs")