跳转到内容

沙盒自测

operator-conformance 是一个命令行工具,它完全按平台的方式调用你的钱包接口,并逐条检查协议规则:幂等、冲正与墓碑、分段扣款、批量语义和签名拒绝。通过它是生产审核的前提。

工具用 Go 编写。请向你的 Star Game 对接人(contact@sentosatower.com)索取:我们提供 Linux、macOS、Windows 预编译文件,或 Go 源码。从源码构建(Go 1.26 及以上):

终端窗口
go build -o operator-conformance ./cmd/operator-conformance
  1. 在沙盒钱包中创建一个测试玩家,余额至少 1000 个最小单位。

  2. 为该玩家签发两个新的启动码。

  3. 用沙盒钱包基础地址和沙盒签名密钥运行:

    终端窗口
    OPERATOR_WALLET_URL=https://api.example.com/game-wallet/v1 \
    OPERATOR_WALLET_SECRET=whsec_… \
    GAME_ID=lantern \
    ./operator-conformance <launch_code_1> <launch_code_2>

    GAME_ID 可选(默认 conformance)。运行耗时几秒,上限 2 分钟。

结束后测试玩家的余额回到初始值:每笔扣款要么被冲正,要么被等额加款抵消。交易号都以 conf-<随机>: 开头,方便你在日志中查找。

退出码:0 全部通过(WARN 为建议项),1 至少一项失败,2 无法开始(配置错误、认证失败、余额不足 1000)。

# 检查 规则
1 authenticate 启动码返回 player_id、session_id、currency
2 launch code is single-use (SHOULD) 第一个启动码再次使用被拒——建议项(WARN,不算失败)
3 balance sufficient for the suite 测试玩家余额 ≥ 1000
4 debit books and returns balance 扣 100 → ok,余额减少
5 replayed debit returns first result without booking again 幂等
6 same id with different amount is duplicate_mismatch 内容不一致检测
7 debit above balance is insufficient_funds 余额不足拒绝
8 replayed failed debit returns the first result 失败结果同样幂等
9 credit referencing a booked debit books 派彩
10 several debits in one round all book; payout references the first 分段扣款
11 rollback refunds the debit 冲正
12 second rollback of the same debit does not refund twice 冲正幂等
13 credit referencing a rolled-back debit is reference_not_found 已冲正的投注不派彩
14 rollback before its debit is ok, and the late debit is rolled_back and not booked 墓碑
15 batch returns one result per item in order; one failure does not fail the batch 批量语义(21 项)
16 batch rollback restores the balance 20 笔批量冲正
17 second launch code authenticates the same player 同一玩家的新会话
18 unsigned, wrong-key, tampered-body and stale requests are rejected with 401 签名校验
19 net balance unchanged after the suite 没有资金泄漏

对我们的参考运营方运行的输出:

PASS authenticate (player=p1 session=true currency=GOLD err=<nil>)
PASS launch code is single-use (SHOULD) (second use err=wallet: invalid launch code)
PASS balance sufficient for the suite (balance=100000 need>=1000)
PASS debit books and returns balance (status=ok balance=99900 want=99900)
PASS replayed debit returns first result without booking again (status=ok balance=99900)
PASS same id with different amount is duplicate_mismatch (status=duplicate_mismatch)
PASS debit above balance is insufficient_funds (status=insufficient_funds)
PASS replayed failed debit returns the first result (status=insufficient_funds)
PASS credit referencing a booked debit books (status=ok balance=100000 want=100000)
PASS several debits in one round all book; payout references the first (debits=ok,ok credit=ok balance=100000 want=100000)
PASS rollback refunds the debit (debit=ok rollback=ok balance=100000 want=100000)
PASS second rollback of the same debit does not refund twice (status=ok balance=100000)
PASS credit referencing a rolled-back debit is reference_not_found (status=reference_not_found)
PASS rollback before its debit is ok, and the late debit is rolled_back and not booked (rollback=ok late debit=rolled_back balance=100000 want=100000 err=<nil>)
PASS batch returns one result per item in order; one failure does not fail the batch (ok=20/20 last=insufficient_funds)
PASS batch rollback restores the balance (all ok=true balance=100000 want=100000)
PASS second launch code authenticates the same player (player=p1 err=<nil>)
PASS unsigned, wrong-key, tampered-body and stale requests are rejected with 401 (unsigned=401 wrong key=401 tampered=401 stale=401)
PASS net balance unchanged after the suite (balance=100000 start=100000)
19/19 passed

从你的 App 用沙盒入口地址打开几款游戏,玩真实对局(下注、赢、输、对局中充值),并把你的钱包流水与「商户控制台 → 数据」(「沙盒」标签页)对照。然后在「商户控制台 → 概览」点击「申请开通生产环境」。