migration

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: GPL-3.0 Imports: 26 Imported by: 0

Documentation

Overview

Package migration provides framework to test migration of the NeoFS smart contracts.

Smart contracts store sensitive system data of the NeoFS network. The contracts are updated on the fly, so data migration must be performed accurately, without backward compatibility loss. The package provides services of Neo blockchain and particular contract needed for testing. Test blockchain environment can be based on "real" data from the remote NeoFS blockchain instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SkipUnsupportedVersions

func SkipUnsupportedVersions(tb testing.TB, c *Contract, updPrms ...interface{})

SkipUnsupportedVersions calls get current version of the Contract using 'version' method and checks can the Contract be updated similar to common.CheckVersion. If not, SkipUnsupportedVersions skips corresponding test.

Types

type Contract

type Contract struct {
	*neotest.ContractInvoker
	// contains filtered or unexported fields
}

Contract provides part of Neo blockchain services primarily related to the NeoFS contract being tested. Initial state of the tested contract is initialized from the dump of the blockchain in which it has already been deployed (mostly with real data from public networks, but custom options are also possible). The contract itself is identified by its name registered in the NeoFS NNS. After preparing the test shell of the blockchain from the input data, the contract can be updated using the appropriate methods. Contract also provides data access interfaces that can be used to ensure that data is migrated correctly.

Contract instances must be constructed using NewContract.

func NewContract

func NewContract(tb testing.TB, d *dump.Reader, name string, opts ContractOptions) *Contract

NewContract constructs Contract from provided dump.Reader for the named NeoFS contract.

The Contract is initialized with all contracts (states and data) from the dump.Reader. If you need to process storage items of the tested contract before the chain is initialized, use ContractOptions.StorageDumpHandler. If set, NewContract passes each key-value item into the function.

By default, new version of the contract executable is compiled from '../name' directory. The path can be overridden by ContractOptions.SourceCodeDir.

To work with NNS, NewContract compiles NeoFS NNS contract from the source located in '../nns' directory and deploys it.

func (*Contract) Call

func (x *Contract) Call(tb testing.TB, method string, args ...interface{}) stackitem.Item

Call tests that calling the contract method with optional arguments succeeds and result contains single value. The resulting value is returned as stackitem.Item.

Note that Call doesn't change the chain state, so only read (aka safe) methods should be used.

func (*Contract) CheckUpdateFail

func (x *Contract) CheckUpdateFail(tb testing.TB, faultException string, args ...interface{})

CheckUpdateFail tests that contract update with given arguments fails with exact fault exception.

See also CheckUpdateSuccess.

func (*Contract) CheckUpdateSuccess

func (x *Contract) CheckUpdateSuccess(tb testing.TB, args ...interface{})

CheckUpdateSuccess tests that contract update with given arguments succeeds. Contract executable (NEF and manifest) is compiled from source code (see NewContract for details).

func (*Contract) GetStorageItem

func (x *Contract) GetStorageItem(key []byte) []byte

GetStorageItem returns value stored in the tested contract by key.

func (*Contract) InnerRing

func (x *Contract) InnerRing(tb testing.TB) keys.PublicKeys

InnerRing reads Inner Ring composition using RoleManagement contract. The list can be set via SetInnerRing.

func (*Contract) RegisterContractInNNS

func (x *Contract) RegisterContractInNNS(tb testing.TB, name string, addr util.Uint160)

RegisterContractInNNS binds given address to the contract referenced by provided name via additional record for the 'name.neofs' domain in the NeoFS NNS contract. The method is useful when tested contract uses NNS to access other contracts.

Record format can be either Neo address or little-endian HEX string. The exact format is selected randomly.

See also nns.Register, nns.AddRecord.

func (*Contract) SetInnerRing

func (x *Contract) SetInnerRing(tb testing.TB, _keys keys.PublicKeys)

SetInnerRing sets Inner Ring composition using RoleManagement contract. The list can be read via InnerRing.

type ContractOptions

type ContractOptions struct {
	// Path to the directory containing source code of the tested NeoFS contract.
	// Defaults to '../name'.
	SourceCodeDir string

	// Listener of storage dump of the tested contract. Useful for working with raw
	// values that can not be accessed by the contract API.
	StorageDumpHandler func(key, value []byte)
}

ContractOptions groups various options of NewContract.

Jump to

Keyboard shortcuts

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