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