Esempio n. 1
0
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'))
Esempio n. 2
0
    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.")