コード例 #1
0
def test_boi_in_common_submit_big(init_environment):
    """
    Block of interest contained in both chains
    ----x---+------->  Ca
            |
            +---->  Cb
    """

    interface = make_interface(backend)
    block_of_interest_index = submit_proof.size - 1

    res = submit_event_proof(
        interface,
        submit_proof,
        block_of_interest_index,
    )
    assert res["result"] == True

    with pytest.raises(Exception) as ex:
        res = submit_contesting_proof(
            interface,
            submit_proof,
            small_lca,
            small_contest_proof,
            block_of_interest_index,
        )
    assert extract_message_from_error(ex) == errors["boi in sub-chain"]
コード例 #2
0
def test_fail_ganache():
    """
    Test failure at require in smart contract for ganache
    """

    with pytest.raises(Exception) as ex:
        make_interface("ganache").call("fail")
    assert extract_message_from_error(ex) == "test failed successfully"
コード例 #3
0
def test_missing_genesis_submit(init_environment):
    """
    Calls the submit_event_proof of the contracts with a proof without genesis
    """
    block_of_interest_index = 0

    with pytest.raises(Exception) as e:
        submit_event_proof(interface, headless_proof, block_of_interest_index)
    assert extract_message_from_error(e) == errors["genesis"]
コード例 #4
0
def test_insufficient_collateral(init_environment):
    """
    Test contract call with insufficient collateral
    """

    interface = make_interface(backend)

    collateral = pow(10, 17) - 1

    with pytest.raises(Exception) as ex:
        submit_event_proof(interface,
                           proof,
                           proof.size - 1,
                           collateral=collateral)
    assert extract_message_from_error(ex) == errors["ante up"]
コード例 #5
0
def test_boi_out_of_index(init_environment):
    """
    Block of interest contained in both chains
    ---------------->  Ca    x
    """

    interface = make_interface(backend)
    block_of_interest_index = submit_proof.size

    with pytest.raises(Exception) as ex:
        res = submit_event_proof(
            interface,
            submit_proof,
            block_of_interest_index,
        )
    assert extract_message_from_error(ex) == errors["boi not exist"]
コード例 #6
0
def test_dispute_valid(init_environment):
    """
    Try to dispute valid proof
    """

    block_of_interest_index = 0
    interface = make_interface(backend)
    res = submit_event_proof(
        interface, proof, block_of_interest_index, profile=True
    )
    assert res["result"] == True

    with pytest.raises(Exception) as ex:
        res = dispute_existing_proof(
            interface, proof, block_of_interest_index, 1, profile=True
        )
    assert extract_message_from_error(ex) == errors["valid existing"]
コード例 #7
0
def test_proof_exists(init_environment):
    """
    Contest proof exists
    """

    interface = make_interface(backend)

    block_of_interest_index = 0

    res = submit_event_proof(
        interface,
        submit_proof,
        block_of_interest_index,
    )
    assert res["result"] == True

    with pytest.raises(Exception) as ex:
        res = submit_event_proof(
            interface,
            submit_proof,
            block_of_interest_index,
        )
    assert extract_message_from_error(ex) == errors["period expired"]
コード例 #8
0
def run_nipopow(backend, proof):
    """
    Make a call to verifier with proof.
    The block of interest is the last block of the chain.
    """

    block_of_interest_index = 0
    interface = make_interface(backend)
    _t = Timer()
    try:
        result = submit_event_proof(interface,
                                    proof,
                                    block_of_interest_index,
                                    profile=True)
    except Exception as ex:
        print(ex)

        result = {"result": extract_message_from_error(ex)}
    del _t

    interface.end()

    return result["result"]
コード例 #9
0
def test_wrong_lca(init_environment):
    """
    Contest proof lies about lca
    """

    interface = make_interface(backend)
    block_of_interest_index = 0

    res = submit_event_proof(
        interface,
        submit_proof,
        block_of_interest_index,
    )
    assert res["result"] == True

    with pytest.raises(Exception) as ex:
        res = submit_contesting_proof(
            interface,
            submit_proof,
            large_lca - 1,  # this is wrong
            large_contest_proof,
            block_of_interest_index,
        )
    assert extract_message_from_error(ex) == errors["wrong lca"]
コード例 #10
0
def test_same_proofs(init_environment):
    """
    Submit proof is the same as contest proof
    """

    interface = make_interface(backend)
    block_of_interest_index = submit_proof.size - 1

    res = submit_event_proof(
        interface,
        submit_proof,
        block_of_interest_index,
    )
    assert res["result"] == True

    with pytest.raises(Exception) as ex:
        res = submit_contesting_proof(
            interface,
            submit_proof,
            0,
            submit_proof,
            block_of_interest_index,
        )
    assert extract_message_from_error(ex) == errors["boi in sub-chain"]
コード例 #11
0
def test_boi_out_of_index_contest(init_environment):
    """
    Block of interest is in submit but not in contest proof
    """

    interface = make_interface(backend)
    block_of_interest_index = submit_proof.size - 1

    res = submit_event_proof(
        interface,
        submit_proof,
        block_of_interest_index,
    )
    assert res["result"] == True

    with pytest.raises(Exception) as ex:
        res = submit_contesting_proof(
            interface,
            submit_proof,
            large_lca,
            large_contest_proof,
            submit_proof.size,  # This is out of range
        )
    assert extract_message_from_error(ex) == errors["boi not exist"]