vectorcases

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	OutcomeFound       = "found"
	OutcomeNotFound    = "not_found"
	OutcomeUnreachable = "unreachable"
)

The outcomes of a replayed answer (SPEC.md section 13.2).

View Source
const (
	PolicyFirst   = "first"
	PolicyAtLeast = "at_least"
	PolicyAll     = "all"
)

The source policies of SPEC.md section 9.

Variables

View Source
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).

View Source
var ErrUnreachable = errors.New("vectorcases: the replayed answer is unreachable")

ErrUnreachable marks a read whose replayed answer is unreachable.

View Source
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

func Dir

func Dir() string

Dir returns the absolute path of testdata/verification/vectors.

func Path

func Path(relative string) string

Path joins a path relative to vectors/, as cases.json writes one, under Dir.

func StepIndex

func StepIndex(step string) int

StepIndex returns the position of step in Steps, or -1.

Types

type Answer

type Answer struct {
	Outcome string
	Value   map[string]any
	Reason  string
}

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

func Load() ([]Case, error)

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.

func (Case) Family

func (c Case) Family() string

Family is the first hyphen-separated word of a case's id, such as parse for parse-depth-33.

func (Case) ProofPath

func (c Case) ProofPath() string

ProofPath is the absolute path of the case's proof.

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.

func (Expected) Bare

func (e Expected) Bare() bool

Bare reports whether the case expects a bare rejection: a code and no label (SPEC.md section 13.2), since a report case may give its code too.

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

type Record struct {
	Kind    string
	Network string
	Source  string
}

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

func LoadCaseReplay(c Case) (*Replay, error)

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

func LoadReplay(relative string) (*Replay, error)

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

func ParseReplay(data []byte) (*Replay, error)

ParseReplay reads a replay file's bytes, as LoadReplay does.

func (*Replay) Answer

func (r *Replay) Answer(read map[string]any, source string) (Answer, bool)

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

func (r *Replay) Identity(chain, network, source string) (string, error)

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

func (r *Replay) Keyring(url string) (any, error)

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.

func (*Replay) Records

func (r *Replay) Records() []Record

Records returns what each record holds besides its answer, in the file's order.

func (*Replay) Sources

func (r *Replay) Sources() []Source

Sources returns the sources whose identity read the file holds, in the file's order: the file stands as each (SPEC.md section 13.2).

type Row

type Row struct {
	Code   *string
	Part   *string
	Status string
	Step   string
}

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) String

func (r Row) String() string

String writes the row as cases.json does, for messages.

func (*Row) UnmarshalJSON

func (r *Row) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a row from its four-element array.

type Source

type Source struct {
	Chain   string
	Network string
	Name    string
}

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL