feat: add probation and ban enforcement
This commit is contained in:
@@ -7,10 +7,10 @@ import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
from meshnet_gateway.server import GatewayServer
|
||||
from meshnet_gateway.server import GatewayServer, _banned_route_wallet
|
||||
from meshnet_node.server import StubNodeServer
|
||||
from meshnet_contracts import LocalSolanaContracts
|
||||
from meshnet_tracker.server import TrackerServer
|
||||
from meshnet_tracker.server import TrackerServer, _registration_ban_error
|
||||
|
||||
|
||||
def _post_json(url: str, payload: dict) -> dict:
|
||||
@@ -252,11 +252,15 @@ def test_tracker_excludes_banned_wallets_from_routes():
|
||||
{"endpoint": "http://127.0.0.1:9001", "shard_start": 0, "shard_end": 15,
|
||||
"hardware_profile": {}, "wallet_address": "wallet-a", "score": 1.0},
|
||||
)
|
||||
_post_json(
|
||||
f"http://127.0.0.1:{tracker_port}/v1/nodes/register",
|
||||
{"endpoint": "http://127.0.0.1:9002", "shard_start": 16, "shard_end": 31,
|
||||
"hardware_profile": {}, "wallet_address": "wallet-b", "score": 1.0},
|
||||
)
|
||||
try:
|
||||
_post_json(
|
||||
f"http://127.0.0.1:{tracker_port}/v1/nodes/register",
|
||||
{"endpoint": "http://127.0.0.1:9002", "shard_start": 16, "shard_end": 31,
|
||||
"hardware_profile": {}, "wallet_address": "wallet-b", "score": 1.0},
|
||||
)
|
||||
raise AssertionError("Expected 403 for banned wallet registration")
|
||||
except urllib.error.HTTPError as exc:
|
||||
assert exc.code == 403
|
||||
|
||||
try:
|
||||
_get_json(f"http://127.0.0.1:{tracker_port}/v1/route?model=stub-model")
|
||||
@@ -269,6 +273,52 @@ def test_tracker_excludes_banned_wallets_from_routes():
|
||||
tracker.stop()
|
||||
|
||||
|
||||
def test_tracker_rejects_banned_wallet_registration():
|
||||
"""A banned wallet cannot register with the tracker."""
|
||||
contracts = LocalSolanaContracts()
|
||||
contracts.registry.submit_stake("wallet-b", 1_000)
|
||||
contracts.registry.ban_wallet("wallet-b")
|
||||
tracker = TrackerServer(contracts=contracts, minimum_stake=100)
|
||||
tracker_port = tracker.start()
|
||||
try:
|
||||
try:
|
||||
_post_json(
|
||||
f"http://127.0.0.1:{tracker_port}/v1/nodes/register",
|
||||
{"endpoint": "http://127.0.0.1:9002", "shard_start": 0, "shard_end": 31,
|
||||
"hardware_profile": {}, "wallet_address": "wallet-b", "score": 1.0},
|
||||
)
|
||||
raise AssertionError("Expected 403 for banned wallet registration")
|
||||
except urllib.error.HTTPError as exc:
|
||||
assert exc.code == 403
|
||||
body = json.loads(exc.read())
|
||||
assert body == {"error": "wallet is banned"}
|
||||
finally:
|
||||
tracker.stop()
|
||||
|
||||
|
||||
def test_tracker_ban_registration_guard_reads_contract_state():
|
||||
"""The tracker registration guard reads ban status from the contract facade."""
|
||||
contracts = LocalSolanaContracts()
|
||||
contracts.registry.ban_wallet("wallet-b")
|
||||
|
||||
assert _registration_ban_error(contracts, "wallet-b") == "wallet is banned"
|
||||
assert _registration_ban_error(contracts, "wallet-a") is None
|
||||
assert _registration_ban_error(None, "wallet-b") is None
|
||||
|
||||
|
||||
def test_gateway_route_guard_rejects_banned_wallet_metadata():
|
||||
"""Gateway rejects tracker routes that include a wallet now banned on-chain."""
|
||||
contracts = LocalSolanaContracts()
|
||||
contracts.registry.ban_wallet("wallet-b")
|
||||
|
||||
banned_wallet = _banned_route_wallet(
|
||||
contracts,
|
||||
[{"endpoint": "http://node", "wallet_address": "wallet-b"}],
|
||||
)
|
||||
|
||||
assert banned_wallet == "wallet-b"
|
||||
|
||||
|
||||
def test_gateway_routes_even_when_compute_node_has_low_stake():
|
||||
"""Routing is not based on a compute node's token balance."""
|
||||
contracts = LocalSolanaContracts()
|
||||
|
||||
Reference in New Issue
Block a user