def command_deploy(self): if os.path.isdir(self.output): self.output = os.path.join(self.output, "config.yaml") if not os.path.isfile(self.output): return logging.error('The path is not valid. Please add a path to the config.yaml file.') dirname = os.path.dirname(os.path.abspath(self.output)) if not self.wallet: return logging.error('No wallet has been specified. Please add --wallet NAME. Add a wallet with the wallet command.') else: try: wallet = Vault().find_wallet(name=self.wallet) except ValueError: return logging.error('The wallet is not recognized. Add a wallet with the wallet command.') name = LocalParams(self.output).name GlobalParams().create_or_update(name, dirname) c_org_manager = ContinuousOrganisationManager(name) try: c_org_manager.deploy(wallet) except ValueError as e: err = e.args[0] logging.error('''Oops... Something wrong happened! {}'''.format(err['message'])) if err['code'] == -32000: logging.error('The specified wallet has insufficient funds to deploy your Continuous Organization, please send ~0.1eth to {}'.format(wallet.address)) return logging.info("Great! Your continuous organisation exists!")
def command_add_ether_wallet(self): try: wallet = Vault().find_wallet(name=self.name) except ValueError: return logging.error("The wallet's name can not be found.") wallet.add_ether(2000000000000000000) logging.info("Some ethers have been added.")
def test_add_wallet(self): sys.argv = [exe_cli] + [ "wallet", "add", "test", utils.generate_random_private_key() ] main() self.assertTrue(Vault().exist_wallet("test"))
def command_buy(self): if not isinstance(self.amount, float) or self.amount < 0: return logging.error("Please add a positive amount to buy.") vault = Vault() try: wallet = vault.find_wallet(name=self.wallet) except ValueError: return logging.error( 'The wallet is not recognized. Add a wallet with the wallet command.' ) c_org_manager = ContinuousOrganisationManager(self.name) if not c_org_manager.is_built(): return logging.error( 'The continuous organisation is not deployed. Run first `c-org deploy --help`.' ) logging.debug('Buying an amount of {:.3f} to {}'.format( self.amount, self.name)) c_org_manager.buy(self.amount, wallet) balance = c_org_manager.get_balance(wallet) logging.info( "Great! Your buy tokens! Your balance is now {:d}".format(balance))
def test_deploy_default_wallet(self): Vault().default_wallet().add_ether(init_ether) config_file = os.path.join(self.my_co_path, "config.yaml") sys.argv = [exe_cli, "deploy", config_file] main() self.assertTrue(os.path.isfile(self.c_org_manager.build_file)) contract = self.c_org_manager.contract self.assertTrue(len(contract.find_functions_by_name('buy')))
def command_rm_wallet(self): vault = Vault() if not vault.exist_wallet(name=self.name): return logging.error("The wallet's name can not be found.") logging.debug("Removing a wallet with name {}.".format(self.name)) vault.remove_wallet(self.name) logging.info("The wallet is removed.")
def command_create_wallet(self): vault = Vault() if vault.exist_wallet(name=self.name): return logging.error("The wallet's name already exists.") logging.debug("Creating a wallet with name {}.".format(self.name)) wallet = vault.create_wallet(self.name) logging.info( "The wallet is created. Please add some ethers to its address {}. You can use Metamask for that (see https://youtu.be/-uJjfn4wizE)." .format(wallet.address))
def test_no_enough_funds(self): config_file = os.path.join(self.my_co_path, "config.yaml") wallet = Vault().create_wallet('poor-wallet') command = [exe_cli, "deploy", config_file, "--wallet", wallet.name] p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = p.communicate() self.assertEqual(out, b'') self.assertIn(wallet.address.encode('utf-8'), err)
def command_add_wallet(self): vault = Vault() if vault.exist_wallet(name=self.name): return logging.error("The wallet's name already exists.") if self.name: logging.debug("Adding a wallet with name {}.".format(self.name)) else: logging.debug("Adding a wallet with private key") wallet = Wallet(name=self.name, private_key=self.private_key) vault.store_wallet(wallet) logging.info("The wallet is added.")
def command_stats(self): vault = Vault() try: wallet = vault.find_wallet(name=self.wallet) except ValueError: return logging.error( 'The wallet is not recognized. Add a wallet with the wallet command.' ) c_org_manager = ContinuousOrganisationManager(self.name) if not c_org_manager.is_built(): return logging.error( 'The continuous organisation is not deployed. Run first `c-org deploy --help`.' ) logging.debug('Retrieving the statistics') balance = c_org_manager.get_balance(wallet) logging.info("Balance: {:.3f} tokens".format(balance)) tokens = c_org_manager.get_n_tokens() logging.info("Total tokens: {:.3f} tokens".format(tokens)) reserve = c_org_manager.get_sell_reserve() logging.info("Reserve: {:.3f}".format(reserve))
def test_add_ether_wallet(self): wallet = Vault().create_wallet(name="test-add-ether") sys.argv = [exe_cli, "wallet", "add_ether", "test-add-ether"] main() self.assertEqual(init_ether, wallet.balance)
def test_list_wallet(self): Vault().create_wallet(name="test-list") with self.assertLogs() as cm: sys.argv = [exe_cli, "wallet", "list"] main() self.assertIn(True, ['test-list' in i for i in cm.output])
def test_create_wallet(self): sys.argv = [exe_cli, "wallet", "create", "my-wallet"] main() self.assertTrue(Vault().exist_wallet("my-wallet"))
def setUp(self): self.generate_c_org() self.generate_wallet() self.v = Vault()
def command_list_wallet(self): for i, wallet in enumerate(Vault().wallets): logging.info("[{}] at {}".format(wallet['name'], wallet['address']))
def test_rm_wallet(self): Vault().create_wallet(name="name") self.assertTrue(Vault().exist_wallet("name")) sys.argv = [exe_cli, "wallet", "remove", "name"] main() self.assertFalse(Vault().exist_wallet("name"))
def generate_wallet(self): if not self.has_temporary_files(): self.temp_files() self.wallet = Vault().create_wallet('test') self.wallet.add_ether(init_ether)