Esempio n. 1
0
def test_validate_asset_in_terms():
    try:
        asset = "DIVISIBLE"
        client_key = lib.create_key(asset)
        secret_hash = util.hash160hex(util.b2h(os.urandom(32)))
        params = {"asset": asset, "spend_secret_hash": secret_hash}
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        api.mph_request(**params)
        assert False
    except err.AssetNotInTerms:
        assert True
Esempio n. 2
0
def test_validate_asset_exists():
    try:
        asset = "NONEXISTINGASSET"
        client_key = lib.create_key(asset)
        secret_hash = util.hash160hex(util.b2h(os.urandom(32)))
        params = {"asset": asset, "spend_secret_hash": secret_hash}
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        api.mph_request(**params)
        assert False
    except err.AssetDoesNotExist:
        assert True
Esempio n. 3
0
def test_validate_url():
    try:
        asset = "XCP"
        client_key = lib.create_key(asset)
        secret_hash = util.hash160hex(util.b2h(os.urandom(32)))
        params = {
            "asset": asset,
            "spend_secret_hash": secret_hash,
            "hub_rpc_url": "?? invalid url ??",
        }
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        api.mph_request(**params)
        assert False
    except err.InvalidUrl:
        assert True
def test_validate_deposit_not_already_given():
    try:
        asset = "XCP"
        client_key = lib.create_key(asset, netcode="XTN")
        client_pubkey = client_key["pubkey"]

        h2c_spend_secret = util.b2h(os.urandom(32))
        h2c_spend_secret_hash = util.hash160hex(h2c_spend_secret)

        params = {"asset": asset, "spend_secret_hash": h2c_spend_secret_hash}
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        result = api.mph_request(**params)

        handle = result["handle"]
        hub_pubkey = result["pubkey"]
        c2h_spend_secret_hash = result["spend_secret_hash"]

        c2h_deposit_script = compile_deposit_script(client_pubkey, hub_pubkey,
                                                    c2h_spend_secret_hash,
                                                    1337)

        # submit deposit
        next_revoke_secret_hash = util.hash160hex(util.b2h(os.urandom(32)))

        params = {
            "handle": handle,
            "deposit_script": c2h_deposit_script,
            "next_revoke_secret_hash": next_revoke_secret_hash
        }
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        result = api.mph_deposit(**params)
        assert result is not None
        jsonschema.validate(result, DEPOSIT_RESULT_SCHEMA)

        # resubmit deposit
        next_revoke_secret_hash = util.hash160hex(util.b2h(os.urandom(32)))
        params = {
            "handle": handle,
            "deposit_script": c2h_deposit_script,
            "next_revoke_secret_hash": next_revoke_secret_hash
        }
        privkey = keys.wif_to_privkey(client_key["wif"])
        params = auth.sign_json(params, privkey)
        result = api.mph_deposit(**params)

        assert False
    except err.DepositAlreadyGiven:
        assert True
Esempio n. 5
0
def test_standard_usage_xcp():
    asset = "XCP"
    client_key = lib.create_key(asset)
    secret_hash = util.hash160hex(util.b2h(os.urandom(32)))
    params = {
        "asset": asset,
        "spend_secret_hash": secret_hash,
        "hub_rpc_url": "https://does.not.exist",
    }
    privkey = keys.wif_to_privkey(client_key["wif"])
    params = auth.sign_json(params, privkey)
    result = api.mph_request(**params)
    assert result is not None
    jsonschema.validate(result, REQUEST_RESULT_SCHEMA)