def test_asset_missmatch(connected_clients): alice, bob, charlie, david, eric, fred = connected_clients try: quantity = 5 sync_fee = david.channel_terms["sync_fee"] commit = _create_commit(david, quantity + sync_fee) h2c_next_revoke_secret_hash = david._gen_secret() david._add_to_commits_requested(h2c_next_revoke_secret_hash) params = { "handle": david.handle, "sends": [{ "payee_handle": alice.handle, "amount": quantity, "token": "deadbeef" }], "commit": commit, "revokes": None, "next_revoke_secret_hash": h2c_next_revoke_secret_hash } params = auth.sign_json(params, david.api.auth_wif) api.mph_sync(**params) assert False except err.AssetMissmatch: assert True
def test_validate_commit_format(connected_clients): alice, bob, charlie, david, eric, fred = connected_clients try: secret = lib.create_secret() params = { "handle": alice.handle, "sends": [], "commit": "invalidformat", "revokes": None, "next_revoke_secret_hash": secret["secret_hash"] } params = auth.sign_json(params, alice.api.auth_wif) api.mph_sync(**params) assert False except jsonschema.exceptions.ValidationError: assert True
def test_standard_commit(connected_clients): alice, bob, charlie, david, eric, fred = connected_clients quantity = 5 sync_fee = alice.channel_terms["sync_fee"] commit = _create_commit(alice, quantity + sync_fee) h2c_next_revoke_secret_hash = alice._gen_secret() alice._add_to_commits_requested(h2c_next_revoke_secret_hash) params = { "handle": alice.handle, "sends": [{ "payee_handle": alice.handle, "amount": quantity, "token": "deadbeef" }], "commit": commit, "revokes": None, "next_revoke_secret_hash": h2c_next_revoke_secret_hash } params = auth.sign_json(params, alice.api.auth_wif) result = api.mph_sync(**params) assert result["receive"] == [{ "payer_handle": alice.handle, "token": "deadbeef", "amount": 5 }] assert result["commit"] is not None
def test_pubkey_missmatch(connected_clients): alice, bob, charlie, david, eric, fred = connected_clients try: secret = lib.create_secret() handle = alice.handle wif = keys.generate_wif(netcode=etc.netcode) params = { "handle": handle, "sends": [], "commit": None, "revokes": None, "next_revoke_secret_hash": secret["secret_hash"] } params = auth.sign_json(params, wif) api.mph_sync(**params) assert False except err.ClientPubkeyMissmatch: assert True
def test_send_exceeds_max(connected_clients): alice, bob, charlie, david, eric, fred = connected_clients # check before status alice_status = alice.get_status() assert alice_status["send_balance"] == 1000000 bob_status = bob.get_status() assert bob_status["send_balance"] == 1000000 try: secret = lib.create_secret() params = { "handle": alice.handle, "sends": [{ "payee_handle": bob.handle, "amount": 1000000, "token": "deadbeef" }], "commit": None, "revokes": None, "next_revoke_secret_hash": secret["secret_hash"] } params = auth.sign_json(params, alice.api.auth_wif) api.mph_sync(**params) assert False except err.AmountExceedsSpendable: assert True # check after status alice_status = alice.get_status() assert alice_status["send_balance"] == 1000000 bob_status = bob.get_status() assert bob_status["send_balance"] == 1000000 # actors can still sync assert alice.sync() == [] assert bob.sync() == []