def test_apply_block_updates_vote_balance_of_voted_delegate(redis, mocker): manager = WalletManager() apply_transaction_mock = mocker.patch( "chain.plugins.database.wallet_manager.WalletManager.apply_transaction" ) transaction_1 = TransferTransaction() transaction_2 = TransferTransaction() block = Block() block.height = 1337 block.reward = 2 block.transactions = [transaction_1, transaction_2] block.generator_public_key = ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ) redis.set( "wallets:address:AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM", json.dumps( { "address": "AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM", "public_key": ( "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f" ), "vote_balance": 2000000, } ), ) redis.set( "wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", Wallet( { "address": "ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", "public_key": ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ), "balance": 0, "vote": ( "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f" ), } ).to_json(), ) manager.apply_block(block) assert apply_transaction_mock.call_count == 2 delegate = Wallet( json.loads(redis.get("wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe")) ) assert delegate.balance == 2 vote_wallet = Wallet( json.loads(redis.get("wallets:address:AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM")) ) assert vote_wallet.vote_balance == 2000002
def test_apply_transaction_force_apply_skips_can_be_applied_check(redis, mocker): manager = WalletManager() balances_mock = mocker.patch( "chain.plugins.database.wallet_manager.WalletManager._update_vote_balances" ) mocker.patch( "chain.plugins.database.wallet_manager.is_transaction_exception", return_value=True, ) block = Block() transaction = TransferTransaction() transaction.type = TRANSACTION_TYPE_TRANSFER transaction.fee = 10000 transaction.amount = 430000 transaction.id = "hehe" transaction.sender_public_key = ( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ) transaction.recipient_id = "AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW" redis.set( "wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", Wallet( { "address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "public_key": ( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), "balance": 0, } ).to_json(), ) manager.apply_transaction(transaction, block) # updated sender wallet is saved back to redis sender = Wallet( json.loads(redis.get("wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof")) ) assert sender.balance == -440000 # updated recipient wallet is saved back to redis recipient = Wallet( json.loads(redis.get("wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW")) ) assert recipient.balance == 430000 balances_mock.assert_called_once()
def test_get_wallet_by_address_returns_correct_wallet(redis): manager = WalletManager() redis.set( "wallets:address:spongebob", Wallet({"address": "spongebob", "username": "******"}).to_json(), ) redis.set( "wallets:address:patrick", Wallet({"address": "patrick", "username": "******"}).to_json(), ) wallet = manager._get_wallet_by_address("spongebob") assert wallet.address == "spongebob" assert wallet.username == "squarepants"
def test_save_wallet_saves_wallet_to_redis(redis): manager = WalletManager() wallet = Wallet({"address": "spongebob", "username": "******"}) manager.save_wallet(wallet) keys = redis.keys("*") assert keys == [b"wallets:address:spongebob"]
def test_apply_transaction_raises_if_cant_be_applied_to_sender_wallet(redis, mocker): manager = WalletManager() block = Block() transaction = TransferTransaction() transaction.type = TRANSACTION_TYPE_TRANSFER transaction.fee = 10000 transaction.amount = 430000 transaction.id = "hehe" transaction.sender_public_key = ( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ) transaction.recipient_id = "AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW" redis.set( "wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", Wallet( { "address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "public_key": ( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), "balance": 5, } ).to_json(), ) with pytest.raises(Exception) as excinfo: manager.apply_transaction(transaction, block) assert str(excinfo.value) == ( "Can't apply transaction hehe from sender AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof" )
def test_update_vote_balances_correctly_for_transaction_type_vote_minus_revert(redis): manager = WalletManager() transaction = VoteTransaction() transaction.fee = 10000 transaction.amount = 430000 transaction.type = TRANSACTION_TYPE_VOTE transaction.asset = { "votes": ["-03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2"] } redis.set( "wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW", json.dumps( {"address": "AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW", "vote_balance": 10000000} ), ) sender = Wallet( {"address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "balance": 1337000} ) manager._update_vote_balances(sender, None, transaction, revert=True) delegate = json.loads( redis.get("wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW") ) assert delegate["vote_balance"] == 11337000
def test_save_wallet(redis): manager = PoolWalletManager() wallet = Wallet({"address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof"}) manager.save_wallet(wallet) data = json.loads( redis.get("pool_wallet:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof") ) assert data["address"] == wallet.address
def find_by_address(self, address): if not isinstance(address, str): raise ValueError("address must be str") assert isinstance(address, str) wallet = self._get_wallet_by_address(address) if wallet: return wallet return Wallet({"address": address})
def test_can_be_applied_to_wallet_calls_super(mocker): transaction = SecondSignatureTransaction() wallet = Wallet({}) super_mock = mocker.patch( ("chain.crypto.objects.transactions.second_signature.BaseTransaction." "can_be_applied_to_wallet"), return_value=True, ) can_apply = transaction.can_be_applied_to_wallet(wallet, None, None) assert can_apply is True assert super_mock.call_count == 1
def test_revert_for_sender_wallet(mocker): transaction = SecondSignatureTransaction() transaction.asset = {"signature": {"publicKey": "harambe"}} wallet = Wallet({"second_public_key": "harambe"}) super_mock = mocker.patch( "chain.crypto.objects.transactions.delegate_registration.BaseTransaction." "revert_for_sender_wallet") transaction.revert_for_sender_wallet(wallet) assert super_mock.call_count == 1 assert wallet.second_public_key is None
def find_by_address(self, address): """Finds a wallet by a given address. If wallet is not found, it is copied from blockchain wallet manager. :param string address: wallet address :returns Wallet: wallet object """ key = self.key_for_address(address) if not self.redis.exists(key): self.save_wallet(self.database.wallets.find_by_address(address)) wallet = json.loads(self.redis.get(key)) return Wallet(wallet)
def test_revert_for_sender_wallet(mocker): transaction = DelegateRegistrationTransaction() transaction.asset = {"delegate": {"username": "******"}} wallet = Wallet({"username": "******"}) super_mock = mocker.patch( "chain.crypto.objects.transactions.delegate_registration.BaseTransaction." "revert_for_sender_wallet") transaction.revert_for_sender_wallet(wallet) assert super_mock.call_count == 1 assert wallet.username is None
def test_apply(redis, mocker): transaction = DelegateRegistrationTransaction() manager = WalletManager() sender_wallet = Wallet({ "address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "username": "******" }) transaction.apply(sender_wallet, None, manager) data = redis.get("wallets:username:harambe") assert data == b"AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof"
def test_can_apply_to_sender_returns_true_if_everything_ok(redis, crypto_transaction): manager = PoolWalletManager() chain_wallet = Wallet( {"address": "AS2YSSDbbXBAehfbm1KAEvJMJFdPPT2aRT", "balance": 133700000} ) redis.set( "wallets:address:AS2YSSDbbXBAehfbm1KAEvJMJFdPPT2aRT", chain_wallet.to_json() ) crypto_transaction.second_signature = None crypto_transaction.sign_signature = None can_apply = manager.can_apply_to_sender(crypto_transaction, 2243161) assert can_apply is True
def test_apply(redis, mocker): transaction = TransferTransaction() transaction.recipient_id = "DB4gFuDztmdGALMb8i1U4Z4R5SktxpNTAY" manager = WalletManager() recipient = Wallet({"address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof"}) apply_mock = mocker.patch.object(transaction, "apply_to_recipient_wallet") transaction.apply(None, recipient, manager) data = json.loads( redis.get("wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof")) assert data["address"] == recipient.address assert apply_mock.call_count == 1
def test_find_by_address_copies_wallet_from_blockchain_wallet_manager(redis): manager = PoolWalletManager() chain_wallet = Wallet( {"address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "username": "******"} ) redis.set( "wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", chain_wallet.to_json() ) wallet = manager.find_by_address("AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof") assert redis.exists("pool_wallet:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof") assert wallet.to_json() == chain_wallet.to_json()
def test_find_by_address_returns_existin_wallet_from_redis(redis): manager = PoolWalletManager() existing_wallet = Wallet( {"address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "username": "******"} ) redis.set( "pool_wallet:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", existing_wallet.to_json(), ) wallet = manager.find_by_address("AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof") assert len(redis.keys("pool_wallet:address:*")) == 1 assert wallet.to_json() == existing_wallet.to_json()
def test_wallet_sets_default_attributes_with_default_values(): wallet = Wallet({}) assert wallet.address is None assert wallet.public_key is None assert wallet.second_public_key is None assert wallet.multisignature is None assert wallet.vote is None assert wallet.username is None assert wallet.balance == 0 assert wallet.vote_balance == 0 assert wallet.produced_blocks == 0 assert wallet.missed_blocks == 0 assert wallet.forged_fees == 0 assert wallet.forged_rewards == 0
def test_find_by_address_returns_existing_wallet(redis): address = "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof" key = "wallets:address:{}".format(address).encode() manager = WalletManager() redis.set(key, Wallet({"address": address, "username": "******"}).to_json()) wallet = manager.find_by_address(address) assert wallet.address == address assert wallet.username == "spongebob" keys = redis.keys("*") assert keys == [key]
def test_can_apply_to_sender_returns_false_if_balance_is_zero( redis, crypto_transaction ): manager = PoolWalletManager() chain_wallet = Wallet( {"address": "AMm7u2Kpaf3gY2Y96MovudH2q65WHi8Sqd", "balance": 0} ) redis.set( "wallets:address:AMm7u2Kpaf3gY2Y96MovudH2q65WHi8Sqd", chain_wallet.to_json() ) can_apply = manager.can_apply_to_sender(crypto_transaction, 2243161) assert can_apply is False
def test_apply_block(redis, mocker): manager = WalletManager() apply_transaction_mock = mocker.patch( "chain.plugins.database.wallet_manager.WalletManager.apply_transaction" ) transaction_1 = TransferTransaction() transaction_2 = TransferTransaction() block = Block() block.height = 1337 block.reward = 2 block.transactions = [transaction_1, transaction_2] block.generator_public_key = ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ) redis.set( "wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", Wallet( { "address": "ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", "public_key": ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ), "balance": 0, } ).to_json(), ) manager.apply_block(block) assert apply_transaction_mock.call_count == 2 delegate = Wallet( json.loads(redis.get("wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe")) ) assert delegate.balance == 2
def test_find_by_public_key_returns_existin_wallet_from_redis(redis): manager = PoolWalletManager() existing_wallet = Wallet( {"address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "username": "******"} ) redis.set( "pool_wallet:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", existing_wallet.to_json(), ) wallet = manager.find_by_public_key( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ) assert len(redis.keys("pool_wallet:address:*")) == 1 assert wallet.to_json() == existing_wallet.to_json()
def test_find_by_public_key_copies_wallet_from_blockchain_wallet_manager(redis): manager = PoolWalletManager() chain_wallet = Wallet( {"address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "username": "******"} ) redis.set( "wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", chain_wallet.to_json() ) wallet = manager.find_by_public_key( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ) assert redis.exists("pool_wallet:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof") assert wallet.to_json() == chain_wallet.to_json()
def test_find_by_public_key_returns_existing_wallet(redis): address = "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof" public_key = "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" key = "wallets:address:{}".format(address).encode() manager = WalletManager() redis.set(key, Wallet({"address": address, "public_key": public_key}).to_json()) wallet = manager.find_by_public_key(public_key) assert wallet.address == address assert wallet.public_key == public_key keys = redis.keys("*") assert keys == [key]
def __init__(self, redis, **kwargs): if "address" not in kwargs and "public_key" not in kwargs: raise ValueError("address or public_key are required") address = kwargs.get("address") if not address: address = address_from_public_key(kwargs["public_key"]) kwargs["address"] = address self.key = "wallets:address:{}".format(address) self.redis = redis wallet = Wallet(kwargs) redis.set(self.key, wallet.to_json()) self._set_attributes(wallet)
def test_can_apply_to_sender_returns_true_if_transaction_is_exception( redis, crypto_transaction, mocker ): manager = PoolWalletManager() exception_mock = mocker.patch( "chain.plugins.transaction_pool.pool_wallet_manager.is_transaction_exception", return_value=True, ) chain_wallet = Wallet( {"address": "AMm7u2Kpaf3gY2Y96MovudH2q65WHi8Sqd", "balance": 133700000} ) redis.set( "wallets:address:AMm7u2Kpaf3gY2Y96MovudH2q65WHi8Sqd", chain_wallet.to_json() ) can_apply = manager.can_apply_to_sender(crypto_transaction, 2243161) assert can_apply is True exception_mock.assert_called_once_with(crypto_transaction.id)
def test_wallet_sets_attributes_with_correct_values(): data = { "address": "DSMxEhoudwLYVt1jtHDu1dtisa2gS7LeCW", "public_key": ("023918d30ff448ec897e12b77ccd529835c78aee07db1682639320c253cc21a1c7"), "second_public_key": None, "multisignature": None, "vote": "023918d30ff448ec897e12b77ccd529835c78aee07db1682639320c253cc21a1c7", "username": "******", "balance": 600000000, "vote_balance": 600000000, "produced_blocks": 1, "missed_blocks": 0, "forged_fees": 0, "forged_rewards": 0, } wallet = Wallet(data) assert wallet.address == data["address"] assert wallet.public_key == data["public_key"] assert wallet.second_public_key == data["second_public_key"] assert wallet.multisignature == data["multisignature"] assert wallet.vote == data["vote"] assert wallet.username == data["username"] assert wallet.balance == data["balance"] assert wallet.vote_balance == data["vote_balance"] assert wallet.produced_blocks == data["produced_blocks"] assert wallet.missed_blocks == data["missed_blocks"] assert wallet.forged_fees == data["forged_fees"] assert wallet.forged_rewards == data["forged_rewards"]
def test_update_vote_balances_correctly_for_transaction_revert(redis): manager = WalletManager() transaction = TransferTransaction() transaction.fee = 10000 transaction.amount = 430000 transaction.type = TRANSACTION_TYPE_TRANSFER redis.set( "wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW", json.dumps( { "address": "AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW", "public_key": ( "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ), "vote_balance": 10000000, } ), ) redis.set( "wallets:address:AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM", json.dumps( { "address": "AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM", "public_key": ( "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f" ), "vote_balance": 2000000, } ), ) sender = Wallet( { "address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "public_key": ( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), "balance": 1337000, "vote": ( "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ), } ) recipient = Wallet( { "address": "ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", "public_key": ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ), "balance": 66000, "vote": ( "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f" ), } ) manager._update_vote_balances(sender, recipient, transaction, revert=True) delegate1 = json.loads( redis.get("wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW") ) assert delegate1["vote_balance"] == 10440000 delegate2 = json.loads( redis.get("wallets:address:AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM") ) assert delegate2["vote_balance"] == 1570000
def test_build_votes(empty_db, redis): manager = WalletManager() block = BlockFactory() TransactionFactory( block_id=block.id, type=TRANSACTION_TYPE_VOTE, asset={ "votes": [ "+03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ] }, sender_public_key=( "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ), ) redis.set( "wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW", Wallet( { "address": "AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW", "public_key": ( "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ), "username": "******", "vote_balance": 1, "balance": 4, } ).to_json(), ) TransactionFactory( block_id=block.id, type=TRANSACTION_TYPE_VOTE, asset={ "votes": [ "+022eedf9f1cdae0cfaae635fe415b6a8f1912bc89bc3880ec41135d62cbbebd3d3" ] }, sender_public_key=( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), timestamp=1234, sequence=1, ) TransactionFactory( block_id=block.id, type=TRANSACTION_TYPE_VOTE, asset={ "votes": [ "+022eedf9f1cdae0cfaae635fe415b6a8f1912bc89bc3880ec41135d62cbbebd3d3" ] }, sender_public_key=( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), timestamp=1234, sequence=2, ) TransactionFactory( block_id=block.id, type=TRANSACTION_TYPE_VOTE, asset={ "votes": [ "+03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ] }, sender_public_key=( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), timestamp=1234, sequence=0, ) redis.set( "wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", Wallet( { "address": "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", "public_key": ( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), "balance": 1000, } ).to_json(), ) TransactionFactory( block_id=block.id, type=TRANSACTION_TYPE_VOTE, asset={ "votes": [ "-03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ] }, sender_public_key=( "022eedf9f1cdae0cfaae635fe415b6a8f1912bc89bc3880ec41135d62cbbebd3d3" ), ) redis.set( "wallets:address:AcHFimRcEinGcJ1gBD3QAXKcFe8ZwNBkN7", Wallet( { "address": "AcHFimRcEinGcJ1gBD3QAXKcFe8ZwNBkN7", "public_key": ( "022eedf9f1cdae0cfaae635fe415b6a8f1912bc89bc3880ec41135d62cbbebd3d3" ), "balance": 1337, } ).to_json(), ) TransactionFactory( block_id=block.id, type=TRANSACTION_TYPE_TRANSFER, amount=13000, fee=3000, sender_public_key=( "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ), ) manager._build_votes() data_1 = json.loads(redis.get("wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW")) assert data_1["address"] == "AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW" assert ( data_1["vote"] == "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ) assert data_1["vote_balance"] == 1005 assert data_1["balance"] == 4 data_2 = json.loads(redis.get("wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof")) assert data_2["address"] == "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof" assert ( data_2["vote"] == "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ) assert data_2["balance"] == 1000 data_3 = json.loads(redis.get("wallets:address:AcHFimRcEinGcJ1gBD3QAXKcFe8ZwNBkN7")) assert data_3["address"] == "AcHFimRcEinGcJ1gBD3QAXKcFe8ZwNBkN7" assert data_3["vote"] is None assert data_3["balance"] == 1337
def refresh_from_redis(self): data = self.redis.get(self.key) wallet = Wallet(json.loads(data)) self._set_attributes(wallet)