def decode(record):
    version = record.get("schema", 1)
    if version == 1:
        # 示例旧契约明确规定：amount 是人民币分。
        amount, currency = record["amount"], "CNY"
    elif version == 2:
        amount = record["money"]["minor"]
        currency = record["money"]["currency"]
    else:
        raise ValueError("不支持的数据版本")
    if type(amount) is not int or amount < 0:
        raise ValueError("金额必须是非负整数最小单位")
    if currency != "CNY":
        raise ValueError("此用例尚未支持该币种")
    return {"minor": amount, "currency": currency}


old = {"schema": 1, "amount": 1250}
new = {"schema": 2, "money": {"minor": 1250, "currency": "CNY"}}
assert decode(old) == decode(new)
for bad in ({"schema": 99}, {"schema": 1, "amount": 12.5}):
    try:
        decode(bad)
    except ValueError:
        pass
    else:
        raise AssertionError("应拒绝未知版本或错误单位类型")
print("旧记录和新记录保持相同语义")
