Documentation
¶
Overview ¶
Package vectorcases loads the conformance cases of SPEC.md section 13.2 (The vectors), testdata/verification/vectors/cases.json, for the tests that run them. It is test support: no command imports it.
A case decodes into typed structs, the members of a case that section 13.2 lists. The one runner over the cases is this package's runner_test.go, which runs every case through every step of section 10.2, each online case answered from its replay file by the replay adapter (replay.go). The conformance test of section 13.1, conformance_test.go's TestConformance, runs every case through that runner and compares exactly what section 13.1 compares; the per-step tests beside it compare more.
cases.json is decoded by encoding/json/v2, which shares no code with the strict reader the runner tests, so a defect in that reader cannot hide in the cases it is compared with. The decode refuses unknown members, a repeated member name and invalid UTF-8, and the runner also parses cases.json with the strict reader. cases.json is larger than MAX_READ_OCTETS, which binds a document and not a data file (SPEC.md section 9), so that parse does not make J1.
Index ¶
Constants ¶
const ( OutcomeFound = "found" OutcomeNotFound = "not_found" OutcomeUnreachable = "unreachable" )
The outcomes of a replayed answer (SPEC.md section 13.2).
const ( PolicyFirst = "first" PolicyAtLeast = "at_least" PolicyAll = "all" )
The source policies of SPEC.md section 9.
Variables ¶
var ErrNoAnswer = errors.New("vectorcases: a read the replay file does not hold")
ErrNoAnswer marks a read the replay file does not hold: under an online case it has no answer, and the test that makes it fails (SPEC.md section 13.2).
var ErrUnreachable = errors.New("vectorcases: the replayed answer is unreachable")
ErrUnreachable marks a read whose replayed answer is unreachable.
var Steps = []string{
"CONFIGURATION", "READ", "PARSE", "ENVELOPE", "ENVIRONMENT", "KEY_BINDING",
"SIGNATURE", "SHAPE", "POLICY", "DERIVE", "CHAIN", "SOURCES", "WINDOW",
"EXPECTED_HASH", "VERDICT",
}
Steps are the steps of SPEC.md section 10.2, in their order.
Functions ¶
Types ¶
type Answer ¶
Answer is one replayed answer: Outcome, with Value for a found answer and Reason, informational only, for an unreachable one.
type Case ¶
type Case struct {
// ID is the case's name, unique in the file.
ID string `json:"id"`
// Proof is the path of its proof, relative to vectors/.
Proof string `json:"proof"`
Config Config `json:"config"`
Expected Expected `json:"expected"`
}
Case is one case of cases.json (SPEC.md section 13.2).
func Load ¶
Load reads every case of cases.json, in the file's order. A member the structs above do not name, a case without an id, proof or environment, two cases with one id, and a case's sources that SPEC.md section 13.2 does not allow ([checkSources]) are errors.
type Config ¶
type Config struct {
// Environment is the verifier's environment, E_v.
Environment string `json:"environment"`
// ExpectedHash is the caller's hash, or nil when none is given.
ExpectedHash *string `json:"expected_hash"`
// Keyring is test, none, unavailable or the path of a keyring file, or
// nil when neither a keyring nor keyless mode is asked for.
Keyring *string `json:"keyring"`
// Networks gives every pin for the case.
Networks Networks `json:"networks"`
// Online is the path of the case's replay file under corpus/replay/, or
// nil for an offline case.
Online *string `json:"online"`
// Sources gives, by chain and then network, the several sources of
// each Stellar or Bitcoin network the case pins that has them (SPEC.md
// section 9), only beside Online; a network it does not name has one
// source, under the policy first (SPEC.md section 13.2).
Sources map[string]map[string]NetworkSources `json:"sources"`
}
Config is a case's configuration.
type Expected ¶
type Expected struct {
Code string `json:"code"`
SubReason string `json:"sub_reason"`
Label string `json:"label"`
Rows []Row `json:"rows"`
// Trace is the path of a trace file, for a case that gives a sound
// proof's trace.
Trace string `json:"trace"`
// SubmittedAfter and SubmittedBefore are an online case's edges, each
// null or {basis, instant}, kept as their JSON.
SubmittedAfter jsontext.Value `json:"submitted_after"`
SubmittedBefore jsontext.Value `json:"submitted_before"`
}
Expected is a case's expected output (SPEC.md section 13.2): a bare rejection's Code and SubReason, with no Label; or a report's Label and Rows, with Code, the report's code, for a case whose point is which failing row decides it, and the empty string otherwise.
type NetworkSources ¶
type NetworkSources struct {
Policy string `json:"policy"`
Required *int `json:"required"`
Sources []string `json:"sources"`
}
NetworkSources is one network's sources in a case's Sources (SPEC.md section 13.2): Sources, the names of the network's sources in their order, each an ASCII16, one or more, no two the same; Policy, first, at_least or all; and Required, the n of at_least n, from 1 to the number of sources, present exactly when Policy is at_least.
type Networks ¶
type Networks struct {
Commitment map[string]string `json:"commitment"`
Entropy map[string]string `json:"entropy"`
}
Networks is a case's commitment pin per chain and entropy pin per source.
type Record ¶
Record is what a record holds besides its answer: the kind and the network of its read, the network the empty string for a read with none, and its source, the empty string for a record without one.
type Replay ¶
type Replay struct {
// contains filtered or unexported fields
}
Replay is a replay file's reads, by read and source.
func LoadCaseReplay ¶
LoadCaseReplay reads the replay file of the online case c, as LoadReplay does, and holds each record's source to c's sources (SPEC.md section 13.2): a record of a read of a network c's sources name has a source, one of that network's names there, and no other record has one.
func LoadReplay ¶
LoadReplay reads the replay file at relative, a path under vectors/ as a case's online member writes it. The file is an object whose one member, reads, is an array of {answer, read} and {answer, read, source} records, no two with the same read and the same source or both without one; a source is an ASCII16, and only a read of a Stellar or Bitcoin network, one whose kind begins stellar_ or bitcoin_, has one; each answer is {outcome: found, value}, {outcome: not_found} or {outcome: unreachable, reason}, and a kind that is never not_found has no such answer; a keyring read's found value is exactly {keyring}; and an identity read is exactly {kind, network}, a network of its chain, whose found value is exactly {network_passphrase}, an ASCII128, for Stellar, and {hash}, a HEX64, for Bitcoin (SPEC.md section 13.2's table).
func ParseReplay ¶
ParseReplay reads a replay file's bytes, as LoadReplay does.
func (*Replay) Answer ¶
Answer returns the replayed answer to read from source, the empty string for a network's one source and for a read of no network, and whether the file holds it.
func (*Replay) Identity ¶
Identity answers the identity read of network of chain from source, the empty string for the network's one source (SPEC.md section 13.2's kinds stellar_identity and bitcoin_identity): the value read, Stellar's network_passphrase or the hash of Bitcoin's block at height 0, for a found answer; an error wrapping ErrUnreachable, with the reason, for an unreachable one; and ErrNoAnswer when the file holds no such read from that source.
func (*Replay) Keyring ¶
Keyring answers the keyring read at url (SPEC.md section 13.2's keyring kind): the keyring value read, which the load checks then judge, for a found answer; an error wrapping ErrUnreachable, with the reason, for an unreachable one; and ErrNoAnswer when the file holds no read of url.
type Row ¶
Row is a report row reduced as SPEC.md section 13.1 compares it: (code, part, status, step), where a nil Code or Part is null.
func (*Row) UnmarshalJSON ¶
UnmarshalJSON reads a row from its four-element array.
type Source ¶
Source is a Stellar or Bitcoin source whose identity read a replay file holds, found or unreachable: Name is the empty string for the record of a network's one source, and the source's name for a named one. The file stands as that network's operator-pinned source, or as that named source (SPEC.md section 13.2).