예제 #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_boi_in_small(init_environment):
    """
    Block of interest contained in both chains
    --------+--x-->  Ca
            |
            +-------->  Cb
    """

    block_of_interest_index = 0
    interface = make_interface(backend)

    res = submit_event_proof(
        interface,
        submit_proof,
        block_of_interest_index,
    )

    assert res["result"] == True

    res = submit_contesting_proof(
        interface,
        submit_proof,
        large_lca,
        large_contest_proof,
        block_of_interest_index,
    )
    assert res["result"] == True
예제 #3
0
def submit_over_contest(backend, mainchain_blocks, fork_point,
                        additional_blocks):
    """
    Display gas for submit and contest proofs
    Contest must succeed if we want to measure gas for both phases, so be sure contesting proof is bigger
    """

    # compile and deploy smart contract
    interface = make_interface(backend)

    # retrieve submit and contest proof
    (submit_proof, contest_lca,
     contest_proof) = init_proofs(backend, mainchain_blocks, fork_point,
                                  additional_blocks)

    # we want to prove the existance of a block that exists only in submit chain
    # for convinience, we pick the tip of submit proof
    block_of_interest_index = 0

    # start submit phase
    res = submit_event_proof(
        interface,
        submit_proof,
        block_of_interest_index,
    )
    # get the result. This includes the amount of gas used
    print("Submit proof gas:", res["gas"])
    # be sure that worked
    assert res["result"], "submit proof failed"

    # start contest phase
    res = submit_contesting_proof(
        interface,
        submit_proof,
        contest_lca,
        contest_proof,
        block_of_interest_index,
    )
    # get the result. This includes the amount of gas used
    print("Contest proof gas:", res["gas"])
    # be sure that worked
    assert res["result"], "contest proof failed"

    # close interfase
    interface.end()
예제 #4
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"]
예제 #5
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"]
예제 #6
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"]