def test_load_active_delegate_wallets_raises_for_wrong_height(): manager = WalletManager() with pytest.raises(Exception) as excinfo: manager.load_active_delegate_wallets(1337) assert str(excinfo.value) == "Trying to build delegates outside of round change"
def test_load_active_delegate_wallets_raises_for_not_enough_delegates(): manager = WalletManager() with pytest.raises(Exception) as excinfo: manager.load_active_delegate_wallets(103) assert str(excinfo.value) == "Expected to find 51 delegates but only found 0."
def test_load_active_delegate_wallets(redis, mocker): mocker.patch( "chain.plugins.database.wallet_manager.config.get_milestone", return_value={"activeDelegates": 3}, ) manager = WalletManager() redis.set( "wallets:address:AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW", json.dumps( { "public_key": ( "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2" ), "vote_balance": 5, } ), ) redis.set("wallets:username:harambe", "AZYnpgXS3x43nxqhT4q29sZScRwZeNKLpW") redis.set( "wallets:address:AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM", json.dumps( { "public_key": ( "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f" ), "vote_balance": 5, } ), ) redis.set("wallets:username:spongebob", "AWoysqF1xm1LXYLQvmRDpfVNKzzaLVwPVM") redis.set( "wallets:address:AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof", json.dumps( { "public_key": ( "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325" ), "vote_balance": 1, } ), ) redis.set("wallets:username:patrick", "AThM5PNSKdU9pu1ydqQnzRWVeNCGr8HKof") redis.set( "wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe", json.dumps( { "public_key": ( "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a" ), "vote_balance": 3, } ), ) redis.set("wallets:username:squidward", "ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe") wallets = manager.load_active_delegate_wallets(10) public_keys = [wallet.public_key for wallet in wallets] assert len(public_keys) == 3 assert public_keys == [ "0316b3dc139c1a35927ecbdcb8d8b628ad06bd4f1869fe3ad0e23c8106678a460f", "03b12f99375c3b0e4f5f5c7ea74e723f0b84a6f169b47d9105ed2a179f30c82df2", "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a", ]