testlib

package
v0.0.0-...-24e5678 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainDataPath   = "_data"
	BloomDataPath   = "_bloombits"
	BloomBitsBlocks = 24
	BloomConfirms   = 10
)
View Source
const GasLimit uint64 = 0x1DCD6500 // 500000000

Variables

View Source
var (
	ErrFileRead = errors.New("File Read Error")
	ErrArgument = errors.New("Argument Error")
)
View Source
var (
	Zero       = big.NewInt(0)
	ZeroAmount = amount.NewAmount(0, 0)
	MaxUint256 = ToAmount(Sub(Exp(big.NewInt(2), big.NewInt(256)), big.NewInt(1)))

	ZeroAddress = common.Address{}
)
View Source
var (
	ChainID = big.NewInt(61337) // mainnet 1,  testnet 65535, local 61337
	Version = uint16(2)

	GasPrice = big.NewInt(748488682)
)
View Source
var DefaultFormulatorPolicy = &formulator.FormulatorPolicy{
	AlphaAmount:    amount.NewAmount(200000, 0),
	SigmaCount:     4,
	SigmaBlocks:    200,
	OmegaCount:     2,
	OmegaBlocks:    300,
	HyperAmount:    amount.NewAmount(3000000, 0),
	MinStakeAmount: amount.NewAmount(100, 0),
}
View Source
var DefaultInitContextInfo = &InitContextInfo{}

Functions

func DexInitialize

func DexInitialize(genesis *types.Context, classMap map[string]uint64, owner, winner common.Address, intialSupplyMap map[common.Address]*amount.Amount) (*common.Address, *common.Address, *common.Address, *common.Address, *common.Address, *common.Address, error)

DexInitialize deploy dex contracts and mint neccesary tokens to sigers

func Exec

func Exec(ctx *types.Context, user common.Address, contAddr common.Address, methodName string, args []interface{}) ([]interface{}, error)

Exec calls ContractContext.Exec from Context

func Exp

func Exp(a, b *big.Int) *big.Int

Exp : exponential

func FormulatorInitialize

func FormulatorInitialize(genesis *types.Context, classMap map[string]uint64, mev, admin common.Address, alphaOwners, sigmaOwners, omegaOwners []common.Address) (*common.Address, error)

FormulatorInitialize deploy formulator contract and set alpha, sigma and omega Owners

func GetAbi

func GetAbi(abiPath string) (map[string]interface{}, *abi.ABI, error)

GetAbi returns the artifact and abi of Evm contract

func GetCC

func GetCC(ctx *types.Context, contAddr common.Address, user common.Address) (*types.ContractContext, error)

GetCC gets ContractContext from Contex with given contract address and user address

func GetSingers

func GetSingers(chainID *big.Int) ([]key.Key, error)

getSigners gets signers which are same with hardhat node users in order to test in tandem

func HaveSameElements

func HaveSameElements(a, b []common.Address) bool

HaveSameElements tells whether a and b contain the same elements.

func MevInitialize

func MevInitialize(ctx *types.Context, classMap map[string]uint64, owner common.Address, initialSupplyMap map[common.Address]*amount.Amount) (*common.Address, error)

MevInitialize deploy mev Token, mint to sigers and register mainToken as mev

func NewRewardPoolTx

func NewRewardPoolTx(senderKey key.Key, nonceIncrement uint64, provider types.Provider, tokenAddress *common.Address) (*RewardPool, *TxWithSigner, error)

NewRewardPoolTx makes New Reward Pool deploy Transaction

func RemoveChainData

func RemoveChainData(path string) error

RemoveChainData removes data directory which includes data files

func Sub

func Sub(a, b *big.Int) *big.Int

Sub : sub

func ToAmount

func ToAmount(b *big.Int) *amount.Amount

ToAmount converts big.Int to amount.Amount

func TokenApprove

func TokenApprove(ctx *types.Context, token, owner, spender common.Address) error

TokenApprove call token.Apporve(to,Amount) from Context

Types

type EvmContract

type EvmContract struct {
	Abi      *abi.ABI
	Provider types.Provider
	Address  *common.Address
}

Evm Contract

func (*EvmContract) MakeEvmTx

func (c *EvmContract) MakeEvmTx(senderKey key.Key, nonceIncrement uint64, method string, args ...any) (*TxWithSigner, error)

MakeEvmTx makes Evm Tx by argument([]any) @arg nonceIncrement : 한 signer가 동시여 여러개의 transaction을 실행할경우 nonceIncrement로 조정해 주어야 한다.

func (*EvmContract) Set

func (c *EvmContract) Set(abi *abi.ABI, provider types.Provider, addr *common.Address)

SetAddress sets the address of EvmContract

func (*EvmContract) SetAddress

func (c *EvmContract) SetAddress(addr *common.Address)

SetAddress sets the address of EvmContract

type FormulatorContract

type FormulatorContract struct {
	GoContract
}

Formulator is a Go Formulator Contract

func BindFormulatorContract

func BindFormulatorContract(address *common.Address, provider types.Provider) *FormulatorContract

NewFormulatorContract gets the depoloyed formulator contract by address

func (*FormulatorContract) BuyFormulatorTx

func (c *FormulatorContract) BuyFormulatorTx(senderKey key.Key, tokenID common.Address) *TxWithSigner

BuyFormulatorTx returns the BuyFormulator method tx of the Formulator contract

func (*FormulatorContract) CreateAlphaTx

func (c *FormulatorContract) CreateAlphaTx(senderKey key.Key) *TxWithSigner

CreateAlphaTx returns the CreateAlpha method tx of the Formulator contract

func (*FormulatorContract) CreateOmegaTx

func (c *FormulatorContract) CreateOmegaTx(senderKey key.Key, tokenIDs []common.Address) *TxWithSigner

CreateOmegaTx returns the CreateOmega method tx of the Formulator contract

func (*FormulatorContract) CreateSigmaTx

func (c *FormulatorContract) CreateSigmaTx(senderKey key.Key, tokenIDs []common.Address) *TxWithSigner

CreateSigmaTx returns the CreateSigma method tx of the Formulator contract

func (*FormulatorContract) RegisterSalesTx

func (c *FormulatorContract) RegisterSalesTx(senderKey key.Key, tokenID common.Address, amt *amount.Amount) *TxWithSigner

RegisterSalesTx returns the RegisterSales method tx of the Formulator contract

func (*FormulatorContract) RevokeTx

func (c *FormulatorContract) RevokeTx(senderKey key.Key, tokenID common.Address) *TxWithSigner

RevokeTx returns the Revoke method tx of the Formulator contract

func (*FormulatorContract) SyncGeneratorTx

func (c *FormulatorContract) SyncGeneratorTx(senderKey key.Key) *TxWithSigner

SyncGeneratorTx returns the SyncGenerator method tx of the Formulator contract

func (*FormulatorContract) TransferFromTx

func (c *FormulatorContract) TransferFromTx(senderKey key.Key, from, to, tokenID common.Address) *TxWithSigner

TransferFromTx returns the TransferFrom method tx of the Formulator contract

type GoContract

type GoContract struct {
	Address  *common.Address
	Provider types.Provider
}

GoContract

func (*GoContract) SetAddress

func (c *GoContract) SetAddress(addr *common.Address)

SetAddress sets the address of GoContract

func (*GoContract) SetProvider

func (c *GoContract) SetProvider(provider types.Provider)

SetProvider sets the provider of GoContract

type IEvmContract

type IEvmContract interface {
	Set(abi *abi.ABI, provider types.Provider, addr *common.Address)
	SetAddress(*common.Address)
	// contains filtered or unexported methods
}

Evm Contract Interface

type InitContextInfo

type InitContextInfo struct {
	InitGenesisHash string
	InitHash        string
	InitHeight      uint32
	InitTimestamp   uint64
}

InitContextInfo struct is parameters for meverse chain with non-zero initheight

type JsonClient

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

JsonClient is a json-rpc senter

func NewJsonClient

func NewJsonClient(tb *TestBlockChain) *JsonClient

NewJsonClient makes a new JsonClient

func (*JsonClient) GetBlockByNumber

func (jc *JsonClient) GetBlockByNumber(height uint32, isFull bool) map[string]interface{}

GetBlockByNumber executes an eth_getBlockByNumber json-rpc

func (*JsonClient) GetLogs

func (jc *JsonClient) GetLogs(filterMap map[string]interface{}) []*types.Log

GetLogs executes an eth_getLogs json-rpc filterMap := map[string]interface{}{} filterMap["address"] = address.String() filterMap["blockHash"] = blockHash.String() filterMap["fromBlock"] = fmt.Sprintf("0x%x", *big.Int) filterMap["toBlock"] = fmt.Sprintf("0x%x", *big.Int) filterMap["topics"] = []interface{}{[]interface{}{transferHash.String()}} or

[]interface{}{transferHash.String()}

topics : service/bloomservice/filter.go FilterQuery struct 참조

func (*JsonClient) GetTransactionReceipt

func (jc *JsonClient) GetTransactionReceipt(hash common.Hash) map[string]interface{}

GetTransactionReceipt executes an eth_getTransactionReceipt json-rpc

func (*JsonClient) ViewCall

func (jc *JsonClient) ViewCall(to *common.Address, method string, params ...any) interface{}

ViewCall executes an view.call json-rpc to non-evm contract

type Mrc20Token

type Mrc20Token struct {
	EvmContract
}

Mrc20Token is deployed by Go-Contract, but has a similiar ERC20-token-abi

func NewMrc20Token

func NewMrc20Token(tb *TestBlockChain, senderKey key.Key, name, symbol string) (*Mrc20Token, error)

NewMrc20Token deploy Go Token Contract and convert to Evm MRC20 Token

func NewMrc20TokenFromAddress

func NewMrc20TokenFromAddress(contractAddress *common.Address, provider types.Provider) (*Mrc20Token, error)

NewMrc20TokenFromAddress makes Mrc20Token EVm Contract with address

func (*Mrc20Token) ApproveTx

func (c *Mrc20Token) ApproveTx(senderKey key.Key, nonceIncrement uint64, to *common.Address, amount *big.Int) (*TxWithSigner, error)

ApproveTx returns the approve method tx of the Mrc20 contract

type RewardPool

type RewardPool struct {
	EvmContract
}

type RewardPool Contract source code : fleta2.0/contracts/RewardPool/RewardPool.sol

func (*RewardPool) AddRewardTx

func (c *RewardPool) AddRewardTx(senderKey key.Key, nonceIncrement uint64, total *big.Int, userRewards []UserReward) (*TxWithSigner, error)

AddRewardTx returns the addReward method tx of the RewardPool contract

func (*RewardPool) ClaimTx

func (c *RewardPool) ClaimTx(senderKey key.Key, nonceIncrement uint64) (*TxWithSigner, error)

ClaimTx returns the claim method tx of the RewardPool contract

type RouterContract

type RouterContract struct {
	GoContract
}

Router is a Go Router Contract

func BindRouterContract

func BindRouterContract(address *common.Address, provider types.Provider) *RouterContract

NewGoContract makes new Go Contract

func (*RouterContract) UniAddLiquidityTx

func (c *RouterContract) UniAddLiquidityTx(senderKey key.Key, token0, token1 common.Address, amountADesired, amountBDesired, amountAMin, amountBMin *amount.Amount) *TxWithSigner

UniAddLiquidityTx returns the UniAddLiquidity method tx of the Router contract

type TestBlockChain

type TestBlockChain struct {
	ChainID  *big.Int //
	Version  uint16
	Path     string // 화일저장 디렉토리
	Chain    *chain.Chain
	Store    *chain.Store
	Provider types.Provider

	FrKeyMap        map[common.Address]key.Key
	ClassMap        map[string]uint64
	StepMiliSeconds uint64 // interval from previous transaction

	Ts itxsearch.ITxSearch
	Bs *bloomservice.BloomBitService
	// contains filtered or unexported fields
}

TestBlockChain is blockchain mock for testing

func NewTestBlockChain

func NewTestBlockChain(path string, deletePath bool, chainID *big.Int, version uint16, chainAdmin common.Address, genesisInitFunc func(*types.Context, map[string]uint64) error, cfg *InitContextInfo) *TestBlockChain

func NewTestBlockChainWithGenesis

func NewTestBlockChainWithGenesis(path string, deletePath bool, chainID *big.Int, version uint16, genesis *types.Context, admin common.Address, cfg *InitContextInfo, classMap map[string]uint64) (*TestBlockChain, error)

NewTestBlockChain makes new test blockchain

func (*TestBlockChain) AddBlock

func (tb *TestBlockChain) AddBlock(txs []*TxWithSigner) (*types.Block, error)

AddBlock adds a block containing txs The block time forwarded by tb.StepMiliSeconds

func (*TestBlockChain) Close

func (tb *TestBlockChain) Close()

Close calls chain.Close()

func (*TestBlockChain) HandleJRPC

func (tb *TestBlockChain) HandleJRPC(req *apiserver.JRPCRequest) interface{}

newContext calls chain.NewContext()

func (*TestBlockChain) MustAddBlock

func (tb *TestBlockChain) MustAddBlock(txs []*TxWithSigner) *types.Block

MustAddBlock adds a block containing txs without err The block time forwarded by tb.StepMiliSeconds

type TokenContract

type TokenContract struct {
	GoContract
}

Token is a Go Token Contract

func BindTokenContract

func BindTokenContract(address *common.Address, provider types.Provider) *TokenContract

NewGoContract makes new Go Contract

func (*TokenContract) ApproveTx

func (c *TokenContract) ApproveTx(senderKey key.Key, to common.Address, amt *amount.Amount) *TxWithSigner

ApproveTx returns the Approve method tx of the Token contract

func (*TokenContract) TransferTx

func (c *TokenContract) TransferTx(senderKey key.Key, to common.Address, amt *amount.Amount) *TxWithSigner

TransferTx returns the Transfer method tx of the Token contract

type TsMock

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

tsMock is the mock of txsearch service range로 검색할 경우 txsearch는 필요없기 때문에 mock으로 가능

func NewTsMocK

func NewTsMocK(provider types.Provider) *TsMock

func (*TsMock) AddBlock

func (t *TsMock) AddBlock(b *types.Block)

func (*TsMock) AddressTxList

func (t *TsMock) AddressTxList(From common.Address, index, size int) ([]itxsearch.TxList, error)

func (*TsMock) Block

func (t *TsMock) Block(i uint32) (*types.Block, error)

func (*TsMock) BlockHeight

func (t *TsMock) BlockHeight(bh hash.Hash256) (uint32, error)

func (*TsMock) BlockList

func (t *TsMock) BlockList(index int) []*itxsearch.BlockInfo

func (*TsMock) Name

func (t *TsMock) Name() string

Name returns the name of the service

func (*TsMock) OnBlockConnected

func (t *TsMock) OnBlockConnected(b *types.Block, loader types.Loader)

OnBlockConnected called when a block is connected to the chain

func (*TsMock) OnLoadChain

func (t *TsMock) OnLoadChain(loader types.Loader) error

OnLoadChain called when the chain loaded

func (*TsMock) OnTransactionFail

func (t *TsMock) OnTransactionFail(height uint32, txs []*types.Transaction, err []error)

OnTransactionFail called when the tx fail

func (*TsMock) OnTransactionInPoolExpired

func (t *TsMock) OnTransactionInPoolExpired(txs []*types.Transaction)

OnLoadChain called when the chain loaded

func (*TsMock) Reward

func (t *TsMock) Reward(cont, rewarder common.Address) (*amount.Amount, error)

func (*TsMock) TokenTxList

func (t *TsMock) TokenTxList(From common.Address, index, size int) ([]itxsearch.TxList, error)

func (*TsMock) Tx

func (t *TsMock) Tx(height uint32, index uint16) (map[string]interface{}, error)

func (*TsMock) TxIndex

func (t *TsMock) TxIndex(th hash.Hash256) (itxsearch.TxID, error)

func (*TsMock) TxList

func (t *TsMock) TxList(index, size int) ([]itxsearch.TxList, error)

type TxWithSigner

type TxWithSigner struct {
	Tx     *types.Transaction
	Signer key.Key
}

non-evmtype transaction with signer key

func DeployFormulatorTx

func DeployFormulatorTx(tb *TestBlockChain, senderKey key.Key, mev, admin common.Address) (*TxWithSigner, error)

DeployFormulatorTx makes the formulator deploy tx

func DeployTokenTx

func DeployTokenTx(tb *TestBlockChain, senderKey key.Key, name, symbol string, initialSupplyMap map[common.Address]*amount.Amount) (*TxWithSigner, error)

DeployTokenTx makes the token deploy tx

func MakeGoTx

func MakeGoTx(senderKey key.Key, provider types.Provider, cont *common.Address, method string, args ...any) *TxWithSigner

MakeGoContract makes go Contract transaction

func NewEvmContractTx

func NewEvmContractTx(cont IEvmContract, senderKey key.Key, nonceIncrement uint64, provider types.Provider, abiPath string, args ...any) (*TxWithSigner, error)

NewEvmContract makes new Contract, abiPath is relative path

func NewTxWithSigner

func NewTxWithSigner(tx *types.Transaction, signer key.Key) *TxWithSigner

NewTxWithSigner makes a new TxWithSigner struct

type UserReward

type UserReward struct {
	User   common.Address
	Amount *big.Int
}

type UserReward

Jump to

Keyboard shortcuts

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