class TestVault(TestBase): '''Vault tests''' def setUp(self): self.generate_c_org() self.generate_wallet() self.v = Vault() def test_vault(self): self.assertIn('infura', self.v.data) self.assertIn('wallets', self.v.data) self.assertIn('my-wallet', self.v.names) def test_save(self): self.v.data['infura'] = "TEST" self.v.save() self.v.data = [] self.v.load() self.assertEqual(self.v.data['infura'], "TEST") def test_exist(self): self.assertTrue(self.v.exist_wallet('my-wallet')) def test_create_wallet(self): self.assertFalse(self.v.exist_wallet('New Wallet')) self.v.create_wallet('New Wallet') self.assertTrue(self.v.exist_wallet('New Wallet')) def test_store_wallet_dict(self): self.assertFalse(self.v.exist_wallet('dict-wallet')) wallet = { 'name': "dict-wallet", 'private_key': utils.generate_random_private_key() } self.v.store_wallet(wallet) self.assertTrue(self.v.exist_wallet('dict-wallet')) def test_store_wallet(self): self.assertFalse(self.v.exist_wallet('wallet-wallet')) wallet = utils.Wallet(name="wallet-wallet", private_key=utils.generate_random_private_key()) self.v.store_wallet(wallet) self.assertTrue(self.v.exist_wallet('wallet-wallet')) def test_remove_wallet(self): self.assertTrue(self.v.exist_wallet('my-wallet')) self.v.remove_wallet('my-wallet') self.assertFalse(self.v.exist_wallet('my-wallet')) def test_no_wallet(self): self.v.data['wallets'] = [] self.v.save() self.assertFalse(self.v.exist_wallet('my-wallet'))
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 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.")