testutil

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0, MIT Imports: 23 Imported by: 1

Documentation

Overview

Package testutil is a fork of some components of github.com/ipfs/go-graphsync/testutil in order to avoid networking dependencies imposed by Graphsync.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsIdentity added in v0.3.0

func AsIdentity(key string) (digest []byte, ok bool, err error)

func MakeDagWithIdentity added in v0.3.0

func MakeDagWithIdentity(t *testing.T, lsys linking.LinkSystem) unixfs.DirEntry

MakeDagWithIdentity makes a non-unixfs DAG, wrapped in the go-unixfsnode/testutil/DirEntry struct (so it can be used in all the places DirEntry is) that has an identity CID in the middle linking a section that the identity CID must be traversed through to find.

func RandomBytes

func RandomBytes(n int64) []byte

RandomBytes returns a byte array of the given size with random values.

Types

type CorrectedMemStore added in v0.3.0

type CorrectedMemStore struct {
	ParentStore
}

TODO: remove when this is fixed in IPLD prime

func (*CorrectedMemStore) Get added in v0.3.0

func (cms *CorrectedMemStore) Get(ctx context.Context, key string) ([]byte, error)

func (*CorrectedMemStore) GetStream added in v0.3.0

func (cms *CorrectedMemStore) GetStream(ctx context.Context, key string) (io.ReadCloser, error)

type ParentStore added in v0.3.0

type TestBlockChain

type TestBlockChain struct {
	GenisisNode ipld.Node
	GenisisLink ipld.Link
	MiddleNodes []ipld.Node
	MiddleLinks []ipld.Link
	TipNode     ipld.Node
	TipLink     ipld.Link
	// contains filtered or unexported fields
}

TestBlockChain is a simulated data structure similar to a blockchain

func SetupBlockChain

func SetupBlockChain(
	ctx context.Context,
	t testing.TB,
	lsys ipld.LinkSystem,
	size uint64,
	blockChainLength int) *TestBlockChain

SetupBlockChain creates a new test block chain with the given height

func (*TestBlockChain) AllBlocks

func (tbc *TestBlockChain) AllBlocks() []blocks.Block

AllBlocks returns all blocks for a blockchain

func (*TestBlockChain) Blocks

func (tbc *TestBlockChain) Blocks(from int, to int) []blocks.Block

Blocks Returns the given raw blocks for the block chain for the given range, indexed from the tip

func (*TestBlockChain) Chooser

func (tbc *TestBlockChain) Chooser(ipld.Link, ipld.LinkContext) (ipld.NodePrototype, error)

Chooser is a NodeBuilderChooser function that always returns the block chain

func (*TestBlockChain) LinkTipIndex

func (tbc *TestBlockChain) LinkTipIndex(fromTip int) ipld.Link

LinkTipIndex returns a link to the block at the given index from the tip

func (*TestBlockChain) NodeTipIndex

func (tbc *TestBlockChain) NodeTipIndex(fromTip int) ipld.Node

NodeTipIndex returns the node to the block at the given index from the tip

func (*TestBlockChain) PathTipIndex

func (tbc *TestBlockChain) PathTipIndex(fromTip int) ipld.Path

PathTipIndex returns the path to the block at the given index from the tip

func (*TestBlockChain) RemainderBlocks

func (tbc *TestBlockChain) RemainderBlocks(from int) []blocks.Block

RemainderBlocks returns the remaining blocks for a blockchain, indexed from tip

func (*TestBlockChain) Selector

func (tbc *TestBlockChain) Selector() ipld.Node

Selector returns the selector to recursive traverse the block chain parent links

type ZeroReader added in v0.3.0

type ZeroReader struct{}

func (ZeroReader) Read added in v0.3.0

func (ZeroReader) Read(b []byte) (n int, err error)

Directories

Path Synopsis
Package chaintypes is a fork of some components of github.com/ipfs/go-graphsync/testutil/chaintypes in order to avoid networking dependencies imposed by Graphsync.
Package chaintypes is a fork of some components of github.com/ipfs/go-graphsync/testutil/chaintypes in order to avoid networking dependencies imposed by Graphsync.

Jump to

Keyboard shortcuts

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