denalijsonmodel

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 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 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 added in v0.0.3

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

JSONBytesFromStringValues extracts values from a slice of JSONBytesFromString into a list

func JSONBytesFromTreeValues added in v0.0.3

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
	Comment       string
	Nonce         JSONUint64
	Balance       JSONBigInt
	Storage       []*StorageKeyValuePair
	Code          JSONBytesFromString
	AsyncCallData string
}

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
}

BlockInfo contains data for the block info hooks

type CheckAccount

type CheckAccount struct {
	Address       JSONBytesFromString
	Comment       string
	Nonce         JSONCheckUint64
	Balance       JSONCheckBigInt
	IgnoreStorage bool
	CheckStorage  []*StorageKeyValuePair
	Code          JSONCheckBytes
	AsyncCallData JSONCheckBytes
}

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 {
	OtherAccountsAllowed bool
	Accounts             []*CheckAccount
}

CheckAccounts encodes rules to check mock accounts.

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 DumpStateStep added in v0.0.3

type DumpStateStep struct {
	Comment string
}

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

func (*DumpStateStep) StepTypeName added in v0.0.3

func (*DumpStateStep) StepTypeName() string

StepTypeName type as string

type ExternalStepsStep

type ExternalStepsStep struct {
	Path string
}

ExternalStepsStep allows including steps from another file

func (*ExternalStepsStep) StepTypeName

func (*ExternalStepsStep) StepTypeName() string

StepTypeName type as string

type JSONBigInt

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

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

type JSONBytesFromString added in v0.0.3

type JSONBytesFromString struct {
	Value    []byte
	Original string
}

JSONBytesFromString stores a byte slice

func NewJSONBytesFromString added in v0.0.3

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

NewJSONBytesFromString creates a new JSONBytesFromString instance.

type JSONBytesFromTree added in v0.0.3

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 added in v0.0.3

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
}

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

func JSONCheckBigIntDefault added in v0.0.3

func JSONCheckBigIntDefault() JSONCheckBigInt

JSONCheckBigIntDefault 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) IsDefault added in v0.0.3

func (jcbi JSONCheckBigInt) IsDefault() bool

IsDefault yields true if the field was originally unspecified.

type JSONCheckBytes

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

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

func JSONCheckBytesDefault added in v0.0.3

func JSONCheckBytesDefault() JSONCheckBytes

JSONCheckBytesDefault yields JSONCheckBytes default "*" value.

func JSONCheckBytesExplicitStar added in v0.0.3

func JSONCheckBytesExplicitStar() JSONCheckBytes

JSONCheckBytesExplicitStar yields JSONCheckBytes explicit "*" value.

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) IsDefault added in v0.0.3

func (jcbytes JSONCheckBytes) IsDefault() bool

IsDefault yields true if the field was originally unspecified.

func (JSONCheckBytes) OriginalEmpty added in v0.0.3

func (jcbytes JSONCheckBytes) OriginalEmpty() bool

OriginalEmpty returns true if original = "".

type JSONCheckUint64

type JSONCheckUint64 struct {
	Value    uint64
	IsStar   bool
	Original string
}

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

func JSONCheckUint64Default added in v0.0.3

func JSONCheckUint64Default() JSONCheckUint64

JSONCheckUint64Default 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) IsDefault added in v0.0.3

func (jcu JSONCheckUint64) IsDefault() bool

IsDefault 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

type LogEntry

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

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
	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
	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
	IgnoreLogs 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

	// 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 "DHARITRI_Reward" in storage.
	ValidatorReward
)

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) 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