mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
42 lines
3.0 KiB
GDScript
42 lines
3.0 KiB
GDScript
extends "res://tests/test_case.gd"
|
|
|
|
const Client = preload("res://scripts/server_result_client.gd")
|
|
|
|
|
|
func test_result_nonce_is_deterministic_and_score_bound() -> void:
|
|
var first := Client.result_nonce("match-123456789", "server-123456789", 3, 2, "CERTIFIED")
|
|
assert_eq(first, Client.result_nonce("match-123456789", "server-123456789", 3, 2, "CERTIFIED"), "retry keeps the exact nonce")
|
|
assert_true(first != Client.result_nonce("match-123456789", "server-123456789", 2, 3, "CERTIFIED"), "a conflicting score cannot reuse the nonce")
|
|
assert_true(first.length() >= 16, "nonce satisfies the control-plane minimum")
|
|
|
|
|
|
func test_result_configuration_fails_closed() -> void:
|
|
assert_true(Client.valid_configuration("https://control.invalid", "token", "match-123456789", "server-123456789"), "valid result reporter configuration is accepted")
|
|
assert_true(not Client.valid_configuration("https://control.invalid?token=leak", "token", "match-123456789", "server-123456789"), "query-bearing endpoint is rejected")
|
|
assert_true(not Client.valid_configuration("https://control@evil.invalid", "token", "match-123456789", "server-123456789"), "userinfo-bearing endpoint is rejected")
|
|
assert_true(not Client.valid_configuration("https://control.invalid", "", "match-123456789", "server-123456789"), "empty bearer is rejected")
|
|
|
|
|
|
func test_only_a_committed_result_acknowledgement_releases_the_match() -> void:
|
|
assert_true(Client.response_is_accepted(202), "the endpoint's accepted response releases RESULTS")
|
|
assert_true(not Client.response_is_accepted(200), "an unexpected generic success cannot lose the result")
|
|
assert_true(not Client.response_is_accepted(422), "validation failure remains held for operator-visible retry")
|
|
assert_true(not Client.response_is_accepted(503), "outage remains held for retry")
|
|
|
|
|
|
func test_review_results_are_permitted_but_forged_states_are_not() -> void:
|
|
var client := Client.new()
|
|
assert_true(client.configure("https://control.invalid", "token", "match-123456789", "server-123456789"), "test client configures")
|
|
# submit itself is asynchronous; the pure configuration boundary proves the
|
|
# reporter can carry the REVIEW state selected by bounded overtime.
|
|
assert_true(Client.result_nonce("match-123456789", "server-123456789", 1, 1, "REVIEW") != Client.result_nonce("match-123456789", "server-123456789", 1, 1, "CERTIFIED"), "integrity state binds the receipt identity")
|
|
|
|
|
|
func test_match_net_forwards_review_integrity_to_the_reporter() -> void:
|
|
var received: Array = []
|
|
MatchNet.configure_result_submission(func(team_0: int, team_1: int, integrity: String): received.append_array([team_0, team_1, integrity]))
|
|
assert_true(MatchNet.submit_authoritative_result({0: 1, 1: 1}, "REVIEW"), "configured reporter accepts the bounded-overtime outcome")
|
|
assert_eq(received, [1, 1, "REVIEW"], "review state reaches the reporter and cannot become a rated result")
|
|
MatchNet.configure_result_submission(Callable())
|
|
assert_true(not MatchNet.submit_authoritative_result({0: 1, 1: 1}, "CERTIFIED"), "cleared reporter cannot silently claim result delivery")
|