mock

package
v1.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 40 Imported by: 3

Documentation

Index

Constants

View Source
const NetworkMainPartition = "main"

Variables

View Source
var (
	ErrBlockAttacherInvalidBlock              = ierrors.New("invalid block")
	ErrBlockAttacherAttachingNotPossible      = ierrors.New("attaching not possible")
	ErrBlockAttacherIncompleteBlockNotAllowed = ierrors.New("incomplete block is not allowed on this node")
	ErrBlockTooRecent                         = ierrors.New("block is too recent compared to latest commitment")
)
View Source
var NewEvents = event.CreateGroupConstructor(func() (newEvents *Events) {
	return &Events{
		BlockConstructed: event.New1[*model.Block](),
		BlockIssued:      event.New1[*model.Block](),
		Error:            event.New1[error](),
	}
})

NewEvents contains the constructor of the Events object (it is generated by a generic factory).

Functions

func AccountConversionManaCost

func AccountConversionManaCost(protocolParameters iotago.ProtocolParameters) iotago.Mana

TODO: add the correct formula later.

func MaxBlockManaCost

func MaxBlockManaCost(protocolParameters iotago.ProtocolParameters) iotago.Mana

TODO: add the correct formula later.

func MinDelegationAmount

func MinDelegationAmount(protocolParameters iotago.ProtocolParameters) iotago.BaseToken

func MinIssuerAccountAmount

func MinIssuerAccountAmount(protocolParameters iotago.ProtocolParameters) iotago.BaseToken

func MinValidatorAccountAmount

func MinValidatorAccountAmount(protocolParameters iotago.ProtocolParameters) iotago.BaseToken

func RegisterIDAlias

func RegisterIDAlias(id peer.ID, alias string)

RegisterIDAlias registers an alias that will modify the String() output of the ID to show a human readable string instead of the base58 encoded version of itself.

func UnregisterIDAliases

func UnregisterIDAliases()

UnregisterIDAliases removes all aliases registered through the RegisterIDAlias function.

func WithAccountIncreasedFoundryCounter

func WithAccountIncreasedFoundryCounter(diff uint32) options.Option[builder.AccountOutputBuilder]

func WithAllotAllManaToAccount

func WithAllotAllManaToAccount(slot iotago.SlotIndex, accountID iotago.AccountID) options.Option[builder.TransactionBuilder]

func WithAllotments

func WithAllotments(allotments iotago.Allotments) options.Option[builder.TransactionBuilder]

func WithBasicBlockHeader

func WithBasicBlockHeader(opts ...options.Option[BlockHeaderParams]) func(builder *BasicBlockParams)

func WithBlockIssuerExpirySlot

func WithBlockIssuerExpirySlot(expirySlot iotago.SlotIndex) options.Option[builder.AccountOutputBuilder]

func WithCreationSlot

func WithCreationSlot(creationSlot iotago.SlotIndex) options.Option[builder.TransactionBuilder]

func WithDelegatedAmount

func WithDelegatedAmount(delegatedAmount iotago.BaseToken) options.Option[builder.DelegationOutputBuilder]

func WithDelegatedValidatorAddress

func WithDelegatedValidatorAddress(validatorAddress *iotago.AccountAddress) options.Option[builder.DelegationOutputBuilder]

func WithDelegationStartEpoch

func WithDelegationStartEpoch(startEpoch iotago.EpochIndex) options.Option[builder.DelegationOutputBuilder]

func WithHighestSupportedVersion

func WithHighestSupportedVersion(highestSupportedVersion iotago.Version) func(builder *ValidationBlockParams)

func WithIncompleteBlockAccepted

func WithIncompleteBlockAccepted(accepted bool) options.Option[BlockIssuer]

func WithIssuer

func WithIssuer(issuer wallet.Account) func(builder *BlockHeaderParams)

func WithIssuingTime

func WithIssuingTime(issuingTime time.Time) func(builder *BlockHeaderParams)

func WithLatestFinalizedSlot

func WithLatestFinalizedSlot(commitmentIndex iotago.SlotIndex) func(builder *BlockHeaderParams)

func WithParentsCount

func WithParentsCount(parentsCount int) func(builder *BlockHeaderParams)

func WithPayload

func WithPayload(payload iotago.Payload) func(builder *BasicBlockParams)

func WithProtocolParametersHash

func WithProtocolParametersHash(protocolParametersHash iotago.Identifier) func(builder *ValidationBlockParams)

func WithProtocolVersion

func WithProtocolVersion(version iotago.Version) func(builder *BlockHeaderParams)

func WithRateSetterEnabled

func WithRateSetterEnabled(enabled bool) options.Option[BlockIssuer]

func WithShallowLikeParents

func WithShallowLikeParents(blockIDs ...iotago.BlockID) func(builder *BlockHeaderParams)

func WithSkipReferenceValidation

func WithSkipReferenceValidation(skipReferenceValidation bool) func(builder *BlockHeaderParams)

func WithSlotCommitment

func WithSlotCommitment(commitment *iotago.Commitment) func(builder *BlockHeaderParams)

func WithStakingFeature

func WithStakingFeature(amount iotago.BaseToken, fixedCost iotago.Mana, startEpoch iotago.EpochIndex, optEndEpoch ...iotago.EpochIndex) options.Option[builder.AccountOutputBuilder]

func WithStrongParents

func WithStrongParents(blockIDs ...iotago.BlockID) func(builder *BlockHeaderParams)

func WithTaggedDataPayload

func WithTaggedDataPayload(payload *iotago.TaggedData) options.Option[builder.TransactionBuilder]

func WithTipSelectionRetryInterval

func WithTipSelectionRetryInterval(interval time.Duration) options.Option[BlockIssuer]

func WithTipSelectionTimeout

func WithTipSelectionTimeout(timeout time.Duration) options.Option[BlockIssuer]

func WithValidationBlockHeaderOptions

func WithValidationBlockHeaderOptions(opts ...options.Option[BlockHeaderParams]) func(builder *ValidationBlockParams)

func WithWeakParents

func WithWeakParents(blockIDs ...iotago.BlockID) func(builder *BlockHeaderParams)

func WithoutBlockIssuerFeature

func WithoutBlockIssuerFeature() options.Option[builder.AccountOutputBuilder]

func WithoutStakingFeature

func WithoutStakingFeature() options.Option[builder.AccountOutputBuilder]

Types

type BasicBlockParams

type BasicBlockParams struct {
	BlockHeader *BlockHeaderParams
	Payload     iotago.Payload
}

type BlockHeaderParams

type BlockHeaderParams struct {
	ParentsCount            int
	References              model.ParentReferences
	SlotCommitment          *iotago.Commitment
	LatestFinalizedSlot     *iotago.SlotIndex
	IssuingTime             *time.Time
	ProtocolVersion         *iotago.Version
	Issuer                  wallet.Account
	SkipReferenceValidation bool
}

type BlockIssuer

type BlockIssuer struct {
	Testing *testing.T

	Name      string
	Validator bool

	AccountID iotago.AccountID
	OutputID  iotago.OutputID
	PublicKey ed25519.PublicKey
	// contains filtered or unexported fields
}

BlockIssuer contains logic to create and issue blocks signed by the given account.

func NewBlockIssuer

func NewBlockIssuer(t *testing.T, name string, keyManager *wallet.KeyManager, accountID iotago.AccountID, validator bool, opts ...options.Option[BlockIssuer]) *BlockIssuer

func (*BlockIssuer) AttachBlock

func (i *BlockIssuer) AttachBlock(ctx context.Context, iotaBlock *iotago.Block, node *Node, optIssuerAccount ...wallet.Account) (iotago.BlockID, error)

func (*BlockIssuer) BlockIssuerKey

func (i *BlockIssuer) BlockIssuerKey() iotago.BlockIssuerKey

func (*BlockIssuer) BlockIssuerKeys

func (i *BlockIssuer) BlockIssuerKeys() iotago.BlockIssuerKeys

func (*BlockIssuer) CopyIdentityFromBlockIssuer

func (i *BlockIssuer) CopyIdentityFromBlockIssuer(otherBlockIssuer *BlockIssuer)

func (*BlockIssuer) CreateBasicBlock

func (i *BlockIssuer) CreateBasicBlock(ctx context.Context, alias string, node *Node, opts ...options.Option[BasicBlockParams]) (*blocks.Block, error)

CreateBlock creates a new block with the options.

func (*BlockIssuer) CreateValidationBlock

func (i *BlockIssuer) CreateValidationBlock(ctx context.Context, alias string, issuerAccount wallet.Account, node *Node, opts ...options.Option[ValidationBlockParams]) (*blocks.Block, error)

func (*BlockIssuer) IssueActivity

func (i *BlockIssuer) IssueActivity(ctx context.Context, wg *sync.WaitGroup, startSlot iotago.SlotIndex, node *Node)

func (*BlockIssuer) IssueBasicBlock

func (i *BlockIssuer) IssueBasicBlock(ctx context.Context, alias string, node *Node, opts ...options.Option[BasicBlockParams]) *blocks.Block

func (*BlockIssuer) IssueBlock

func (i *BlockIssuer) IssueBlock(block *model.Block, node *Node) error

func (*BlockIssuer) IssueBlockAndAwaitEvent

func (i *BlockIssuer) IssueBlockAndAwaitEvent(ctx context.Context, block *model.Block, node *Node, evt *event.Event1[*blocks.Block]) error

IssueBlockAndAwaitEvent submits a block to be processed and waits for the event to be triggered.

func (*BlockIssuer) IssueValidationBlock

func (i *BlockIssuer) IssueValidationBlock(ctx context.Context, alias string, node *Node, opts ...options.Option[ValidationBlockParams]) *blocks.Block

func (*BlockIssuer) Shutdown

func (i *BlockIssuer) Shutdown()

Shutdown shuts down the block issuer.

type Endpoint

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

func (*Endpoint) LocalPeerID

func (e *Endpoint) LocalPeerID() peer.ID

func (*Endpoint) RegisterProtocol

func (e *Endpoint) RegisterProtocol(_ func() proto.Message, handler func(peer.ID, proto.Message) error)

func (*Endpoint) Send

func (e *Endpoint) Send(packet proto.Message, to ...peer.ID)

func (*Endpoint) Shutdown

func (e *Endpoint) Shutdown()

func (*Endpoint) UnregisterProtocol

func (e *Endpoint) UnregisterProtocol()

type Events

type Events struct {
	// Fired when a block is built.
	BlockConstructed *event.Event1[*model.Block]

	// Triggered when a block is issued, i.e. sent to the protocol to be processed.
	BlockIssued *event.Event1[*model.Block]

	// Fired when an error occurred.
	Error *event.Event1[error]

	event.Group[Events, *Events]
}

Events represents events happening on a block factory.

type InvalidSignedTransactionEvent

type InvalidSignedTransactionEvent struct {
	Metadata mempool.SignedTransactionMetadata
	Error    error
}

type Network

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

func NewNetwork

func NewNetwork() *Network

func (*Network) JoinWithEndpoint

func (n *Network) JoinWithEndpoint(endpoint *Endpoint, newPartition string) *Endpoint

func (*Network) JoinWithEndpointID

func (n *Network) JoinWithEndpointID(endpointID peer.ID, partition string) *Endpoint

func (*Network) MergePartitionsToMain

func (n *Network) MergePartitionsToMain(partitions ...string)

type Node

type Node struct {
	Testing *testing.T

	Name       string
	Validator  *BlockIssuer
	KeyManager *wallet.KeyManager

	PeerID peer.ID

	Partition string
	Endpoint  *Endpoint
	Workers   *workerpool.Group

	Protocol *protocol.Protocol
	// contains filtered or unexported fields
}

func NewNode

func NewNode(t *testing.T, parentLogger log.Logger, net *Network, partition string, name string, validator bool) *Node

func (*Node) AttachedBlocks

func (n *Node) AttachedBlocks() []*blocks.Block

func (*Node) CandidateEngineActivatedCount

func (n *Node) CandidateEngineActivatedCount() int

func (*Node) FilteredBlocks

func (n *Node) FilteredBlocks() []*postsolidfilter.BlockFilteredEvent

func (*Node) ForkDetectedCount

func (n *Node) ForkDetectedCount() int

func (*Node) HighestSupportedVersion

func (n *Node) HighestSupportedVersion() iotago.Version

func (*Node) Initialize

func (n *Node) Initialize(failOnBlockFiltered bool, opts ...options.Option[protocol.Protocol])

func (*Node) IsValidator

func (n *Node) IsValidator() bool

func (*Node) IssueValidationBlock

func (n *Node) IssueValidationBlock(ctx context.Context, alias string, opts ...options.Option[ValidationBlockParams]) *blocks.Block

func (*Node) MainEngineSwitchedCount

func (n *Node) MainEngineSwitchedCount() int

func (*Node) ProtocolParametersHash

func (n *Node) ProtocolParametersHash() iotago.Identifier

func (*Node) SetCurrentSlot

func (n *Node) SetCurrentSlot(slot iotago.SlotIndex)

func (*Node) SetHighestSupportedVersion

func (n *Node) SetHighestSupportedVersion(version iotago.Version)

func (*Node) SetProtocolParametersHash

func (n *Node) SetProtocolParametersHash(hash iotago.Identifier)

func (*Node) Shutdown

func (n *Node) Shutdown()

func (*Node) TransactionFailure

func (n *Node) TransactionFailure(txID iotago.SignedTransactionID) (InvalidSignedTransactionEvent, bool)

func (*Node) Wait

func (n *Node) Wait()

type ValidationBlockParams

type ValidationBlockParams struct {
	BlockHeader             *BlockHeaderParams
	HighestSupportedVersion *iotago.Version
	ProtocolParametersHash  *iotago.Identifier
}

type Wallet

type Wallet struct {
	Testing *testing.T

	Name string

	Node *Node

	BlockIssuer *BlockIssuer
	// contains filtered or unexported fields
}

Wallet is an object representing a wallet (similar to a FireFly wallet) capable of the following: - hierarchical deterministic key management - signing transactions - signing blocks - keeping track of unspent outputs.

func NewWallet

func NewWallet(t *testing.T, name string, node *Node, keyManager ...*wallet.KeyManager) *Wallet

func (*Wallet) AccountOutput

func (w *Wallet) AccountOutput(outputName string) *utxoledger.Output

func (*Wallet) AddOutput

func (w *Wallet) AddOutput(outputName string, output *utxoledger.Output)

func (*Wallet) Address

func (w *Wallet) Address() iotago.DirectUnlockableAddress

func (*Wallet) AddressSigner

func (w *Wallet) AddressSigner() iotago.AddressSigner

func (*Wallet) AllotManaFromInputs

func (w *Wallet) AllotManaFromInputs(transactionName string, allotments iotago.Allotments, inputNames ...string) *iotago.SignedTransaction

func (*Wallet) AllotManaToWallet

func (w *Wallet) AllotManaToWallet(transactionName string, inputName string, recipientWallet *Wallet) *iotago.SignedTransaction

func (*Wallet) Balance

func (w *Wallet) Balance() iotago.BaseToken

func (*Wallet) BlockIssuerKey

func (w *Wallet) BlockIssuerKey() iotago.BlockIssuerKey

func (*Wallet) ClaimDelegatorRewards

func (w *Wallet) ClaimDelegatorRewards(transactionName string, inputName string) *iotago.SignedTransaction

func (*Wallet) ClaimValidatorRewards

func (w *Wallet) ClaimValidatorRewards(transactionName string, inputName string) *iotago.SignedTransaction

func (*Wallet) CreateAccountFromInput

func (w *Wallet) CreateAccountFromInput(transactionName string, inputName string, recipientWallet *Wallet, opts ...options.Option[builder.AccountOutputBuilder]) *iotago.SignedTransaction

func (*Wallet) CreateBasicOutputsEquallyFromInput

func (w *Wallet) CreateBasicOutputsEquallyFromInput(transactionName string, outputCount int, inputName string) *iotago.SignedTransaction

func (*Wallet) CreateDelegationFromInput

func (w *Wallet) CreateDelegationFromInput(transactionName string, inputName string, opts ...options.Option[builder.DelegationOutputBuilder]) *iotago.SignedTransaction

CreateDelegationFromInput creates a new DelegationOutput with given options from an input. If the remainder Output is not created, then StoredMana from the input is not passed and can potentially be burned. In order not to burn it, it needs to be assigned manually in another output in the transaction.

func (*Wallet) CreateImplicitAccountFromInput

func (w *Wallet) CreateImplicitAccountFromInput(transactionName string, inputName string, recipientWallet *Wallet) *iotago.SignedTransaction

CreateImplicitAccountFromInput creates an implicit account output.

func (*Wallet) CreateNFTFromInput

func (w *Wallet) CreateNFTFromInput(transactionName string, inputName string, opts ...options.Option[builder.NFTOutputBuilder]) *iotago.SignedTransaction

func (*Wallet) DelayedClaimingTransition

func (w *Wallet) DelayedClaimingTransition(transactionName string, inputName string, delegationEndEpoch iotago.EpochIndex) *iotago.SignedTransaction

DelayedClaimingTransition transitions DelegationOutput into delayed claiming state by setting DelegationID and EndEpoch.

func (*Wallet) DelegationEndFromSlot

func (w *Wallet) DelegationEndFromSlot(slot iotago.SlotIndex) iotago.EpochIndex

func (*Wallet) DelegationStartFromSlot

func (w *Wallet) DelegationStartFromSlot(slot iotago.SlotIndex) iotago.EpochIndex

func (*Wallet) DestroyAccount

func (w *Wallet) DestroyAccount(transactionName string, inputName string) *iotago.SignedTransaction

func (*Wallet) HasAddress

func (w *Wallet) HasAddress(address iotago.Address) bool

func (*Wallet) ImplicitAccountCreationAddress

func (w *Wallet) ImplicitAccountCreationAddress() *iotago.ImplicitAccountCreationAddress

func (*Wallet) IssueBasicBlock

func (w *Wallet) IssueBasicBlock(ctx context.Context, blockName string, opts ...options.Option[BasicBlockParams]) *blocks.Block

func (*Wallet) KeyPair

func (w *Wallet) KeyPair() (ed25519.PrivateKey, ed25519.PublicKey)

func (*Wallet) Output

func (w *Wallet) Output(outputName string) *utxoledger.Output

func (*Wallet) PotentialMana

func (w *Wallet) PotentialMana(api iotago.API, input *utxoledger.Output) iotago.Mana

Computes the Potential Mana that the output generates until the current slot.

func (*Wallet) RemoveFeatureFromAccount

func (w *Wallet) RemoveFeatureFromAccount(featureType iotago.FeatureType, transactionName string, inputName string) *iotago.SignedTransaction

func (*Wallet) SendFundsFromAccount

func (w *Wallet) SendFundsFromAccount(transactionName string, accountOutputName string, commitmentID iotago.CommitmentID, inputNames ...string) *iotago.SignedTransaction

func (*Wallet) SendFundsToAccount

func (w *Wallet) SendFundsToAccount(transactionName string, accountID iotago.AccountID, inputNames ...string) *iotago.SignedTransaction

func (*Wallet) SetBlockIssuer

func (w *Wallet) SetBlockIssuer(accountID iotago.AccountID)

func (*Wallet) SetCurrentSlot

func (w *Wallet) SetCurrentSlot(slot iotago.SlotIndex)

func (*Wallet) SetDefaultNode

func (w *Wallet) SetDefaultNode(node *Node)

func (*Wallet) StoredMana

func (w *Wallet) StoredMana(api iotago.API, input *utxoledger.Output) iotago.Mana

Computes the decay on stored mana that the output holds until the current slot.

func (*Wallet) Transaction

func (w *Wallet) Transaction(alias string) *iotago.Transaction

func (*Wallet) TransactionID

func (w *Wallet) TransactionID(alias string) iotago.TransactionID

func (*Wallet) Transactions

func (w *Wallet) Transactions(transactionNames ...string) []*iotago.Transaction

func (*Wallet) TransitionAccount

func (w *Wallet) TransitionAccount(transactionName string, inputName string, opts ...options.Option[builder.AccountOutputBuilder]) *iotago.SignedTransaction

func (*Wallet) TransitionImplicitAccountToAccountOutput

func (w *Wallet) TransitionImplicitAccountToAccountOutput(transactionName string, inputName string, opts ...options.Option[builder.AccountOutputBuilder]) *iotago.SignedTransaction

func (*Wallet) TransitionNFTWithTransactionOpts

func (w *Wallet) TransitionNFTWithTransactionOpts(transactionName string, inputName string, opts ...options.Option[builder.TransactionBuilder]) *iotago.SignedTransaction

Jump to

Keyboard shortcuts

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