Beispiel #1
0
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
Beispiel #2
0
def test_apply_block_raises_if_not_genesis_and_no_delegate(redis):
    manager = WalletManager()

    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"
    )

    with pytest.raises(Exception) as excinfo:
        manager.apply_block(block)

    assert str(excinfo.value) == (
        "Could not find a delegate with public key: "
        "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a"
    )
Beispiel #3
0
def test_apply_block_correctly_handles_genesis_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 = 1
    block.reward = 2
    block.transactions = [transaction_1, transaction_2]
    block.generator_public_key = (
        "0316510c1409d3307d9f205cac58f1a871499c3ffea3878ddbbb48c821cfbc079a"
    )
    manager.apply_block(block)

    assert apply_transaction_mock.call_count == 2
    delegate = Wallet(
        json.loads(redis.get("wallets:address:ASt5oBHKDW8AeJe2Ybc1RucMLS7mRCiuRe"))
    )
    assert delegate.balance == 2