schema: add message receipts + description and comments informational fields (#209)

This commit is contained in:
Raúl Kripalani 2020-08-06 17:20:17 +01:00 committed by GitHub
parent 8203a5d2c3
commit fd35438a30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 18 deletions

View File

@ -21,9 +21,19 @@
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"id": { "id": {
"title": "a unique identifier that identifies this test vector",
"type": "string" "type": "string"
}, },
"version": { "version": {
"title": "the version of this test vector",
"type": "string"
},
"description": {
"title": "an optional description of the test vector",
"type": "string"
},
"comment": {
"title": "optional comments about this test vector, e.g. applicability, hints, rationale, etc.",
"type": "string" "type": "string"
}, },
"gen": { "gen": {
@ -68,6 +78,26 @@
} }
} }
}, },
"receipt": {
"type": "object",
"required": [
"exit_code",
"return",
"gas_used"
],
"additionalProperties": false,
"properties": {
"exit_code": {
"type": "number"
},
"return": {
"$ref": "#/definitions/hex"
},
"gas_used": {
"type": "number"
}
}
},
"preconditions": { "preconditions": {
"title": "execution preconditions", "title": "execution preconditions",
"description": "preconditions that need to be applied and satisfied before this test vector can be executed", "description": "preconditions that need to be applied and satisfied before this test vector can be executed",
@ -92,18 +122,23 @@
"title": "state tree postconditions", "title": "state tree postconditions",
"description": "state tree postconditions that must be true for this test vector to pass", "description": "state tree postconditions that must be true for this test vector to pass",
"$ref": "#/definitions/state_tree" "$ref": "#/definitions/state_tree"
},
"receipts": {
"title": "receipts to match",
"description": "receipts to match, required when using messages-class test vectors; length of this array MUST be equal to length of apply_messages",
"type": "array",
"items": {
"$ref": "#/definitions/receipt"
}
} }
} }
}, },
"apply_messages": { "apply_messages": {
"title": "messages to apply, hex-encoded", "title": "messages to apply, along with the receipt to expect for each",
"type": "array", "type": "array",
"items": [ "items": {
{
"type": "string",
"$ref": "#/definitions/hex" "$ref": "#/definitions/hex"
} }
]
} }
}, },
"required": [ "required": [
@ -115,7 +150,7 @@
"description": "test vector class; depending on the value, the apply_* property to provide (and its schema) will vary; the relevant apply property is apply_[class]", "description": "test vector class; depending on the value, the apply_* property to provide (and its schema) will vary; the relevant apply property is apply_[class]",
"type": "string", "type": "string",
"enum": [ "enum": [
"message", "messages",
"block", "block",
"tipset", "tipset",
"chain" "chain"
@ -146,7 +181,7 @@
"if": { "if": {
"properties": { "properties": {
"class": { "class": {
"const": "message" "const": "messages"
} }
} }
}, },

View File

@ -1,34 +1,40 @@
{ {
"class": "message", "class": "messages",
"selector": "<some predicate for the driver to determine if this vector applies to the implementation, e.g. to deal with protocol upgrades>", "selector": "<some predicate for the driver to determine if this vector applies to the implementation, e.g. to deal with protocol upgrades>",
"_meta": { "_meta": {
"id": "test_vector_id", "id": "test_vector_id",
"version": "version_id", "version": "version_id",
"description": "tests that the VM rejects a message containing...",
"comment": "this message should never actually be fed to the VM, because the block would be deemed invalid by the syncer",
"gen": { "gen": {
"source": "lotus", "source": "lotus",
"version": "0.4.1+git.27d74337+api0.8.1" "version": "0.4.1+git.27d74337+api0.8.1"
} }
}, },
"car_bytes": "0x890043009920583103b5b1fab6769fcb464146d192af785915d8e1dacff264b2be3bcb7bf4064a77cb3b13e27063ea4825dc48cd0a7df77e211916e748002740f0c493a2824200011a09d9c4dc0758c68219091c58c083e7c59e748e070b382a813f4ffe8ead2a090469aaa37f0664b82c092bc78b43fac300335cd2d6e4a8c71ce138003c0fa8ee1707b41aa87f35c811613d59ac53449aef8263aa51c876f2e67c185118ec9628f73442f58e093909ce952e431e770ac693cdbe99f2f9404ad3ca754196ab443c6c66afa41310e705e453496bdcedf0f271529dc7374021d7b80d343397f996d06bf11e753a49eaed7b3ce80a8e9bbaa48bf83223527bd8a2933f002949fdb8058103336a4a979375d5e963cdd7b1", "car_bytes": "0x890043009920583103b5b1fab6769fcb464146d192af785915d8e1dacff264b2be3bcb7bf4064a77cb3b13e27063ea4825dc48cd0a7df77e211916e748002740f0c493a2824200011a09d9c4dc0758c68219091c58c083e7c59e748e070b382a813f4ffe8ead2a090469aaa37f0664b82c092bc78b43fac300335cd2d6e4a8c71ce138003c0fa8ee1707b41aa87f35c811613d59ac53449aef8263aa51c876f2e67c185118ec9628f73442f58e093909ce952e431e770ac693cdbe99f2f9404ad3ca754196ab443c6c66afa41310e705e453496bdcedf0f271529dc7374021d7b80d343397f996d06bf11e753a49eaed7b3ce80a8e9bbaa48bf83223527bd8a2933f002949fdb8058103336a4a979375d5e963cdd7b1",
"preconditions": { "preconditions": {
"height": 100, "epoch": 100,
"state_tree": { "state_tree": {
"root_cid": { "root_cid": {
"/": "bafy2bzacebbxsepazfgwepawspvzenb2x64pmqjyan3wgtfpxu5nxez33wzkc" "/": "bafy2bzacebbxsepazfgwepawspvzenb2x64pmqjyan3wgtfpxu5nxez33wzkc"
} }
} }
}, },
"apply_messages": [
"apply_message": "0x89004300ba20583103b85358cc1c968d826c0a0efcde99b6e4db138edfc051f188a4471cfc23ccf7884adbbac912e45f7363774bf16f83ca8f1902b44800505e1442e66b744200011a09d225c80758c68219016f58c099a447a8c80988e1c061dd3a8dd674033c3a6083c4b55cf035e6e8de3baf09436ad00adf6eb14d58ae6691d22ce82255874047e7aa0b9a86bbf424afc6d89dc29f7b253dd04c88a625b86345f05aa0bdee503971c1e9735ed5b81c31ad41a1f10b387d96151d1cbd0c4286267daf04087fd8d5272f870994c3732f3fc4f54287a485d6c8dafb6056df3fc9233f849027b4c1272850435126fef65a8363768a858c0cc5f9d9114ff378ad50cab25ab0a2f685ca63d9f1f7727da4d06db5b80b5f", "0x89004300ba20583103b85358cc1c968d826c0a0efcde99b6e4db138edfc051f188a4471cfc23ccf7884adbbac912e45f7363774bf16f83ca8f1902b44800505e1442e66b744200011a09d225c80758c68219016f58c099a447a8c80988e1c061dd3a8dd674033c3a6083c4b55cf035e6e8de3baf09436ad00adf6eb14d58ae6691d22ce82255874047e7aa0b9a86bbf424afc6d89dc29f7b253dd04c88a625b86345f05aa0bdee503971c1e9735ed5b81c31ad41a1f10b387d96151d1cbd0c4286267daf04087fd8d5272f870994c3732f3fc4f54287a485d6c8dafb6056df3fc9233f849027b4c1272850435126fef65a8363768a858c0cc5f9d9114ff378ad50cab25ab0a2f685ca63d9f1f7727da4d06db5b80b5f"
],
"postconditions": { "postconditions": {
"state_tree": { "state_tree": {
"root_cid": { "root_cid": {
"/": "bafy2bzacebbxsepazfgwepawspvzenb2x64pmqjyan3wgtfpxu5nxez33wzkc" "/": "bafy2bzacebbxsepazfgwepawspvzenb2x64pmqjyan3wgtfpxu5nxez33wzkc"
} }
} },
"receipts": [
{
"exit_code": 10,
"gas_used": 1000,
"return": "0x"
}
]
} }
} }

View File

@ -3,8 +3,10 @@ package main
import ( import (
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"fmt"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
) )
@ -29,6 +31,8 @@ type Selector string
type Metadata struct { type Metadata struct {
ID string `json:"id"` ID string `json:"id"`
Version string `json:"version"` Version string `json:"version"`
Desc string `json:"description"`
Comment string `json:"comment"`
Gen GenerationData `json:"gen"` Gen GenerationData `json:"gen"`
} }
@ -54,9 +58,17 @@ type Preconditions struct {
StateTree *StateTree `json:"state_tree"` StateTree *StateTree `json:"state_tree"`
} }
// Receipt represents a receipt to match against.
type Receipt struct {
ExitCode exitcode.ExitCode `json:"exit_code"`
ReturnValue HexEncodedBytes `json:"return"`
GasUsed int64 `json:"gas_used"`
}
// Postconditions contain a representation of VM state at th end of the test // Postconditions contain a representation of VM state at th end of the test
type Postconditions struct { type Postconditions struct {
StateTree *StateTree `json:"state_tree"` StateTree *StateTree `json:"state_tree"`
Receipts []*Receipt `json:"receipts"`
} }
// MarshalJSON implements json.Marshal for HexEncodedBytes // MarshalJSON implements json.Marshal for HexEncodedBytes
@ -94,3 +106,15 @@ type TestVector struct {
ApplyMessages []HexEncodedBytes `json:"apply_messages"` ApplyMessages []HexEncodedBytes `json:"apply_messages"`
Post *Postconditions `json:"postconditions"` Post *Postconditions `json:"postconditions"`
} }
// Validate validates this test vector against the JSON schema, and applies
// further validation rules that cannot be enforced through JSON Schema.
func (tv TestVector) Validate() error {
// TODO validate against JSON Schema.
if tv.Class == ClassMessage {
if len(tv.Post.Receipts) != len(tv.ApplyMessages) {
return fmt.Errorf("length of postcondition receipts must match length of messages to apply")
}
}
return nil
}