Exemplo n.º 1
0
def test_previous_tx_non_existent():
    """ 
     tests transaction update when a previous transaction does
     not exist 
    """
    # make a synthetic previous transaction
    num_prev_tx_outputs = secrets.randbelow(5) + 1
    previous_tx = make_synthetic_previous_transaction(num_prev_tx_outputs)
    
    #reflect this previous transaction in HeliumDB
    ctr = 0
    for vout in previous_tx["vout"]:
        #pdb.set_trace()
        fragment = {}
        fragment["pkhash"] = vout["ScriptPubKey"][2]
        fragment["spent"] = False 
        fragment["value"] = max(secrets.randbelow(1000000), 10)
        fragment["tx_chain"] =  ""

        txid = previous_tx["transactionid"] + "_" + str(ctr)
        chain.put_transaction( txid, fragment)
        ctr += 1

    # make a transaction consuming some previous transaction outputs
    trx = make_synthetic_transaction(previous_tx)
    trx["vin"][0]["txid"] = "bad previous tx id"
    #update the Helium Chainstate
    assert chain.transaction_update(trx) == False
Exemplo n.º 2
0
def test_get_for_fake_key():
    """
    attempt to get a key value for a fictitous key
    """
    txid = make_transactionid()
    vout_index = make_vout_index()

    keyvalue = {
        "pkhash": make_pkhash(),
        "value":  make_value(),
        "spent":  make_spent(),
        "tx_chain": ""
    }

    assert chain.put_transaction(txid + "_" + str(vout_index), keyvalue) == True

    key = "junk_" + str(vout_index)
    ret = chain.get_transaction(key)
    assert ret == False
Exemplo n.º 3
0
def test_put_keyvalue():
    """
    put a key-value pair into the chainstate database
    values have already been validated by validate_transaction
    """
    ctr = 0
    while ctr < 10:
        txid = make_transactionid()
        vout_index = make_vout_index()

        keyvalue = {
            "pkhash": make_pkhash(),
            "value":  make_value(),
            "spent":  make_spent(),
            "tx_chain": ""
        }

        assert chain.put_transaction(txid + "_" + str(vout_index), keyvalue) == True
        ctr += 1
Exemplo n.º 4
0
def test_get_keyvalue():
    """
    get a key value for an existing key
    """
    txid = make_transactionid()
    vout_index = make_vout_index()

    keyvalue = {
        "pkhash": make_pkhash(),
        "value":  make_value(),
        "spent":  make_spent(),
        "tx_chain": ""
    }

    assert chain.put_transaction(txid + "_" + str(vout_index), keyvalue) == True

    key = txid + "_" + str(vout_index)
    ret = chain.get_transaction(key)
    assert ret != False
    assert type(ret) == dict