pytest: add schema support for JSON responses.

This adds our first (basic) schema, and sews support into pyln-testing
so it will load schemas for any method for doc/schemas/{method}.schema.json.

All JSON responses in a test run are checked against the schema (if any).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-05-26 15:17:01 +09:30
parent 8a67c4a1ba
commit ea99a05249
6 changed files with 237 additions and 4 deletions

View File

@@ -0,0 +1,72 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"pays": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"payment_hash": {
"type": "hex",
"description": "the hash of the *payment_preimage* which will prove payment",
"maxLength": 64,
"minLength": 64
},
"status": {
"type": "string",
"enum": [ "pending", "failed", "complete" ],
"description": "status of the payment"
},
"destination": {
"type": "pubkey",
"description": "the final destination of the payment if known"
},
"amount_msat": {
"type": "msat",
"description": "the amount the destination received, if known (**status** *complete* or *pending*)"
},
"amount_sent_msat": {
"type": "msat",
"description": "the amount we actually sent, including fees (**status** *complete* or *pending*)"
},
"created_at": {
"type": "u64",
"description": "the UNIX timestamp showing when this payment was initiated"
},
"preimage": {
"type": "hex",
"description": "proof of payment, only if (and always if) **status** is *complete*",
"FIXME": "we should enforce the status/payment_preimage relation in the schema!",
"maxLength": 64,
"minLength": 64
},
"label": {
"type": "string",
"description": "the label, if given to sendpay"
},
"bolt11": {
"type": "string",
"description": "the bolt11 string (if pay supplied one)"
},
"bolt12": {
"type": "string",
"description": "the bolt12 string (if supplied for pay: **experimental-offers** only)."
},
"erroronion": {
"type": "hex",
"description": "the error onion returned on failure, if any."
},
"number_of_parts": {
"type": "u64",
"description": "the number of parts for a successful payment (only if more than one, and **status** is *complete*)."
}
},
"required": [ "payment_hash", "status", "created_at" ]
}
}
},
"required": [ "pays" ]
}