コード例 #1
0
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"
    )
コード例 #2
0
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()
コード例 #3
0
def test_apply_transaction_raises_if_voted_delegate_doesnt_exist():
    """
    Should raise exception if delegate already exists
    """
    manager = WalletManager()
    public_key = "020f5df4d2bc736d12ce43af5b1663885a893fade7ee5e62b3cc59315a63e6a325"
    block = Block()
    transaction = TransferTransaction()
    transaction.type = TRANSACTION_TYPE_VOTE
    transaction.id = "hehe"
    transaction.asset["votes"] = ["+{}".format(public_key)]

    with pytest.raises(Exception) as excinfo:
        manager.apply_transaction(transaction, block)

    assert str(
        excinfo.value
    ) == "Can't apply transaction hehe: delegate {} does not exist".format(public_key)
コード例 #4
0
def test_apply_transaction_raises_if_delegate_already_exists_for_delegate_reg(redis):
    """
    Should raise exception if delegate already exists
    """
    manager = WalletManager()

    block = Block()
    transaction = TransferTransaction()
    transaction.type = TRANSACTION_TYPE_DELEGATE_REGISTRATION
    transaction.id = "hehe"
    transaction.asset["delegate"] = {"username": "******"}

    manager = WalletManager()

    redis.set("wallets:username:harambe", "")

    with pytest.raises(Exception) as excinfo:
        manager.apply_transaction(transaction, block)

    assert "Can't apply transaction hehe: delegate name harambe already taken" == str(
        excinfo.value
    )