tests

package
v0.0.0-...-198e6eb Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: Apache-2.0, BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Timeout denotes the default condition polling timout duration.
	Timeout = 1 * time.Minute
	// Tick denotes the default condition polling tick time.
	Tick = 500 * time.Millisecond
)

Variables

View Source
var ConsensusSnapshotOptions = []options.Option[snapshotcreator.Options]{
	snapshotcreator.WithFilePath("/assets/dynamic_snapshots/consensus_snapshot.bin"),
	snapshotcreator.WithGenesisTokenAmount(800_000),
	snapshotcreator.WithPeersSeedBase58([]string{
		"Bk69VaYsRuiAaKn8hK6KxUj45X5dED3ueRtxfYnsh4Q8",
		"HUH4rmxUxMZBBtHJ4QM5Ts6s8DP3HnFpChejntnCxto2",
		"CmFVE14Yh9rqn2FrXD8s7ybRoRN5mUnqQxLAuD5HF2em",
		"DuJuWE3hisFrFK1HmrXkd9FSsNNWbw58JcQnKdBn6TdN",
	}),
	snapshotcreator.WithPeersAmountsPledged([]uint64{1_600_000, 800_000, 800_000, 800_000, 800_000}),
	snapshotcreator.WithInitialAttestationsBase58([]string{"3kwsHfLDb7ifuxLbyMZneXq3s5heRWnXKKGPAARJDaUE"}),
}
View Source
var EqualSnapshotOptions = []options.Option[snapshotcreator.Options]{
	snapshotcreator.WithFilePath("/assets/dynamic_snapshots/equal_snapshot.bin"),
	snapshotcreator.WithGenesisTokenAmount(2_500_000_000_000_000),
	snapshotcreator.WithPeersSeedBase58([]string{
		"GtKSdqanb4mokUBjAf9JZmsSqWzWjzzw57mRR56LjfBL",
		"CmFVE14Yh9rqn2FrXD8s7ybRoRN5mUnqQxLAuD5HF2em",
		"DuJuWE3hisFrFK1HmrXkd9FSsNNWbw58JcQnKdBn6TdN",
		"3YX6e7AL28hHihZewKdq6CMkEYVsTJBLgRiprUNiNq5E",
	}),
	snapshotcreator.WithPeersAmountsPledged([]uint64{2_500_000_000_000_000, 2_500_000_000_000_000, 2_500_000_000_000_000, 2_500_000_000_000_000}),
	snapshotcreator.WithInitialAttestationsBase58([]string{"B45CgJeL9rfigCNXdkReZoVmK4RJqw4E81zYuETA4zJC"}),
}

EqualSnapshotOptions defines snapshot options for equal test scenario.

View Source
var OrphanageSnapshotOptions = []options.Option[snapshotcreator.Options]{
	snapshotcreator.WithFilePath("/assets/dynamic_snapshots/orphanage_snapshot.bin"),
	snapshotcreator.WithGenesisTokenAmount(0),
	snapshotcreator.WithPeersSeedBase58([]string{
		"3YX6e7AL28hHihZewKdq6CMkEYVsTJBLgRiprUNiNq5E",
		"GtKSdqanb4mokUBjAf9JZmsSqWzWjzzw57mRR56LjfBL",
		"CmFVE14Yh9rqn2FrXD8s7ybRoRN5mUnqQxLAuD5HF2em",
		"DuJuWE3hisFrFK1HmrXkd9FSsNNWbw58JcQnKdBn6TdN",
	}),
	snapshotcreator.WithPeersAmountsPledged([]uint64{2_500_000_000_000_000, 2_500_000_000_000_000, 2_500_000_000_000_000, 10}),
}

OrphanageSnapshotOptions defines snapshot options for orphanage test scenario.

Functions

func AcceptedOnAllPeers

func AcceptedOnAllPeers(blockID string, peers []*framework.Node) bool

AcceptedOnAllPeers checks if the blk is accepted on all supplied peers.

func AddressUnspentOutputs

func AddressUnspentOutputs(t *testing.T, node *framework.Node, address devnetvm.Address, numOfExpectedOuts int) []jsonmodels.WalletOutput

AddressUnspentOutputs returns the unspent outputs on address.

func Balance

func Balance(t *testing.T, node *framework.Node, address devnetvm.Address, color devnetvm.Color) uint64

Balance returns the total balance of color at address.

func BootstrapNetwork

func BootstrapNetwork(t *testing.T, n *framework.Network)

func Bootstrapped

func Bootstrapped(t *testing.T, node *framework.Node) bool

Bootstrapped returns whether node is bootstrapped.

func CommonSnapshotConfigFunc

func CommonSnapshotConfigFunc(t *testing.T, snapshotOptions *snapshotcreator.Options, cfgFunc ...framework.CfgAlterFunc) framework.CfgAlterFunc

CommonSnapshotConfigFunc returns a peer configuration altering function that uses the specified Snapshot information for all peers. If a cfgFunc is provided, further manipulation of the base config for every peer is possible.

func Context

Context creates a new context that matches the test deadline.

func CreateTransactionFromOutputs

func CreateTransactionFromOutputs(t *testing.T, manaPledgeID identity.ID, targetAddresses []devnetvm.Address, keyPairs map[string]*ed25519.KeyPair, utxos ...devnetvm.Output) *devnetvm.Transaction

CreateTransactionFromOutputs takes the given utxos inputs and create a transaction that spreads the total input balance across the targetAddresses. In order to correctly sign we have a keyPair map that maps a given address to its public key. Access and Consensus Mana is pledged to the node we specify.

func GetIdentSeed

func GetIdentSeed(t *testing.T, snapshotOptions *snapshotcreator.Options, peerIndex int) []byte

GetIdentSeed returns decoded seed bytes for the supplied SnapshotInfo and peer index

func Mana

func Mana(t *testing.T, node *framework.Node) jsonmodels.Mana

Mana returns the mana reported by node.

func OutputIndex

func OutputIndex(transaction *devnetvm.Transaction, address devnetvm.Address) int

OutputIndex returns the index of the first output to address.

func RequireBalancesEqual

func RequireBalancesEqual(t *testing.T, nodes []*framework.Node, balancesByAddress map[string]map[devnetvm.Color]uint64)

RequireBalancesEqual asserts that all nodes report the balances as specified in balancesByAddress.

func RequireBlocksAvailable

func RequireBlocksAvailable(t *testing.T, nodes []*framework.Node, blockIDs map[string]DataBlockSent, waitFor time.Duration, tick time.Duration, accepted ...bool)

RequireBlocksAvailable asserts that all nodes have received BlockIDs in waitFor time, periodically checking each tick. Optionally, a ConfirmationState can be specified, which then requires the blocks to reach this ConfirmationState.

func RequireBlocksEqual

func RequireBlocksEqual(t *testing.T, nodes []*framework.Node, blocksByID map[string]DataBlockSent, waitFor time.Duration, tick time.Duration)

RequireBlocksEqual asserts that all nodes return the correct data blocks as specified in blocksByID.

func RequireBlocksOrphaned

func RequireBlocksOrphaned(t *testing.T, nodes []*framework.Node, blockIDs map[string]DataBlockSent, waitFor time.Duration, tick time.Duration)

RequireBlocksOrphaned asserts that all nodes have received BlockIDs and marked them as orphaned in waitFor time, periodically checking each tick.

func RequireConfirmationStateEqual

func RequireConfirmationStateEqual(t *testing.T, nodes framework.Nodes, expectedStates ExpectedTxsStates, waitFor time.Duration, tick time.Duration)

RequireConfirmationStateEqual asserts that all nodes have received the transaction and have correct expectedStates in waitFor time, periodically checking each tick.

func RequireTransactionsEqual

func RequireTransactionsEqual(t *testing.T, nodes []*framework.Node, transactionsByID map[string]*ExpectedTransaction)

RequireTransactionsEqual asserts that all nodes return the correct transactions as specified in transactionsByID.

func SendDataBlocks

func SendDataBlocks(t *testing.T, peers []*framework.Node, numBlocks int, idsMap ...map[string]DataBlockSent) map[string]DataBlockSent

SendDataBlocks sends a total of numBlocks data blocks and saves the sent block to a map. It chooses the peers to send the blocks from in a round-robin fashion.

func SendDataBlocksWithDelay

func SendDataBlocksWithDelay(t *testing.T, peers []*framework.Node, numBlocks int, delay time.Duration, idsMap ...map[string]DataBlockSent) (result map[string]DataBlockSent)

SendDataBlocksWithDelay sends a total of numBlocks data blocks, each after a delay interval, and saves the sent block to a map. It chooses the peers to send the blocks from in a round-robin fashion.

func SendTransaction

func SendTransaction(t *testing.T, from *framework.Node, to *framework.Node, color devnetvm.Color, value uint64, txConfig TransactionConfig, addrBalance ...map[string]map[devnetvm.Color]uint64) (string, error)

SendTransaction sends a transaction of value and color. It returns the transactionID and the error return by PostTransaction. If addrBalance is given the balance mutation are added to that map.

func ShutdownNetwork

func ShutdownNetwork(ctx context.Context, t *testing.T, n interface{ Shutdown(context.Context) error })

ShutdownNetwork shuts down the network and reports errors.

func Synced

func Synced(t *testing.T, node *framework.Node) bool

Synced returns whether node is synchronized.

func True

func True() *bool

True returns a pointer to a true bool.

func TryAcceptBlock

func TryAcceptBlock(t *testing.T, peers []*framework.Node, blockID string, waitFor time.Duration, tick time.Duration)

TryAcceptBlock tries to accept the block on all the peers provided within the time limit provided.

Types

type DataBlockSent

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

DataBlockSent defines a struct to identify from which issuer a data block was sent.

func SendDataBlock

func SendDataBlock(t *testing.T, node *framework.Node, data []byte, number int) (string, DataBlockSent)

SendDataBlock sends a data block on a given peer and returns the id and a DataBlockSent struct.

func SendFaucetRequest

func SendFaucetRequest(t *testing.T, node *framework.Node, addr devnetvm.Address, manaPledgeIDs ...string) (string, DataBlockSent)

SendFaucetRequest sends a data block on a given peer and returns the id and a DataBlockSent struct. By default, it pledges mana to the peer making the request.

type ExpectedAddrsBalances

type ExpectedAddrsBalances map[string]map[devnetvm.Color]uint64

ExpectedAddrsBalances is a map of base58 encoded addresses to the balances they should hold.

type ExpectedState

type ExpectedState struct {
	// The optional confirmation state to check against.
	ConfirmationState confirmation.State
	// The optional solid state to check against.
	Solid *bool
}

ExpectedState is an expected state. All fields are optional.

type ExpectedTransaction

type ExpectedTransaction struct {
	Inputs []*jsonmodels.Input
	// The optional outputs to check against.
	Outputs []*jsonmodels.Output
	// The optional unlock blocks to check against.
	UnlockBlocks []*jsonmodels.UnlockBlock
}

ExpectedTransaction defines the expected data of a transaction. All fields are optional.

type ExpectedTxsStates

type ExpectedTxsStates map[string]ExpectedState

ExpectedTxsStates is a map of base58 encoded transactionIDs to their ExpectedState(s).

type TransactionConfig

type TransactionConfig struct {
	FromAddressIndex      uint64
	ToAddressIndex        uint64
	AccessManaPledgeID    identity.ID
	ConsensusManaPledgeID identity.ID
}

TransactionConfig defines the configuration for a transaction.

Jump to

Keyboard shortcuts

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