blockutil

package
v0.0.0-...-84d53aa Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ChainID is chain id for test configuration.
	ChainID uint32 = 1

	// DynastySize is dynasty size for test configuration
	DynastySize = 3
)

Functions

func FloatToUint128

func FloatToUint128(t *testing.T, med float64) *util.Uint128

FloatToUint128 covert float to uint128 (precision is only 1e-03)

func NewTestGenesisBlock

func NewTestGenesisBlock(t *testing.T, dynastySize int) (genesis *core.Block, dynasties keyutil.AddrKeyPairs, distributed keyutil.AddrKeyPairs)

NewTestGenesisBlock returns a genesis block for tests.

func NewTestGenesisConf

func NewTestGenesisConf(t *testing.T, dynastySize int) (genesis *corepb.Genesis, dynasties keyutil.AddrKeyPairs, distributed keyutil.AddrKeyPairs)

NewTestGenesisConf returns a genesis configuration for tests.

func Points

func Points(t *testing.T, tx *core.Transaction, b *core.Block) *util.Uint128

Points returns bandwidth usage of a transaction.

Types

type BlockBuilder

type BlockBuilder struct {
	B *core.BlockTestWrap

	Dynasties keyutil.AddrKeyPairs
	TokenDist keyutil.AddrKeyPairs
	KeyPairs  keyutil.AddrKeyPairs
	// contains filtered or unexported fields
}

BlockBuilder is structure for building block

func New

func New(t *testing.T, dynastySize int) *BlockBuilder

New returns new block builder

func (*BlockBuilder) AccountRoot

func (bb *BlockBuilder) AccountRoot(root []byte) *BlockBuilder

AccountRoot sets account root.

func (*BlockBuilder) AddKeyPairs

func (bb *BlockBuilder) AddKeyPairs(keyPairs keyutil.AddrKeyPairs) *BlockBuilder

AddKeyPairs sets key pairs on block builder

func (*BlockBuilder) AddTx

func (bb *BlockBuilder) AddTx(tx *core.Transaction) *BlockBuilder

AddTx add transaction

func (*BlockBuilder) Block

func (bb *BlockBuilder) Block(b *core.Block) *BlockBuilder

Block sets block

func (*BlockBuilder) Build

func (bb *BlockBuilder) Build() *core.Block

Build builds block.

func (*BlockBuilder) BuildBytes

func (bb *BlockBuilder) BuildBytes() []byte

BuildBytes builds block in bytes.

func (*BlockBuilder) BuildProto

func (bb *BlockBuilder) BuildProto() *corepb.Block

BuildProto builds block in protobuf format.

func (*BlockBuilder) CalcHash

func (bb *BlockBuilder) CalcHash() *BlockBuilder

CalcHash calculate hash

func (*BlockBuilder) ChainID

func (bb *BlockBuilder) ChainID(chainID uint32) *BlockBuilder

ChainID sets chain ID.

func (*BlockBuilder) Child

func (bb *BlockBuilder) Child() *BlockBuilder

Child create child block

func (*BlockBuilder) ChildNextDynasty

func (bb *BlockBuilder) ChildNextDynasty() *BlockBuilder

ChildNextDynasty create first child block of next dynasty

func (*BlockBuilder) ChildWithTimestamp

func (bb *BlockBuilder) ChildWithTimestamp(ts int64) *BlockBuilder

ChildWithTimestamp create child block on specific timestamp

func (*BlockBuilder) Clone

func (bb *BlockBuilder) Clone() *BlockBuilder

Clone clones block on block builders (State of block must unprepared)

func (*BlockBuilder) Coinbase

func (bb *BlockBuilder) Coinbase(addr common.Address) *BlockBuilder

Coinbase sets coinbase.

func (*BlockBuilder) DposRoot

func (bb *BlockBuilder) DposRoot(root []byte) *BlockBuilder

DposRoot sets dpos root.

func (*BlockBuilder) ExecuteTx

func (bb *BlockBuilder) ExecuteTx(tx *core.Transaction) *BlockBuilder

ExecuteTx execute transaction

func (*BlockBuilder) ExecuteTxErr

func (bb *BlockBuilder) ExecuteTxErr(tx *core.Transaction, expected error) *BlockBuilder

ExecuteTxErr expect error occurred on executing

func (*BlockBuilder) Expect

func (bb *BlockBuilder) Expect() *Expect

Expect return expect

func (*BlockBuilder) FindProposer

func (bb *BlockBuilder) FindProposer() *keyutil.AddrKeyPair

FindProposer finds proposer.

func (*BlockBuilder) Flush

func (bb *BlockBuilder) Flush() *BlockBuilder

Flush saves state to storage TODO remove prepare, flush calls

func (*BlockBuilder) Genesis

func (bb *BlockBuilder) Genesis() *BlockBuilder

Genesis create genesis block

func (*BlockBuilder) GetProposer

func (bb *BlockBuilder) GetProposer() common.Address

GetProposer returns proposer.

func (*BlockBuilder) Hash

func (bb *BlockBuilder) Hash(hash []byte) *BlockBuilder

Hash sets hash

func (*BlockBuilder) Height

func (bb *BlockBuilder) Height(height uint64) *BlockBuilder

Height sets block height.

func (*BlockBuilder) ParentHash

func (bb *BlockBuilder) ParentHash(hash []byte) *BlockBuilder

ParentHash sets parenthash

func (*BlockBuilder) PayReward

func (bb *BlockBuilder) PayReward() *BlockBuilder

PayReward pay reward and update reward and supply

func (*BlockBuilder) Prepare

func (bb *BlockBuilder) Prepare() *BlockBuilder

Prepare prepare block state

func (*BlockBuilder) Reward

func (bb *BlockBuilder) Reward(reward uint64) *BlockBuilder

Reward sets reward.

func (*BlockBuilder) Seal

func (bb *BlockBuilder) Seal() *BlockBuilder

Seal set root hash on header

func (*BlockBuilder) Sealed

func (bb *BlockBuilder) Sealed(sealed bool) *BlockBuilder

Sealed sets sealed

func (*BlockBuilder) Sign

func (bb *BlockBuilder) Sign(sign []byte) *BlockBuilder

Sign sets signature.

func (*BlockBuilder) SignKey

func (bb *BlockBuilder) SignKey(key signature.PrivateKey) *BlockBuilder

SignKey signs by private key

func (*BlockBuilder) SignPair

func (bb *BlockBuilder) SignPair(pair *keyutil.AddrKeyPair) *BlockBuilder

SignPair set coinbase, seal, calculate hash and sign with key pair

func (*BlockBuilder) SignProposer

func (bb *BlockBuilder) SignProposer() *BlockBuilder

SignProposer find proposer and sign with key pair

func (*BlockBuilder) Stake

func (bb *BlockBuilder) Stake() *BlockBuilder

Stake executes stake transactions.

func (*BlockBuilder) Supply

func (bb *BlockBuilder) Supply(supply string) *BlockBuilder

Supply sets supply.

func (*BlockBuilder) Timestamp

func (bb *BlockBuilder) Timestamp(ts int64) *BlockBuilder

Timestamp sets timestamp.

func (*BlockBuilder) Tx

func (bb *BlockBuilder) Tx() *TxBuilder

Tx sets tx

func (*BlockBuilder) TxRoot

func (bb *BlockBuilder) TxRoot(root []byte) *BlockBuilder

TxRoot sets data state root.

func (*BlockBuilder) UpdateDynastyState

func (bb *BlockBuilder) UpdateDynastyState(parent *core.Block) *BlockBuilder

UpdateDynastyState update dynasty state

type Expect

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

Expect is a structure for expect

func NewExpect

func NewExpect(t *testing.T, block *core.Block) *Expect

NewExpect return new expect

func (*Expect) Balance

func (e *Expect) Balance(addr common.Address, med float64) *Expect

Balance compare balance of account to expected value

func (*Expect) GetNonce

func (e *Expect) GetNonce(addr common.Address) uint64

GetNonce gets nonce of account to expected value

func (*Expect) LastPointsTs

func (e *Expect) LastPointsTs(addr common.Address, ts int64) *Expect

LastPointsTs compares last update time of points

func (*Expect) LastUnstakingTs

func (e *Expect) LastUnstakingTs(addr common.Address, ts int64) *Expect

LastUnstakingTs compares last update time of unstaking

func (*Expect) Nonce

func (e *Expect) Nonce(addr common.Address, nonce uint64) *Expect

Nonce compare nonce of account to expected value

func (*Expect) Points

func (e *Expect) Points(addr common.Address, bandwidth *util.Uint128) *Expect

Points compares points of account to expected value

func (*Expect) Staking

func (e *Expect) Staking(addr common.Address, med float64) *Expect

Staking compare staking of account to expected value

func (*Expect) Unstaking

func (e *Expect) Unstaking(addr common.Address, med float64) *Expect

Unstaking compares unstaking of account to expected value

type TxBuilder

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

TxBuilder is a structure for transaction builder

func (*TxBuilder) Add

func (tb *TxBuilder) Add() *BlockBuilder

Add add transaction on block builder

func (*TxBuilder) Build

func (tb *TxBuilder) Build() *core.Transaction

Build build transaction

func (*TxBuilder) BuildBytes

func (tb *TxBuilder) BuildBytes() []byte

BuildBytes build marshaled transaction

func (*TxBuilder) BuildCtx

func (tb *TxBuilder) BuildCtx() *core.TxContext

BuildCtx build transaction context.

func (*TxBuilder) BuildProto

func (tb *TxBuilder) BuildProto() *corepb.Transaction

BuildProto build protobuf transaction

func (*TxBuilder) CalcHash

func (tb *TxBuilder) CalcHash() *TxBuilder

CalcHash calculate hash

func (*TxBuilder) ChainID

func (tb *TxBuilder) ChainID(chainID uint32) *TxBuilder

ChainID sets chainID

func (*TxBuilder) Execute

func (tb *TxBuilder) Execute() *BlockBuilder

Execute excute transaction on block builder

func (*TxBuilder) ExecuteErr

func (tb *TxBuilder) ExecuteErr(err error) *BlockBuilder

ExecuteErr expect error occurred on executing

func (*TxBuilder) From

func (tb *TxBuilder) From(addr common.Address) *TxBuilder

From sets from

func (*TxBuilder) Hash

func (tb *TxBuilder) Hash(hash []byte) *TxBuilder

Hash sets hash

func (*TxBuilder) Nonce

func (tb *TxBuilder) Nonce(nonce uint64) *TxBuilder

Nonce sets nonce

func (*TxBuilder) Payer

func (tb *TxBuilder) Payer(addr common.Address) *TxBuilder

Payer sets payer

func (*TxBuilder) PayerSign

func (tb *TxBuilder) PayerSign(sign []byte) *TxBuilder

PayerSign sets payerSign

func (*TxBuilder) Payload

func (tb *TxBuilder) Payload(payload transaction.Payload) *TxBuilder

Payload sets payload

func (*TxBuilder) RandomTx

func (tb *TxBuilder) RandomTx() *TxBuilder

RandomTx generate random Tx

func (*TxBuilder) RandomTxs

func (tb *TxBuilder) RandomTxs(n int) []*core.Transaction

RandomTxs generate random transactions

func (*TxBuilder) Sign

func (tb *TxBuilder) Sign(sign []byte) *TxBuilder

Sign sets sign

func (*TxBuilder) SignKey

func (tb *TxBuilder) SignKey(key signature.PrivateKey) *TxBuilder

SignKey sign by private key

func (*TxBuilder) SignPair

func (tb *TxBuilder) SignPair(pair *keyutil.AddrKeyPair) *TxBuilder

SignPair set from, seal ,calculate hash and sign with key pair

func (*TxBuilder) SignPairWithNonce

func (tb *TxBuilder) SignPairWithNonce(pair *keyutil.AddrKeyPair, nonce uint64) *TxBuilder

SignPairWithNonce set from, calculate hash, and sign with key pair.

func (*TxBuilder) SignPayerKey

func (tb *TxBuilder) SignPayerKey(key signature.PrivateKey) *TxBuilder

SignPayerKey sign by payer private key TODO Make SignPayerKey consistent with SignKey

func (*TxBuilder) SignPayerPair

func (tb *TxBuilder) SignPayerPair(pair *keyutil.AddrKeyPair) *TxBuilder

SignPayerPair sets payer and sign transaction by payer key.

func (*TxBuilder) StakeTx

func (tb *TxBuilder) StakeTx(pair *keyutil.AddrKeyPair, med float64) *TxBuilder

StakeTx generate stake Tx

func (*TxBuilder) To

func (tb *TxBuilder) To(addr common.Address) *TxBuilder

To sets to

func (*TxBuilder) Type

func (tb *TxBuilder) Type(txType string) *TxBuilder

Type sets type

func (*TxBuilder) UnstakeTx

func (tb *TxBuilder) UnstakeTx(pair *keyutil.AddrKeyPair, med float64) *TxBuilder

UnstakeTx generate stake Tx

func (*TxBuilder) Value

func (tb *TxBuilder) Value(med float64) *TxBuilder

Value sets value

func (*TxBuilder) ValueRaw

func (tb *TxBuilder) ValueRaw(value *util.Uint128) *TxBuilder

ValueRaw sets raw value in Uint128

Jump to

Keyboard shortcuts

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