testutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package testutil holds fixtures shared by the package tests.

Index

Constants

This section is empty.

Variables

View Source
var JSKeys = map[string]string{
	"020863639c1793cdc32abffca1c903f96d282de5530ab3167d661caf96b827369c": "8b0d3e5ee88edea5314eca1ae8d4f9e276bdc08ac163ba540dc312014b568e37",
	"023d1ef7a14d2d4c901afb3a244875c988f4e69ccd3df1575ae08097a314ccf8c0": "fa9b7df085feccaff5a83f74cb46381c623dc6dc652e598277a22d7659c37066",
	"02c322b7edb44fe8e0f4d8d70feb8a9c30b30721110a355ec9f200b4e49a4637d4": "0b43ca53b8875baf229faed396f0efdd21498984210bb3f4df04364299ee430b",
	"02e7247a4c155b63d182a23c70cb6fe8ba2e44bc9e9d62dc45d4c4167ccde95944": "5c557f3ca56651e22e68ee770da8e7cc6f12d30081f60a3ca4b5f9f3a9a5f9df",
	"031e1ec273bc1badb26164a4394b20e587c484ad9409ae20d0545a0976ec7d44b6": "c6a97e6b53e0f966e97cd91c58344ca1745c2a6dd64790eb0ee3adb3cd11d4d3",
	"03602a3da3eb35f1148e8028f141ec415ef7f6d4103443edbfec2a0711d716f53f": "1b57d51eec137085753bd911bd874024cd5d91edd8802809023666675635290b",
	"03c2c4887bb3fbc131f6874959a0fbe646d43a200cf81056e22f9405c1f58ba611": "4ba52f65ada1d2ca5f70c562202c1a9d9cbef125df78525b0737aff3d13653f4",
	"03eea986152805dcfe9292be7aa3560949e1db0f0972be4290824c11c661f419de": "b235eede06363471087291ddefeb31ce74209d43c29c87475d0ebb5397fd2c90",
	"0x01234567890abcdefghijklmnopqrstuvwxyz":                            "9c5d99a925257730d70ae64af9169d8f7e3aac27a211416698a00bfe8cd2e4bd",
	"QmFoo":  "efa068bfa5bd6d63ddbef943c55618f163f204b824be8a135de6c660a2a73d34",
	"key1":   "be88e7bb43ae78fa596966bf24d97ddfd0d17b88a1aafb9f22dd8b1d8c525d7f",
	"pubKey": "2dff73c70964e8cb9c7bcb1edfdd8ce327ef55ebdad92b2d2656a10f8583c57b",
	"userA":  "5f74f154ac4591ccf8a67f7edc98971759d684c07f53037ea0d361e2ba3f4683",
	"userB":  "7824c1579131baa6d6c34736b95c596c6c81afdb2f84654228eb2c75403e4c65",
	"userC":  "81f78e97259ce190f46141cb5a3d9a9c006557126e8bb752bc78d62d07c1bb3e",
	"userX":  "dfe24b20dbcb02217cf0a487f1db3004397160091ba6539dfb8042e94568f47e",
}

JSKeys are the raw secp256k1 private keys in the keystore fixture of the @orbitdb/core 4.0.0 test suite (test/fixtures/newtestkeys2), by keystore id. Loading them makes Go derive the same identities as the JavaScript tests, so the hashes those tests assert can be asserted here too.

Functions

func Keystore

func Keystore(t testing.TB) *keystore.KeyStore

Keystore returns an in-memory keystore preloaded with JSKeys.

Types

type AddressVector

type AddressVector struct {
	Address string  `json:"address"`
	Valid   bool    `json:"valid"`
	String  *string `json:"string"`
}

AddressVector is the result of isValidAddress and OrbitDBAddress.

type ClockVector

type ClockVector struct {
	ID   string `json:"id"`
	Time int64  `json:"time"`
}

ClockVector is a Lamport clock.

type EncryptionCase

type EncryptionCase struct {
	LogID    string `json:"logId"`
	Writer   string `json:"writer"`
	Appended []struct {
		Hash  string `json:"hash"`
		Bytes Hex    `json:"bytes"`
	} `json:"appended"`
	Payloads []any `json:"payloads"`
}

EncryptionCase is a log written with the toy cipher of the generator.

type EntryVector

type EntryVector struct {
	Name      string   `json:"name"`
	LogID     string   `json:"logId"`
	Writer    string   `json:"writer"`
	ClockTime int64    `json:"clockTime"`
	Next      []string `json:"next"`
	Refs      []string `json:"refs"`
	Payload   any      `json:"payload"`
	Hash      string   `json:"hash"`
	Bytes     Hex      `json:"bytes"`
}

EntryVector is a single entry created by userA (or Writer).

type Hex

type Hex []byte

Hex is a byte slice that unmarshals from a hex string.

func (*Hex) UnmarshalJSON

func (h *Hex) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type IdentityVector

type IdentityVector struct {
	ID         string            `json:"id"`
	PublicKey  string            `json:"publicKey"`
	Signatures map[string]string `json:"signatures"`
	Type       string            `json:"type"`
	Hash       string            `json:"hash"`
	Bytes      Hex               `json:"bytes"`
}

IdentityVector is an identity created for a fixture key id.

type IteratorCase

type IteratorCase struct {
	Options struct {
		GT     *int `json:"gt"`
		GTE    *int `json:"gte"`
		LT     *int `json:"lt"`
		LTE    *int `json:"lte"`
		Amount *int `json:"amount"`
	} `json:"options"`
	Payloads []string `json:"payloads"`
}

IteratorCase gives iterator options as indexes into IteratorVectors.Hashes.

type IteratorVectors

type IteratorVectors struct {
	LogID  string         `json:"logId"`
	Writer string         `json:"writer"`
	Size   int            `json:"size"`
	Hashes []string       `json:"hashes"`
	Cases  []IteratorCase `json:"cases"`
}

IteratorVectors are Log.Iterator results over a 100-entry log.

type LogResult

type LogResult struct {
	Values []ValueVector `json:"values"`
	Heads  []string      `json:"heads"`
	Clock  ClockVector   `json:"clock"`
}

LogResult describes a log at the end of a scenario.

type LogScenario

type LogScenario struct {
	LogID   string               `json:"logId"`
	Writers map[string]string    `json:"writers"`
	Ops     [][]any              `json:"ops"`
	Results []any                `json:"results"`
	Final   map[string]LogResult `json:"final"`
}

LogScenario is a sequence of log operations and the resulting logs.

Ops are ["append", log, payload, referencesCount], ["join", into, from] or ["joinEntry", into, from, index].

type ManifestVector

type ManifestVector struct {
	Write                 []string       `json:"write"`
	AccessController      string         `json:"accessController"`
	AccessControllerBytes Hex            `json:"accessControllerBytes"`
	Name                  string         `json:"name"`
	Type                  string         `json:"type"`
	Meta                  any            `json:"meta"`
	Hash                  string         `json:"hash"`
	Bytes                 Hex            `json:"bytes"`
	Manifest              map[string]any `json:"manifest"`
	Address               string         `json:"address"`
	HeadsProtocol         string         `json:"headsProtocol"`
}

ManifestVector is a database manifest with its access controller.

type ValueVector

type ValueVector struct {
	Hash    string      `json:"hash"`
	Payload any         `json:"payload"`
	Next    []string    `json:"next"`
	Refs    []string    `json:"refs"`
	Clock   ClockVector `json:"clock"`
}

ValueVector is one entry of LogResult.Values.

type Vectors

type Vectors struct {
	Generator  string                    `json:"generator"`
	Identities map[string]IdentityVector `json:"identities"`
	Entries    []EntryVector             `json:"entries"`
	Logs       map[string]LogScenario    `json:"logs"`
	Iterators  IteratorVectors           `json:"iterators"`
	Manifests  []ManifestVector          `json:"manifests"`
	Addresses  []AddressVector           `json:"addresses"`
	Encryption map[string]EncryptionCase `json:"encryption"`
	// SimpleEncryption are ciphertexts of @orbitdb/simple-encryption.
	SimpleEncryption []struct {
		Password   string `json:"password"`
		Plaintext  Hex    `json:"plaintext"`
		Ciphertext Hex    `json:"ciphertext"`
	} `json:"simpleEncryption"`
}

Vectors is the decoded content of testdata/js-vectors.json.

func JSVectors

func JSVectors(t testing.TB) *Vectors

JSVectors returns the golden vectors.

Jump to

Keyboard shortcuts

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