utils

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: LGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MODE = os.Getenv("MODE")

	HOSTNAME = os.Getenv("HOSTNAME")
	PORT     = os.Getenv("PORT")

	LOGLEVEL = os.Getenv("LOG")

	NETWORK_SIZE = os.Getenv("NETWORK_SIZE")

	ContentTypeJSON = "application/json"
)

nolint

View Source
var (
	// KeyList is the list of built-in keys
	KeyList = []string{"alice", "bob", "charlie", "dave", "eve", "ferdie", "george", "heather", "ian"}

	// BaseRPCPort is the starting RPC port for test nodes
	BaseRPCPort = 8540

	// BaseWSPort is the starting Websocket port for test nodes
	BaseWSPort = 8546

	// GenesisOneAuth is the genesis file that has 1 authority
	GenesisOneAuth string = filepath.Join(currentDir, "../utils/genesis_oneauth.json")
	// GenesisThreeAuths is the genesis file that has 3 authorities
	GenesisThreeAuths string = filepath.Join(currentDir, "../utils/genesis_threeauths.json")
	// GenesisSixAuths is the genesis file that has 6 authorities
	GenesisSixAuths string = filepath.Join(currentDir, "../utils/genesis_sixauths.json")
	// GenesisDefault is the default gssmr genesis file
	GenesisDefault string = filepath.Join(currentDir, "../..", "chain/gssmr/genesis.json")

	// ConfigDefault is the default config file
	ConfigDefault string = filepath.Join(currentDir, "../utils/config_default.toml")
	// ConfigLogGrandpa is a config file where log levels are set to CRIT except for GRANDPA
	ConfigLogGrandpa string = filepath.Join(currentDir, "../utils/config_log_grandpa.toml")
	// ConfigNoBABE is a config file with BABE disabled
	ConfigNoBABE string = filepath.Join(currentDir, "../utils/config_nobabe.toml")
	// ConfigBABEMaxThreshold is a config file with BABE threshold set to maximum (node can produce block every slot)
	ConfigBABEMaxThreshold string = filepath.Join(currentDir, "../utils/config_babe_max_threshold.toml")
)
View Source
var (
	// CHAIN METHODS
	ChainGetBlock                = "chain_getBlock"
	ChainGetHeader               = "chain_getHeader"
	ChainGetFinalizedHead        = "chain_getFinalizedHead"
	ChainGetFinalizedHeadByRound = "chain_getFinalizedHeadByRound"
	ChainGetBlockHash            = "chain_getBlockHash"

	// AUTHOR METHODS
	AuthorSubmitExtrinsic   = "author_submitExtrinsic"
	AuthorPendingExtrinsics = "author_pendingExtrinsics"

	// STATE METHODS
	StateGetStorage = "state_getStorage"

	// DEV METHODS
	DevControl = "dev_control"

	// GRANDPA
	GrandpaProveFinality = "grandpa_proveFinality"
)

nolint

Functions

func CheckNodeStarted

func CheckNodeStarted(t *testing.T, gossamerHost string) error

CheckNodeStarted check if gossamer node is started

func CreateConfigBabeMaxThreshold added in v0.2.0

func CreateConfigBabeMaxThreshold()

CreateConfigBabeMaxThreshold generates and creates babe max threshold config file.

func CreateConfigLogGrandpa added in v0.2.0

func CreateConfigLogGrandpa()

CreateConfigLogGrandpa generates and creates grandpa config file.

func CreateConfigNoBabe added in v0.2.0

func CreateConfigNoBabe()

CreateConfigNoBabe generates and creates no babe config file.

func CreateDefaultConfig added in v0.3.0

func CreateDefaultConfig()

CreateDefaultConfig generates and creates default config file.

func DecodeRPC

func DecodeRPC(t *testing.T, body []byte, target interface{}) error

DecodeRPC will decode []body into target interface

func DecodeRPC_NT added in v0.2.0

func DecodeRPC_NT(body []byte, target interface{}) error

DecodeRPC_NT will decode []body into target interface (NT is Not Test testing required)

func DecodeWebsocket added in v0.2.0

func DecodeWebsocket(t *testing.T, body []byte, target interface{}) error

DecodeWebsocket will decode body into target interface

func EpochLength added in v0.3.0

func EpochLength(t *testing.T, node *Node) uint64

EpochLength Calls dev endpoint for epoch length

func GenerateGenesisOneAuth added in v0.2.0

func GenerateGenesisOneAuth()

GenerateGenesisOneAuth generates Genesis file with one authority.

func GenerateGenesisSixAuth added in v0.2.0

func GenerateGenesisSixAuth()

GenerateGenesisSixAuth generates Genesis file with six authority.

func GenerateGenesisThreeAuth added in v0.2.0

func GenerateGenesisThreeAuth()

GenerateGenesisThreeAuth generates Genesis file with three authority.

func GetBlock added in v0.2.0

func GetBlock(t *testing.T, node *Node, hash common.Hash) *types.Block

GetBlock calls the endpoint chain_getBlock

func GetBlockHash added in v0.2.0

func GetBlockHash(t *testing.T, node *Node, num string) (common.Hash, error)

GetBlockHash calls the endpoint chain_getBlockHash to get the latest chain head

func GetChainHead added in v0.2.0

func GetChainHead(t *testing.T, node *Node) *types.Header

GetChainHead calls the endpoint chain_getHeader to get the latest chain head

func GetChainHeadWithError added in v0.2.0

func GetChainHeadWithError(t *testing.T, node *Node) (*types.Header, error)

GetChainHeadWithError calls the endpoint chain_getHeader to get the latest chain head

func GetFinalizedHead added in v0.2.0

func GetFinalizedHead(t *testing.T, node *Node) common.Hash

GetFinalizedHead calls the endpoint chain_getFinalizedHead to get the latest finalized head

func GetFinalizedHeadByRound added in v0.2.0

func GetFinalizedHeadByRound(t *testing.T, node *Node, round uint64) (common.Hash, error)

GetFinalizedHeadByRound calls the endpoint chain_getFinalizedHeadByRound to get the finalized head at a given round TODO: add setID, hard-coded at 1 for now

func GetHeader added in v0.2.0

func GetHeader(t *testing.T, node *Node, hash common.Hash) *types.Header

GetHeader calls the endpoint chain_getHeader

func GetPeers added in v0.2.0

func GetPeers(t *testing.T, node *Node) []common.PeerInfo

GetPeers calls the endpoint system_peers

func GetStorage added in v0.2.0

func GetStorage(t *testing.T, node *Node, key []byte) []byte

GetStorage calls the endpoint state_getStorage

func HeaderResponseToHeader added in v0.2.0

func HeaderResponseToHeader(t *testing.T, header *modules.ChainBlockHeaderResponse) *types.Header

HeaderResponseToHeader converts a *ChainBlockHeaderResponse to a *types.Header

func KillProcess

func KillProcess(t *testing.T, cmd *exec.Cmd) error

KillProcess kills a instance of gossamer

func NewEndpoint added in v0.2.0

func NewEndpoint(port string) string

NewEndpoint will create a new endpoint string based on utils.HOSTNAME and port

func PauseBABE added in v0.2.0

func PauseBABE(t *testing.T, node *Node) error

PauseBABE calls the endpoint dev_control with the params ["babe", "stop"]

func PostRPC

func PostRPC(method, host, params string) ([]byte, error)

PostRPC utils for sending payload to endpoint and getting []byte back

func PostRPCWithRetry added in v0.2.0

func PostRPCWithRetry(method, host, params string, retry int) ([]byte, error)

PostRPCWithRetry is a wrapper around `PostRPC` that calls it `retry` number of times.

func SetLogLevel added in v0.2.0

func SetLogLevel(lvl log.Lvl)

SetLogLevel sets the logging level for this package

func SlotDuration added in v0.3.0

func SlotDuration(t *testing.T, node *Node) time.Duration

SlotDuration Calls dev endpoint for slot duration

func StartGossamer added in v0.2.0

func StartGossamer(t *testing.T, node *Node, websocket bool) error

StartGossamer starts given node

func StartNodes

func StartNodes(t *testing.T, nodes []*Node) error

StartNodes starts given array of nodes

func StopNodes added in v0.2.0

func StopNodes(t *testing.T, nodes []*Node) (errs []error)

StopNodes stops the given nodes

func TearDown

func TearDown(t *testing.T, nodes []*Node) (errorList []error)

TearDown stops the given nodes and remove their datadir

func TestDir added in v0.2.0

func TestDir(t *testing.T, name string) string

TestDir returns the test directory path <current-directory>/test_data/<test-name>/<name>

Types

type ErrCode

type ErrCode int

ErrCode is a int type used for the rpc error codes

type Error

type Error struct {
	Message   string                 `json:"message"`
	ErrorCode ErrCode                `json:"code"`
	Data      map[string]interface{} `json:"data"`
}

Error is a struct that holds the error message and the error code for a error

func (*Error) Error

func (e *Error) Error() string

Error returns the error Message string

type Framework added in v0.2.0

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

Framework struct to hold references to framework data

func InitFramework added in v0.2.0

func InitFramework(qtyNodes int) (*Framework, error)

InitFramework creates given quanity of nodes

func (*Framework) CallRPC added in v0.2.0

func (fw *Framework) CallRPC(idx int, method, params string) (respJSON interface{}, err error)

CallRPC call RPC method with given params for node at idx

func (*Framework) CheckEqual added in v0.2.0

func (fw *Framework) CheckEqual(c1, c2 int, field string) bool

CheckEqual returns true if the field values are equal

func (*Framework) GetRecord added in v0.2.0

func (fw *Framework) GetRecord(callIdx int) interface{}

GetRecord return value of record for node and call index

func (*Framework) KillNodes added in v0.2.0

func (fw *Framework) KillNodes(t *testing.T) []error

KillNodes stops all running nodes

func (*Framework) PrintDB added in v0.2.0

func (fw *Framework) PrintDB()

PrintDB prints all records for given node

func (*Framework) StartNodes added in v0.2.0

func (fw *Framework) StartNodes(t *testing.T) (errorList []error)

StartNodes calls RestartGossamor for all nodes

type Node

type Node struct {
	Process *exec.Cmd
	Key     string
	RPCPort string
	Idx     int

	WSPort string
	// contains filtered or unexported fields
}

Node represents a gossamer process

func InitGossamer added in v0.2.0

func InitGossamer(idx int, basePath, genesis, config string) (*Node, error)

InitGossamer initializes given node number and returns node reference

func InitNodes added in v0.2.0

func InitNodes(num int, config string) ([]*Node, error)

InitNodes initializes given number of nodes

func InitializeAndStartNodes added in v0.2.0

func InitializeAndStartNodes(t *testing.T, num int, genesis, config string) ([]*Node, error)

InitializeAndStartNodes will spin up `num` gossamer nodes

func InitializeAndStartNodesWebsocket added in v0.2.0

func InitializeAndStartNodesWebsocket(t *testing.T, num int, genesis, config string) ([]*Node, error)

InitializeAndStartNodesWebsocket will spin up `num` gossamer nodes running with Websocket rpc enabled

func RunGossamer

func RunGossamer(t *testing.T, idx int, basepath, genesis, config string, websocket bool) (*Node, error)

RunGossamer will initialize and start a gossamer instance

type ServerResponse

type ServerResponse struct {
	// JSON-RPC Version
	Version string `json:"jsonrpc"`
	// Resulting values
	Result json.RawMessage `json:"result"`
	// Any generated errors
	Error *Error `json:"error"`
	// Request id
	ID *json.RawMessage `json:"id"`
}

ServerResponse wraps the RPC response

type WebsocketResponse added in v0.2.0

type WebsocketResponse struct {
	// JSON-RPC Version
	Version string `json:"jsonrpc"`
	// Method name called
	Method string `json:"method"`
	// Resulting values
	Result json.RawMessage `json:"result"`
	// Params values including results
	Params json.RawMessage `json:"params"`
	// Any generated errors
	Error *Error `json:"error"`
	// Request id
	Subscription *json.RawMessage `json:"subscription"`
	// Request id
	ID *json.RawMessage `json:"id"`
}

WebsocketResponse wraps the Websocket response

Jump to

Keyboard shortcuts

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