availability_test

package
v0.0.0-...-4e9d6c2 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillBS

func FillBS(t *testing.T, bServ blockservice.BlockService, shares []share.Share) *share.Root

FillBS fills the given BlockService with the given shares.

func MockNode

func MockNode(t *testing.T, net *TestDagNet) (*TestNode, *FraudulentBlockstore)

MockNode creates a TestNode that uses a FraudulentBlockstore to simulate serving corrupted data.

func RandFillBS

func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *share.Root

RandFillBS fills the given BlockService with a random block of a given size.

Types

type CorruptBlock

type CorruptBlock struct {
	// contains filtered or unexported fields
}

CorruptBlock is a block where the cid doesn't match the data. It fulfills the blocks.Block interface.

func NewCorruptBlock

func NewCorruptBlock(data []byte, fakeCID cid.Cid) *CorruptBlock

func (*CorruptBlock) Cid

func (b *CorruptBlock) Cid() cid.Cid

func (*CorruptBlock) Loggable

func (b *CorruptBlock) Loggable() map[string]interface{}

func (*CorruptBlock) RawData

func (b *CorruptBlock) RawData() []byte

func (*CorruptBlock) String

func (b *CorruptBlock) String() string

type FraudulentBlockstore

type FraudulentBlockstore struct {
	ds.Datastore
	Attacking bool
}

FraudulentBlockstore is a mock blockstore.Blockstore that saves both corrupted and original data for every block it receives. If FraudulentBlockstore.Attacking is true, it will serve the corrupted data on requests.

func (FraudulentBlockstore) AllKeysChan

func (fb FraudulentBlockstore) AllKeysChan(context.Context) (<-chan cid.Cid, error)

func (FraudulentBlockstore) DeleteBlock

func (fb FraudulentBlockstore) DeleteBlock(context.Context, cid.Cid) error

func (FraudulentBlockstore) Get

func (fb FraudulentBlockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error)

func (FraudulentBlockstore) GetSize

func (fb FraudulentBlockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error)

func (FraudulentBlockstore) Has

func (fb FraudulentBlockstore) Has(context.Context, cid.Cid) (bool, error)

func (FraudulentBlockstore) HashOnRead

func (fb FraudulentBlockstore) HashOnRead(bool)

func (FraudulentBlockstore) Put

func (FraudulentBlockstore) PutMany

func (fb FraudulentBlockstore) PutMany(ctx context.Context, blocks []blocks.Block) error

type SubNet

type SubNet struct {
	*TestDagNet
	// contains filtered or unexported fields
}

func (*SubNet) AddNode

func (sn *SubNet) AddNode(nd *TestNode)

func (*SubNet) ConnectAll

func (sn *SubNet) ConnectAll()

type TestDagNet

type TestDagNet struct {
	T *testing.T
	// contains filtered or unexported fields
}

func NewTestDAGNet

func NewTestDAGNet(ctx context.Context, t *testing.T) *TestDagNet

NewTestDAGNet creates a new testing swarm utility to spawn different nodes and test how they interact and/or exchange data.

func (*TestDagNet) Connect

func (dn *TestDagNet) Connect(peerA, peerB peer.ID)

Connect connects two given peers.

func (*TestDagNet) ConnectAll

func (dn *TestDagNet) ConnectAll()

ConnectAll connects all the peers on registered on the TestDagNet.

func (*TestDagNet) Disconnect

func (dn *TestDagNet) Disconnect(peerA, peerB peer.ID)

Disconnect disconnects two peers. It does a hard disconnect, meaning that disconnected peers won't be able to reconnect on their own but only with DagNet.Connect or TestDagNet.ConnectAll.

func (*TestDagNet) NewTestNode

func (dn *TestDagNet) NewTestNode() *TestNode

NewTestNode creates a plain network node that can serve and request data.

func (*TestDagNet) NewTestNodeWithBlockstore

func (dn *TestDagNet) NewTestNodeWithBlockstore(dstore ds.Datastore, bstore blockstore.Blockstore) *TestNode

NewTestNodeWithBlockstore creates a new plain TestNode with the given blockstore that can serve and request data.

func (*TestDagNet) SubNet

func (dn *TestDagNet) SubNet() *SubNet

type TestNode

type TestNode struct {
	share.Getter
	share.Availability
	blockservice.BlockService
	host.Host
	// contains filtered or unexported fields
}

func (*TestNode) ClearStorage

func (n *TestNode) ClearStorage()

ClearStorage cleans up the storage of the node.

Jump to

Keyboard shortcuts

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