コード例 #1
0
def test_vsp_authorize(http_get_post):
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    success = {"status": "success", "data": purchaseInfo}
    addressNotSet = {
        "status": "error",
        "code": 9,
        "message": "no address submitted",
    }

    # ok
    addr = "TkKmVKG7u7PwhQaYr7wgMqBwHneJ2cN4e5YpMVUsWSopx81NFXEzK"
    http_get_post(pool.apiPath("getpurchaseinfo"), success)
    pool.authorize(addr)

    # address not submitted
    addr = "TkKmVKG7u7PwhQaYr7wgMqBwHneJ2cN4e5YpMVUsWSopx81NFXEzK"
    http_get_post(pool.apiPath("getpurchaseinfo"), addressNotSet)
    http_get_post(pool.apiPath("getpurchaseinfo"), success)
    http_get_post((pool.apiPath("address"), repr({"UserPubKeyAddr": addr})),
                  success)
    pool.authorize(addr)

    # other error
    systemErr = {"status": "error", "code": 14, "message": "system error"}
    addr = "TkKmVKG7u7PwhQaYr7wgMqBwHneJ2cN4e5YpMVUsWSopx81NFXEzK"
    http_get_post(pool.apiPath("getpurchaseinfo"), systemErr)
    with pytest.raises(DecredError):
        pool.authorize(addr)

    # wrong address
    addr = "TkQ4jEVTpGn1LZBPrAoUJ15fDGGHubzd1DDkMSc4hxtHXpHjW1BJ8"
    http_get_post(pool.apiPath("getpurchaseinfo"), systemErr)
    with pytest.raises(DecredError):
        pool.authorize(addr)
コード例 #2
0
def test_vsp_get_stats(http_get_post):
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    success = {"status": "success", "data": poolStats}

    # ok
    http_get_post(pool.apiPath("stats"), success)
    pool.getStats()

    # pool error
    systemErr = {"status": "error", "code": 14, "message": "system error"}
    http_get_post(pool.apiPath("stats"), systemErr)
    with pytest.raises(DecredError):
        pool.getStats()
コード例 #3
0
def test_vsp_live():
    the_vsp = vsp.VotingServiceProvider(VSP_URL, API_KEY, testnet.Name)
    the_vsp.authorize(SIGNING_ADDRESS)
    the_vsp.getStats()
    purc_info = the_vsp.getPurchaseInfo()
    # Test voting.
    if purc_info.voteBits & (1 << 1) != 0:
        nextVote = 1 | (1 << 2)
    else:
        nextVote = 1 | (1 << 1)
    the_vsp.setVoteBits(nextVote)
    purc_info = the_vsp.getPurchaseInfo()
    assert purc_info.voteBits == nextVote
コード例 #4
0
def test_vsp_update_purchase_info(http_get_post):
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    success = {"status": "success", "data": purchaseInfo}

    # updated
    pool.purchaseInfo.unixTimestamp = 0
    http_get_post(pool.apiPath("getpurchaseinfo"), success)
    pool.updatePurchaseInfo()
    assert pool.purchaseInfo.unixTimestamp != 0

    # not updated
    # within the update threshhold
    before = int(time.time() - vsp.PURCHASE_INFO_LIFE / 2)
    pool.purchaseInfo.unixTimestamp = before
    pool.updatePurchaseInfo()
    assert pool.purchaseInfo.unixTimestamp == before
コード例 #5
0
def test_vsp_set_vote_bits(http_get_post):
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    success = {"status": "success", "data": "ok"}

    # votebits are 5
    assert pool.purchaseInfo.voteBits == 5

    # ok
    http_get_post((pool.apiPath("voting"), repr({"VoteBits": 7})), success)
    pool.setVoteBits(7)
    # set to 7
    assert pool.purchaseInfo.voteBits == 7

    # pool error
    systemErr = {"status": "error", "code": 14, "message": "system error"}
    http_get_post((pool.apiPath("voting"), repr({"VoteBits": 3})), systemErr)
    with pytest.raises(DecredError):
        pool.setVoteBits(3)
    # no change
    assert pool.purchaseInfo.voteBits == 7
コード例 #6
0
def test_vsp_get_purchase_info(http_get_post):
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    success = {"status": "success", "data": purchaseInfo}

    addressNotSet = {
        "status": "error",
        "code": 9,
        "message": "no address submitted",
    }

    # ok
    http_get_post(pool.apiPath("getpurchaseinfo"), success)
    pool.getPurchaseInfo()
    assert not pool.err

    # error
    http_get_post(pool.apiPath("getpurchaseinfo"), addressNotSet)
    with pytest.raises(DecredError):
        pool.getPurchaseInfo()
    assert pool.err
コード例 #7
0
def test_vsp_validate():
    pool = vsp.VotingServiceProvider(**votingServiceProvider)

    # correct address
    addr = "TkKmVKG7u7PwhQaYr7wgMqBwHneJ2cN4e5YpMVUsWSopx81NFXEzK"
    pool.validate(addr)

    # valid but wrong address
    addr = "TkQ4jEVTpGn1LZBPrAoUJ15fDGGHubzd1DDkMSc4hxtHXpHjW1BJ8"
    with pytest.raises(DecredError):
        pool.validate(addr)

    # invalid address
    addr = "ASDF"
    with pytest.raises(DecredError):
        pool.validate(addr)

    # no address
    addr = ""
    with pytest.raises(DecredError):
        pool.validate(addr)
コード例 #8
0
def test_vsp_blobbing():

    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    b = vsp.VotingServiceProvider.blob(pool)
    assert isinstance(b, bytearray)

    rePool = vsp.VotingServiceProvider.unblob(b)
    assertVspIsEqual(rePool)
    ts = rePool.purchaseInfo.unixTimestamp
    assert isinstance(ts, int) and ts == pool.purchaseInfo.unixTimestamp

    # bad version
    bCopy = encode.ByteArray(b, copy=True)
    bCopy[0] = 255
    with pytest.raises(NotImplementedError):
        vsp.VotingServiceProvider.unblob(bCopy.bytes())

    # too long
    bCopy = encode.ByteArray(b, copy=True)
    bCopy += b"\x00"
    with pytest.raises(DecredError):
        vsp.VotingServiceProvider.unblob(bCopy.bytes())
コード例 #9
0
def test_vsp_headers():
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    headers = pool.headers()
    assert headers == {
        "Authorization": "Bearer " + votingServiceProvider["apiKey"]
    }
コード例 #10
0
def test_vsp_api_path():
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    path = pool.apiPath("stakeinfo")
    assert path == "https://www.dcrstakedinner.com/api/v2/stakeinfo"
コード例 #11
0
def test_vsp_serialize():
    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    b = vsp.VotingServiceProvider.blob(pool)
    assert pool.serialize() == encode.ByteArray(b)
コード例 #12
0
def test_vsp_init():

    pool = vsp.VotingServiceProvider(**votingServiceProvider)
    assertVspIsEqual(pool)
    ts = pool.purchaseInfo.unixTimestamp
    assert isinstance(ts, int) and ts >= now