Example #1
0
    def test_init(self):
        config = storage.InRamConfigurationStore()
        key_store = storage.InRamPlainKeyStore(config=config)
        wallet = Wallet(key_store=key_store)
        # InRamStore does not come with a default key
        self.assertFalse(wallet.created())

        self.assertTrue(bool(wallet.rpc))
        self.assertEqual(wallet.prefix, "BTS")
        wif1 = PrivateKey()
        wif2 = PrivateKey()
        wallet.setKeys([
            wif1, wif2
        ])
        self.assertIn(
            str(wif1.pubkey),
            wallet.store.getPublicKeys()
        )
        self.assertIn(
            str(wif2.pubkey),
            wallet.store.getPublicKeys()
        )
        self.assertEqual(
            wallet.getPrivateKeyForPublicKey(
                wif1.pubkey
            ),
            str(wif1)
        )
        self.assertEqual(
            wallet.getPrivateKeyForPublicKey(
                wif2.pubkey
            ),
            str(wif2)
        )
        # wallet.unlock("")
        # wallet.lock()
        # is unlocked because InRamKeyStore and not encrypted
        self.assertFalse(wallet.store.is_encrypted())
        self.assertFalse(wallet.is_encrypted())
        self.assertTrue(wallet.unlocked())
        self.assertFalse(wallet.locked())

        wif3 = PrivateKey()
        wallet.addPrivateKey(wif3)
        self.assertIn(
            str(wif3.pubkey),
            wallet.store.getPublicKeys()
        )
        self.assertEqual(
            wallet.getPrivateKeyForPublicKey(
                wif3.pubkey
            ),
            str(wif3)
        )

        wallet.removePrivateKeyFromPublicKey(wif3.pubkey)
        with self.assertRaises(KeyNotFound):
            wallet.getPrivateKeyForPublicKey(
                wif3.pubkey
            )
Example #2
0
config["node"] = "wss://node.bitshares.eu"

# default wifs key for testing
wifs = [
    "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3",
    "5KCBDTcyDqzsqehcb52tW5nU6pXife6V2rX9Yf7c3saYSzbDZ5W"
]
wif = wifs[0]

# bitshares instance
bitshares = BitShares(
    keys=wifs,
    nobroadcast=True,
    num_retries=1,
    config_store=config,
    key_store=storage.InRamPlainKeyStore()
)

# Set defaults
bitshares.set_default_account("init0")
set_shared_blockchain_instance(bitshares)

# Ensure we are not going to transaction anythin on chain!
assert bitshares.nobroadcast

# Setup custom Cache
BlockchainObject._cache = ObjectCache(
    default_expiration=60 * 60 * 1,
    no_overwrite=True
)