scenjsonmodel

package
v0.0.0-...-b66b357 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const StepNameCheckState = "checkState"

StepNameCheckState is a json step type name.

View Source
const StepNameDumpState = "dumpState"

StepNameDumpState is a json step type name.

View Source
const StepNameExternalSteps = "externalSteps"

StepNameExternalSteps is a json step type name.

View Source
const StepNameScCall = "scCall"

StepNameScCall is a json step type name.

View Source
const StepNameScDeploy = "scDeploy"

StepNameScDeploy is a json step type name.

View Source
const StepNameScQuery = "scQuery"

StepNameScQuery is a json step type name.

View Source
const StepNameSetState = "setState"

StepNameSetState is a json step type name.

View Source
const StepNameTransfer = "transfer"

StepNameTransfer is a json step type name.

View Source
const StepNameValidatorReward = "validatorReward"

StepNameValidatorReward is a json step type name.

Variables

This section is empty.

Functions

func JSONBytesFromStringValues

func JSONBytesFromStringValues(jbs []JSONBytesFromString) [][]byte

JSONBytesFromStringValues extracts values from a slice of JSONBytesFromString into a list

func JSONBytesFromTreeValues

func JSONBytesFromTreeValues(jbs []JSONBytesFromTree) [][]byte

JSONBytesFromTreeValues extracts values from a slice of JSONBytesFromTree into a list

func ResultAsString

func ResultAsString(result [][]byte) string

ResultAsString helps create nicer error messages.

func ResultEqual

func ResultEqual(expected JSONBytesFromString, actual []byte) bool

ResultEqual returns true if result bytes encode the same number.

Types

type Account

type Account struct {
	Address         JSONBytesFromString
	Shard           JSONUint64
	IsSmartContract bool
	Comment         string
	Nonce           JSONUint64
	Balance         JSONBigInt
	Username        JSONBytesFromString
	Storage         []*StorageKeyValuePair
	Code            JSONBytesFromString
	Owner           JSONBytesFromString
	AsyncCallData   string
	DCTData         []*DCTData
}

Account is a json object representing an account.

func FindAccount

func FindAccount(accounts []*Account, address []byte) *Account

FindAccount searches an account list by address.

type Block

type Block struct {
	Results      []*TransactionResult
	Transactions []*Transaction
	BlockHeader  *BlockHeader
}

Block is a json object representing a block.

type BlockHeader

type BlockHeader struct {
	Beneficiary JSONBigInt // "coinbase"
	Difficulty  JSONBigInt
	Number      JSONBigInt
	GasLimit    JSONBigInt
	Timestamp   JSONUint64
}

BlockHeader is a json object representing the block header.

type BlockInfo

type BlockInfo struct {
	BlockTimestamp  JSONUint64
	BlockNonce      JSONUint64
	BlockRound      JSONUint64
	BlockEpoch      JSONUint64
	BlockRandomSeed *JSONBytesFromTree
}

BlockInfo contains data for the block info hooks

type CheckAccount

type CheckAccount struct {
	Address              JSONBytesFromString
	Comment              string
	Nonce                JSONCheckUint64
	Balance              JSONCheckBigInt
	Username             JSONCheckBytes
	CheckStorage         []*CheckStorageKeyValuePair
	IgnoreStorage        bool
	MoreStorageAllowed   bool
	Code                 JSONCheckBytes
	Owner                JSONCheckBytes
	AsyncCallData        JSONCheckBytes
	CheckDCTData         []*CheckDCTData
	IgnoreDCT            bool
	MoreDCTTokensAllowed bool
}

CheckAccount is a json object representing checks for an account.

func FindCheckAccount

func FindCheckAccount(accounts []*CheckAccount, address []byte) *CheckAccount

FindCheckAccount searches a check account list by address.

type CheckAccounts

type CheckAccounts struct {
	Accounts            []*CheckAccount
	MoreAccountsAllowed bool
}

CheckAccounts encodes rules to check mock accounts.

type CheckDCTData

type CheckDCTData struct {
	TokenIdentifier JSONBytesFromString
	Instances       []*CheckDCTInstance
	LastNonce       JSONCheckUint64
	Roles           []string
	Frozen          JSONCheckUint64
}

CheckDCTData checks the DCT tokens held by an account

type CheckDCTInstance

type CheckDCTInstance struct {
	Nonce      JSONCheckUint64
	Balance    JSONCheckBigInt
	Creator    JSONCheckBytes
	Royalties  JSONCheckUint64
	Hash       JSONCheckBytes
	Uri        JSONCheckBytes
	Attributes JSONCheckBytes
}

CheckDCTInstance checks an instance of an NFT/SFT, with its own nonce

func NewCheckDCTInstance

func NewCheckDCTInstance() *CheckDCTInstance

NewCheckDCTInstance creates an instance with all fields unspecified.

type CheckStateStep

type CheckStateStep struct {
	Comment       string
	CheckAccounts *CheckAccounts
}

CheckStateStep is a step where the state of the blockchain mock is verified.

func (*CheckStateStep) StepTypeName

func (*CheckStateStep) StepTypeName() string

StepTypeName type as string

type CheckStorageKeyValuePair

type CheckStorageKeyValuePair struct {
	Key        JSONBytesFromString
	CheckValue JSONCheckBytes
}

CheckStorageKeyValuePair checks a single entry in storage.

type DCTData

type DCTData struct {
	TokenIdentifier JSONBytesFromString
	Instances       []*DCTInstance
	LastNonce       JSONUint64
	Roles           []string
	Frozen          JSONUint64
}

DCTData models an account holding an DCT token

type DCTInstance

type DCTInstance struct {
	Nonce      JSONUint64
	Balance    JSONBigInt
	Creator    JSONBytesFromString
	Royalties  JSONUint64
	Hash       JSONBytesFromString
	Uri        JSONBytesFromTree
	Attributes JSONBytesFromString
}

DCTInstance models an instance of an NFT/SFT, with its own nonce

type DCTTxData

type DCTTxData struct {
	TokenIdentifier JSONBytesFromString
	Nonce           JSONUint64
	Value           JSONBigInt
}

DCTTransfer models the transfer of tokens in a tx

type DumpStateStep

type DumpStateStep struct {
	Comment string
}

DumpStateStep is a step that simply prints the entire state to console. Useful for debugging.

func (*DumpStateStep) StepTypeName

func (*DumpStateStep) StepTypeName() string

StepTypeName type as string

type ExternalStepsStep

type ExternalStepsStep struct {
	Comment string
	Path    string
}

ExternalStepsStep allows including steps from another file

func (*ExternalStepsStep) StepTypeName

func (*ExternalStepsStep) StepTypeName() string

StepTypeName type as string

type GasSchedule

type GasSchedule int

GasSchedule encodes the gas model to be used in scenario tests

const (
	// GasScheduleDefault indicates that the scenario should use whatever the default gas model is.
	// Should be the latest version of the mainnet gas schedule.
	GasScheduleDefault GasSchedule = iota

	// GasScheduleDummy is a dummy model, with all costs set to 1.
	GasScheduleDummy

	// GasScheduleV1 was previously used on mainnet.
	GasScheduleV1

	// GasScheduleV2 was previously used on mainnet.
	GasScheduleV2

	// GasScheduleV3 is currently used on mainnet.
	GasScheduleV3
)

type JSONBigInt

type JSONBigInt struct {
	Value    *big.Int
	Original string
}

JSONBigInt stores the parsed big int value but also the original parsed string

func JSONBigIntZero

func JSONBigIntZero() JSONBigInt

JSONBigIntZero provides an unitialized zero value.

type JSONBytesFromString

type JSONBytesFromString struct {
	Value    []byte
	Original string
}

JSONBytesFromString stores a byte slice

func NewJSONBytesFromString

func NewJSONBytesFromString(value []byte, originalStr string) JSONBytesFromString

NewJSONBytesFromString creates a new JSONBytesFromString instance.

type JSONBytesFromTree

type JSONBytesFromTree struct {
	Value    []byte
	Original oj.OJsonObject
}

JSONBytesFromTree stores a parsed byte slice, either from a string, or from a list of strings. The list of strings representation can be used in storage, arguments or results, and it is designed to make it easier to express serialized objects. The strings in the list get simply concatenated to produce a value.

func (JSONBytesFromTree) OriginalEmpty

func (jb JSONBytesFromTree) OriginalEmpty() bool

OriginalEmpty returns true if the object originates from "".

type JSONCheckBigInt

type JSONCheckBigInt struct {
	Value       *big.Int
	IsStar      bool
	Original    string
	Unspecified bool
}

JSONCheckBigInt holds a big int condition. Values are checked for equality. "*" allows all values.

func JSONCheckBigIntUnspecified

func JSONCheckBigIntUnspecified() JSONCheckBigInt

JSONCheckBigIntUnspecified yields JSONCheckBigInt default "*" value.

func (JSONCheckBigInt) Check

func (jcbi JSONCheckBigInt) Check(other *big.Int) bool

Check returns true if condition expressed in object holds for another value. Explicit values are interpreted as equals assertion.

func (JSONCheckBigInt) IsUnspecified

func (jcbi JSONCheckBigInt) IsUnspecified() bool

IsUnspecified yields true if the field was originally unspecified.

type JSONCheckBytes

type JSONCheckBytes struct {
	Value       []byte
	IsStar      bool
	Original    oj.OJsonObject
	Unspecified bool
}

JSONCheckBytes holds a byte slice condition. Values are checked for equality. "*" allows all values.

func JSONCheckBytesReconstructed

func JSONCheckBytesReconstructed(value []byte, originalString string) JSONCheckBytes

JSONCheckBytesReconstructed creates a JSONCheckBytes without an original JSON source.

func JSONCheckBytesStar

func JSONCheckBytesStar() JSONCheckBytes

JSONCheckBytesStar yields JSONCheckBytes explicit "*" value.

func JSONCheckBytesUnspecified

func JSONCheckBytesUnspecified() JSONCheckBytes

JSONCheckBytesUnspecified yields JSONCheckBytes that check that value is empty.

func (JSONCheckBytes) Check

func (jcbytes JSONCheckBytes) Check(other []byte) bool

Check returns true if condition expressed in object holds for another value. Explicit values are interpreted as equals assertion.

func (JSONCheckBytes) IsUnspecified

func (jcbytes JSONCheckBytes) IsUnspecified() bool

IsUnspecified yields true if the field was originally unspecified.

func (JSONCheckBytes) OriginalEmpty

func (jcbytes JSONCheckBytes) OriginalEmpty() bool

OriginalEmpty returns true if original = "".

type JSONCheckUint64

type JSONCheckUint64 struct {
	Value       uint64
	IsStar      bool
	Original    string
	Unspecified bool
}

JSONCheckUint64 holds a uint64 condition. Values are checked for equality. "*" allows all values.

func JSONCheckUint64Unspecified

func JSONCheckUint64Unspecified() JSONCheckUint64

JSONCheckUint64Unspecified yields JSONCheckBigInt default "*" value.

func (JSONCheckUint64) Check

func (jcu JSONCheckUint64) Check(other uint64) bool

Check returns true if condition expressed in object holds for another value. Explicit values are interpreted as equals assertion.

func (JSONCheckUint64) CheckBool

func (jcu JSONCheckUint64) CheckBool(other bool) bool

CheckBool interprets own value as bool (true = anything > 0, false = 0), We are using JSONCheckUint64 for bool too so we don't create another type.

func (JSONCheckUint64) IsUnspecified

func (jcu JSONCheckUint64) IsUnspecified() bool

IsUnspecified yields true if the field was originally unspecified.

type JSONUint64

type JSONUint64 struct {
	Value    uint64
	Original string
}

JSONUint64 stores the parsed uint64 value but also the original parsed string

func JSONUint64Zero

func JSONUint64Zero() JSONUint64

JSONUint64Zero provides an unitialized zero value.

type LogEntry

type LogEntry struct {
	Address    JSONCheckBytes
	Identifier JSONCheckBytes
	Topics     []JSONCheckBytes
	Data       JSONCheckBytes
}

LogEntry is a json object representing an expected transaction result log entry.

type NewAddressMock

type NewAddressMock struct {
	CreatorAddress JSONBytesFromString
	CreatorNonce   JSONUint64
	NewAddress     JSONBytesFromString
}

NewAddressMock allows tests to specify what new addresses to generate

type Scenario

type Scenario struct {
	Name        string
	Comment     string
	CheckGas    bool
	GasSchedule GasSchedule
	Steps       []Step
}

Scenario is a json object representing a test scenario with steps.

func ConvertTestToScenario

func ConvertTestToScenario(top []*Test) (*Scenario, error)

ConvertTestToScenario converts the old test format to the new scenario format for tests.

type SetStateStep

type SetStateStep struct {
	Comment           string
	Accounts          []*Account
	PreviousBlockInfo *BlockInfo
	CurrentBlockInfo  *BlockInfo
	BlockHashes       []JSONBytesFromString
	NewAddressMocks   []*NewAddressMock
}

SetStateStep is a step where data is saved to the blockchain mock.

func (*SetStateStep) StepTypeName

func (*SetStateStep) StepTypeName() string

StepTypeName type as string

type Step

type Step interface {
	StepTypeName() string
}

Step is the basic block of a scenario.

type StorageKeyValuePair

type StorageKeyValuePair struct {
	Key   JSONBytesFromString
	Value JSONBytesFromTree
}

StorageKeyValuePair is a json key value pair in the storage map.

type Test

type Test struct {
	TestName    string
	CheckGas    bool
	Pre         []*Account
	Blocks      []*Block
	Network     string
	BlockHashes []JSONBytesFromString
	PostState   *CheckAccounts
}

Test is a json object representing a test.

type Transaction

type Transaction struct {
	Type      TransactionType
	Nonce     JSONUint64
	Value     JSONBigInt
	DCTValue  *DCTTxData
	From      JSONBytesFromString
	To        JSONBytesFromString
	Function  string
	Code      JSONBytesFromString
	Arguments []JSONBytesFromTree
	GasPrice  JSONUint64
	GasLimit  JSONUint64
}

Transaction is a json object representing a transaction.

type TransactionResult

type TransactionResult struct {
	Out             []JSONCheckBytes
	Status          JSONCheckBigInt
	Message         JSONCheckBytes
	Gas             JSONCheckUint64
	Refund          JSONCheckBigInt
	LogsStar        bool
	LogsUnspecified bool
	LogHash         string
	Logs            []*LogEntry
}

TransactionResult is a json object representing an expected transaction result.

type TransactionType

type TransactionType int

TransactionType describes the type of simulate transaction

const (
	// ScDeploy describes a transaction that deploys a new contract
	ScDeploy TransactionType = iota

	// ScCall describes a regular smart contract call
	ScCall

	// ScQuery simulates an off-chain call.
	// It is like a SCCall, but without a sender and with infinite gas.
	ScQuery

	// Transfer is an MOA transfer transaction without calling a smart contract
	Transfer

	// ValidatorReward is when the protocol sends a validator reward to the target account.
	// It increases the balance, but also increments the reward value in storage.
	ValidatorReward
)

func (TransactionType) HasDCT

func (tt TransactionType) HasDCT() bool

HasDCT is a helper function to indicate if transaction has `dctValue` or `dctToken` fields.

func (TransactionType) HasFunction

func (tt TransactionType) HasFunction() bool

HasFunction indicates whether tx type allows a `function` field.

func (TransactionType) HasGas

func (tt TransactionType) HasGas() bool

HasGas is a helper function to indicate if transaction has `dctValue` or `dctToken` fields.

func (TransactionType) HasReceiver

func (tt TransactionType) HasReceiver() bool

HasReceiver is a helper function to indicate if transaction has receiver.

func (TransactionType) HasSender

func (tt TransactionType) HasSender() bool

HasSender is a helper function to indicate if transaction has `to` field.

func (TransactionType) HasValue

func (tt TransactionType) HasValue() bool

HasValue indicates whether tx type allows a `value` field.

func (TransactionType) IsSmartContractTx

func (tt TransactionType) IsSmartContractTx() bool

IsSmartContractTx indicates whether tx type allows an `expect` field.

type TxStep

type TxStep struct {
	TxIdent        string
	Comment        string
	Tx             *Transaction
	ExpectedResult *TransactionResult
}

TxStep is a step where a transaction is executed.

func (*TxStep) StepTypeName

func (t *TxStep) StepTypeName() string

StepTypeName type as string

Jump to

Keyboard shortcuts

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