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} params = auth.sign_json(params, client_key["wif"]) api.mph_request(**params) assert False except err.AssetDoesNotExist: assert True
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} params = auth.sign_json(params, client_key["wif"]) api.mph_request(**params) assert False except err.AssetNotInTerms: 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 } params = auth.sign_json(params, client_key["wif"]) 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 } params = auth.sign_json(params, client_key["wif"]) 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 } params = auth.sign_json(params, client_key["wif"]) result = api.mph_deposit(**params) assert False except err.DepositAlreadyGiven: assert True
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", } params = auth.sign_json(params, client_key["wif"]) result = api.mph_request(**params) assert result is not None jsonschema.validate(result, REQUEST_RESULT_SCHEMA)
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 ??", } params = auth.sign_json(params, client_key["wif"]) api.mph_request(**params) assert False except err.InvalidUrl: assert True
def test_validate_handle_exists(): try: asset = "XCP" client_key = lib.create_key(asset, netcode="XTN") next_revoke_secret_hash = util.hash160hex(util.b2h(os.urandom(32))) c2h_deposit_script = util.b2h(os.urandom(32)), params = { "handle": "deadbeef", "deposit_script": c2h_deposit_script, "next_revoke_secret_hash": next_revoke_secret_hash } params = auth.sign_json(params, client_key["wif"]) api.mph_deposit(**params) assert False except err.HandleNotFound: 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} params = auth.sign_json(params, client_key["wif"]) 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 } params = auth.sign_json(params, client_key["wif"]) 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 } params = auth.sign_json(params, client_key["wif"]) result = api.mph_deposit(**params) assert False except err.DepositAlreadyGiven: assert True