test

package
v0.0.0-...-e04c47b Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertUSD

func AssertUSD(t *testing.T, expected, actual *float64)

AssertUSD asserts pointers to float64, and checks that they are equal with a tolerance of 0.01%. After that, the actual value is setted to the expected value in order to be able to perform further assertions using the standar assert functions.

func WipeDB

func WipeDB(db *sqlx.DB)

WipeDB redo all the migrations of the SQL DB (HistoryDB and L2DB), efectively recreating the original state

Types

type AuctionBlock

type AuctionBlock struct {
	State     eth.AuctionState
	Vars      common.AuctionVariables
	Events    eth.AuctionEvents
	Txs       map[ethCommon.Hash]*types.Transaction
	Constants *common.AuctionConstants
	Eth       *EthereumBlock
}

AuctionBlock stores all the data related to the Auction SC from an ethereum block

type Block

type Block struct {
	Rollup   *RollupBlock
	Auction  *AuctionBlock
	WDelayer *WDelayerBlock
	Eth      *EthereumBlock
}

Block represents a ethereum block

func (*Block) Next

func (b *Block) Next() *Block

Next prepares the successive block.

type Client

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

Client implements the eth.ClientInterface interface, allowing to manipulate the values for testing, working with deterministic results.

func NewClient

func NewClient(l bool, timer Timer, addr *ethCommon.Address, setup *ClientSetup) *Client

NewClient returns a new test Client that implements the eth.IClient interface, at the given initialBlockNumber.

func (*Client) AuctionBid

func (c *Client) AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int,
	deadline *big.Int) (tx *types.Transaction, err error)

AuctionBid is the interface to call the smart contract function. This implementation behaves as if any address has infinite tokens.

func (*Client) AuctionBidSimple

func (c *Client) AuctionBidSimple(slot int64, bidAmount *big.Int) (tx *types.Transaction,
	err error)

AuctionBidSimple is a wrapper around AuctionBid that automatically sets `amount` and `deadline`.

func (*Client) AuctionCanForge

func (c *Client) AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)

AuctionCanForge is the interface to call the smart contract function

func (*Client) AuctionChangeDefaultSlotSetBid

func (c *Client) AuctionChangeDefaultSlotSetBid(slotSet int64,
	newInitialMinBid *big.Int) (tx *types.Transaction, err error)

AuctionChangeDefaultSlotSetBid is the interface to call the smart contract function

func (*Client) AuctionClaimCB

func (c *Client) AuctionClaimCB() (tx *types.Transaction, err error)

AuctionClaimCB is the interface to call the smart contract function

func (*Client) AuctionConstants

func (c *Client) AuctionConstants() (*common.AuctionConstants, error)

AuctionConstants returns the Constants of the Auction Smart Contract

func (*Client) AuctionEventInit

func (c *Client) AuctionEventInit(genesisBlockNum int64) (*eth.AuctionEventInitialize, int64, error)

AuctionEventInit returns the initialize event with its corresponding block number

func (*Client) AuctionEventsByBlock

func (c *Client) AuctionEventsByBlock(blockNum int64,
	blockHash *ethCommon.Hash) (*eth.AuctionEvents, error)

AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract

func (*Client) AuctionForge

func (c *Client) AuctionForge(forger ethCommon.Address) (tx *types.Transaction, err error)

AuctionForge is the interface to call the smart contract function

func (*Client) AuctionGetAllocationRatio

func (c *Client) AuctionGetAllocationRatio() ([3]uint16, error)

AuctionGetAllocationRatio is the interface to call the smart contract function

func (*Client) AuctionGetBootCoordinator

func (c *Client) AuctionGetBootCoordinator() (*ethCommon.Address, error)

AuctionGetBootCoordinator is the interface to call the smart contract function

func (*Client) AuctionGetClaimableCB

func (c *Client) AuctionGetClaimableCB(bidder ethCommon.Address) (*big.Int, error)

AuctionGetClaimableCB is the interface to call the smart contract function

func (*Client) AuctionGetClosedAuctionSlots

func (c *Client) AuctionGetClosedAuctionSlots() (uint16, error)

AuctionGetClosedAuctionSlots is the interface to call the smart contract function

func (*Client) AuctionGetCurrentSlotNumber

func (c *Client) AuctionGetCurrentSlotNumber() (int64, error)

AuctionGetCurrentSlotNumber is the interface to call the smart contract function

func (*Client) AuctionGetDefaultSlotSetBid

func (c *Client) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error)

AuctionGetDefaultSlotSetBid is the interface to call the smart contract function

func (*Client) AuctionGetDonationAddress

func (c *Client) AuctionGetDonationAddress() (*ethCommon.Address, error)

AuctionGetDonationAddress is the interface to call the smart contract function

func (*Client) AuctionGetMinBidBySlot

func (c *Client) AuctionGetMinBidBySlot(slot int64) (*big.Int, error)

AuctionGetMinBidBySlot is the interface to call the smart contract function

func (*Client) AuctionGetOpenAuctionSlots

func (c *Client) AuctionGetOpenAuctionSlots() (uint16, error)

AuctionGetOpenAuctionSlots is the interface to call the smart contract function

func (*Client) AuctionGetOutbidding

func (c *Client) AuctionGetOutbidding() (uint16, error)

AuctionGetOutbidding is the interface to call the smart contract function

func (*Client) AuctionGetSlotDeadline

func (c *Client) AuctionGetSlotDeadline() (uint8, error)

AuctionGetSlotDeadline is the interface to call the smart contract function

func (*Client) AuctionGetSlotNumber

func (c *Client) AuctionGetSlotNumber(blockNum int64) (int64, error)

AuctionGetSlotNumber is the interface to call the smart contract function

func (*Client) AuctionGetSlotSet

func (c *Client) AuctionGetSlotSet(slot int64) (*big.Int, error)

AuctionGetSlotSet is the interface to call the smart contract function

func (*Client) AuctionIsRegisteredCoordinator

func (c *Client) AuctionIsRegisteredCoordinator(forgerAddress ethCommon.Address) (bool, error)

AuctionIsRegisteredCoordinator is the interface to call the smart contract function

func (*Client) AuctionMultiBid

func (c *Client) AuctionMultiBid(amount *big.Int, startingSlot int64, endingSlot int64,
	slotSet [6]bool, maxBid, closedMinBid, deadline *big.Int) (tx *types.Transaction, err error)

AuctionMultiBid is the interface to call the smart contract function. This implementation behaves as if any address has infinite tokens.

func (*Client) AuctionSetAllocationRatio

func (c *Client) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (tx *types.Transaction,
	err error)

AuctionSetAllocationRatio is the interface to call the smart contract function

func (*Client) AuctionSetBootCoordinator

func (c *Client) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address,
	newBootCoordinatorURL string) (tx *types.Transaction, err error)

AuctionSetBootCoordinator is the interface to call the smart contract function

func (*Client) AuctionSetClosedAuctionSlots

func (c *Client) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (tx *types.Transaction,
	err error)

AuctionSetClosedAuctionSlots is the interface to call the smart contract function

func (*Client) AuctionSetCoordinator

func (c *Client) AuctionSetCoordinator(forger ethCommon.Address,
	URL string) (tx *types.Transaction, err error)

AuctionSetCoordinator is the interface to call the smart contract function

func (*Client) AuctionSetDonationAddress

func (c *Client) AuctionSetDonationAddress(
	newDonationAddress ethCommon.Address) (tx *types.Transaction, err error)

AuctionSetDonationAddress is the interface to call the smart contract function

func (*Client) AuctionSetOpenAuctionSlots

func (c *Client) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (tx *types.Transaction,
	err error)

AuctionSetOpenAuctionSlots is the interface to call the smart contract function

func (*Client) AuctionSetOutbidding

func (c *Client) AuctionSetOutbidding(newOutbidding uint16) (tx *types.Transaction, err error)

AuctionSetOutbidding is the interface to call the smart contract function

func (*Client) AuctionSetSlotDeadline

func (c *Client) AuctionSetSlotDeadline(newDeadline uint8) (tx *types.Transaction, err error)

AuctionSetSlotDeadline is the interface to call the smart contract function

func (*Client) AuctionUpdateCoordinatorInfo

func (c *Client) AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address,
	newWithdrawAddress ethCommon.Address, newURL string) (tx *types.Transaction, err error)

AuctionUpdateCoordinatorInfo is the interface to call the smart contract function

func (*Client) CtlAddBatch

func (c *Client) CtlAddBatch(args *eth.RollupForgeBatchArgs)

CtlAddBatch adds forged batch to the Rollup, without checking any ZKProof

func (*Client) CtlAddBlocks

func (c *Client) CtlAddBlocks(blocks []common.BlockData) (err error)

CtlAddBlocks adds block data to the smarts contracts. The added blocks will appear as mined. Not thread safe.

func (*Client) CtlAddERC20

func (c *Client) CtlAddERC20(tokenAddr ethCommon.Address, constants eth.ERC20Consts)

CtlAddERC20 adds an ERC20 token to the blockchain.

func (*Client) CtlLastBlock

func (c *Client) CtlLastBlock() *common.Block

CtlLastBlock returns the last blockNum without checks

func (*Client) CtlLastForgedBatch

func (c *Client) CtlLastForgedBatch() int64

CtlLastForgedBatch returns the last batchNum without checks

func (*Client) CtlMineBlock

func (c *Client) CtlMineBlock()

CtlMineBlock moves one block forward

func (*Client) CtlRollback

func (c *Client) CtlRollback()

CtlRollback discards the last mined block. Use this to replace a mined block to simulate reorgs.

func (*Client) CtlSetAddr

func (c *Client) CtlSetAddr(addr ethCommon.Address)

CtlSetAddr sets the address of the client

func (*Client) Debugf

func (c *Client) Debugf(template string, args ...interface{})

Debugf calls log.Debugf if c.log is true

func (*Client) Debugw

func (c *Client) Debugw(template string, kv ...interface{})

Debugw calls log.Debugw if c.log is true

func (*Client) EthAddress

func (c *Client) EthAddress() (*ethCommon.Address, error)

EthAddress returns the ethereum address of the account loaded into the Client

func (*Client) EthBlockByNumber

func (c *Client) EthBlockByNumber(ctx context.Context, blockNum int64) (*common.Block, error)

EthBlockByNumber returns the *common.Block for the given block number in a deterministic way. If number == -1, the latests known block is returned.

func (*Client) EthCall

func (c *Client) EthCall(ctx context.Context, tx *types.Transaction,
	blockNum *big.Int) ([]byte, error)

EthCall runs the transaction as a call (without paying) in the local node at blockNum.

func (*Client) EthChainID

func (c *Client) EthChainID() (*big.Int, error)

EthChainID returns the ChainID of the ethereum network

func (*Client) EthERC20Consts

func (c *Client) EthERC20Consts(tokenAddr ethCommon.Address) (*eth.ERC20Consts, error)

EthERC20Consts returns the constants defined for a particular ERC20 Token instance.

func (*Client) EthKeyStore

func (c *Client) EthKeyStore() *ethKeystore.KeyStore

EthKeyStore returns the keystore in the Client

func (*Client) EthLastBlock

func (c *Client) EthLastBlock() (int64, error)

EthLastBlock returns the last blockNum

func (*Client) EthNonceAt

func (c *Client) EthNonceAt(ctx context.Context, account ethCommon.Address,
	blockNumber *big.Int) (uint64, error)

EthNonceAt returns the account nonce of the given account. The block number can be nil, in which case the nonce is taken from the latest known block.

func (*Client) EthPendingNonceAt

func (c *Client) EthPendingNonceAt(ctx context.Context, account ethCommon.Address) (uint64, error)

EthPendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.

func (*Client) EthSuggestGasPrice

func (c *Client) EthSuggestGasPrice(ctx context.Context) (*big.Int, error)

EthSuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.

func (*Client) EthTransactionReceipt

func (c *Client) EthTransactionReceipt(ctx context.Context,
	txHash ethCommon.Hash) (*types.Receipt, error)

EthTransactionReceipt returns the transaction receipt of the given txHash

func (*Client) RollupAddToken

func (c *Client) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int,
	deadline *big.Int) (tx *types.Transaction, err error)

RollupAddToken is the interface to call the smart contract function

func (*Client) RollupAddTokenSimple

func (c *Client) RollupAddTokenSimple(tokenAddress ethCommon.Address,
	feeAddToken *big.Int) (tx *types.Transaction, err error)

RollupAddTokenSimple is a wrapper around RollupAddToken that automatically sets `deadlie`.

func (*Client) RollupConstants

func (c *Client) RollupConstants() (*common.RollupConstants, error)

RollupConstants returns the Constants of the Rollup Smart Contract

func (*Client) RollupEventInit

func (c *Client) RollupEventInit(genesisBlockNum int64) (*eth.RollupEventInitialize, int64, error)

RollupEventInit returns the initialize event with its corresponding block number

func (*Client) RollupEventsByBlock

func (c *Client) RollupEventsByBlock(blockNum int64,
	blockHash *ethCommon.Hash) (*eth.RollupEvents, error)

RollupEventsByBlock returns the events in a block that happened in the Rollup Smart Contract

func (*Client) RollupForgeBatch

func (c *Client) RollupForgeBatch(args *eth.RollupForgeBatchArgs,
	auth *bind.TransactOpts) (tx *types.Transaction, err error)

RollupForgeBatch is the interface to call the smart contract function

func (*Client) RollupForgeBatchArgs

func (c *Client) RollupForgeBatchArgs(ethTxHash ethCommon.Hash,
	l1UserTxsLen uint16) (*eth.RollupForgeBatchArgs, *ethCommon.Address, error)

RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the Rollup Smart Contract in the given transaction

func (*Client) RollupGetCurrentTokens

func (c *Client) RollupGetCurrentTokens() (*big.Int, error)

RollupGetCurrentTokens is the interface to call the smart contract function

func (*Client) RollupL1UserTxERC20ETH

func (c *Client) RollupL1UserTxERC20ETH(
	fromBJJ babyjub.PublicKeyComp,
	fromIdx int64,
	depositAmount *big.Int,
	amount *big.Int,
	tokenID uint32,
	toIdx int64,
) (tx *types.Transaction, err error)

RollupL1UserTxERC20ETH sends an L1UserTx to the Rollup.

func (*Client) RollupL1UserTxERC20Permit

func (c *Client) RollupL1UserTxERC20Permit(fromBJJ babyjub.PublicKeyComp, fromIdx int64,
	depositAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64,
	deadline *big.Int) (tx *types.Transaction, err error)

RollupL1UserTxERC20Permit is the interface to call the smart contract function

func (*Client) RollupLastForgedBatch

func (c *Client) RollupLastForgedBatch() (int64, error)

RollupLastForgedBatch is the interface to call the smart contract function

func (*Client) RollupRegisterTokensCount

func (c *Client) RollupRegisterTokensCount() (*big.Int, error)

RollupRegisterTokensCount is the interface to call the smart contract function

func (*Client) RollupUpdateFeeAddToken

func (c *Client) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *types.Transaction,
	err error)

RollupUpdateFeeAddToken is the interface to call the smart contract function

func (*Client) RollupUpdateForgeL1L2BatchTimeout

func (c *Client) RollupUpdateForgeL1L2BatchTimeout(newForgeL1Timeout int64) (tx *types.Transaction,
	err error)

RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function

func (*Client) RollupWithdrawCircuit

func (c *Client) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB [2][2]*big.Int,
	tokenID uint32, numExitRoot, idx int64, amount *big.Int,
	instantWithdraw bool) (*types.Transaction, error)

RollupWithdrawCircuit is the interface to call the smart contract function

func (*Client) RollupWithdrawMerkleProof

func (c *Client) RollupWithdrawMerkleProof(babyPubKey babyjub.PublicKeyComp,
	tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int,
	instantWithdraw bool) (tx *types.Transaction, err error)

RollupWithdrawMerkleProof is the interface to call the smart contract function

func (*Client) WDelayerChangeWithdrawalDelay

func (c *Client) WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (tx *types.Transaction,
	err error)

WDelayerChangeWithdrawalDelay is the interface to call the smart contract function

func (*Client) WDelayerClaimEmergencyCouncil

func (c *Client) WDelayerClaimEmergencyCouncil() (tx *types.Transaction, err error)

WDelayerClaimEmergencyCouncil is the interface to call the smart contract function

func (*Client) WDelayerClaimGovernance

func (c *Client) WDelayerClaimGovernance() (tx *types.Transaction, err error)

WDelayerClaimGovernance is the interface to call the smart contract function

func (*Client) WDelayerConstants

func (c *Client) WDelayerConstants() (*common.WDelayerConstants, error)

WDelayerConstants returns the Constants of the WDelayer Contract

func (*Client) WDelayerDeposit

func (c *Client) WDelayerDeposit(onwer, token ethCommon.Address, amount *big.Int) (
	tx *types.Transaction, err error)

WDelayerDeposit is the interface to call the smart contract function

func (*Client) WDelayerDepositInfo

func (c *Client) WDelayerDepositInfo(owner, token ethCommon.Address) (eth.DepositState, error)

WDelayerDepositInfo is the interface to call the smart contract function

func (*Client) WDelayerEnableEmergencyMode

func (c *Client) WDelayerEnableEmergencyMode() (tx *types.Transaction, err error)

WDelayerEnableEmergencyMode is the interface to call the smart contract function

func (*Client) WDelayerEscapeHatchWithdrawal

func (c *Client) WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address, amount *big.Int) (
	tx *types.Transaction, err error)

WDelayerEscapeHatchWithdrawal is the interface to call the smart contract function

func (*Client) WDelayerEventInit

func (c *Client) WDelayerEventInit(genesisBlockNum int64) (*eth.WDelayerEventInitialize, int64, error)

WDelayerEventInit returns the initialize event with its corresponding block number

func (*Client) WDelayerEventsByBlock

func (c *Client) WDelayerEventsByBlock(blockNum int64,
	blockHash *ethCommon.Hash) (*eth.WDelayerEvents, error)

WDelayerEventsByBlock returns the events in a block that happened in the WDelayer Contract

func (*Client) WDelayerGetChainbingGovernanceAddress

func (c *Client) WDelayerGetChainbingGovernanceAddress() (*ethCommon.Address, error)

WDelayerGetChainbingGovernanceAddress is the interface to call the smart contract function

func (*Client) WDelayerGetEmergencyCouncil

func (c *Client) WDelayerGetEmergencyCouncil() (*ethCommon.Address, error)

WDelayerGetEmergencyCouncil is the interface to call the smart contract function

func (*Client) WDelayerGetEmergencyModeStartingTime

func (c *Client) WDelayerGetEmergencyModeStartingTime() (int64, error)

WDelayerGetEmergencyModeStartingTime is the interface to call the smart contract function

func (*Client) WDelayerGetWithdrawalDelay

func (c *Client) WDelayerGetWithdrawalDelay() (int64, error)

WDelayerGetWithdrawalDelay is the interface to call the smart contract function

func (*Client) WDelayerIsEmergencyMode

func (c *Client) WDelayerIsEmergencyMode() (bool, error)

WDelayerIsEmergencyMode is the interface to call the smart contract function

func (*Client) WDelayerTransferEmergencyCouncil

func (c *Client) WDelayerTransferEmergencyCouncil(newAddress ethCommon.Address) (
	tx *types.Transaction, err error)

WDelayerTransferEmergencyCouncil is the interface to call the smart contract function

func (*Client) WDelayerTransferGovernance

func (c *Client) WDelayerTransferGovernance(newAddress ethCommon.Address) (tx *types.Transaction,
	err error)

WDelayerTransferGovernance is the interface to call the smart contract function

func (*Client) WDelayerWithdrawal

func (c *Client) WDelayerWithdrawal(owner, token ethCommon.Address) (tx *types.Transaction,
	err error)

WDelayerWithdrawal is the interface to call the smart contract function

type ClientSetup

type ClientSetup struct {
	RollupConstants   *common.RollupConstants
	RollupVariables   *common.RollupVariables
	AuctionConstants  *common.AuctionConstants
	AuctionVariables  *common.AuctionVariables
	WDelayerConstants *common.WDelayerConstants
	WDelayerVariables *common.WDelayerVariables
	VerifyProof       bool
	ChainID           *big.Int
}

ClientSetup is used to initialize the constants of the Smart Contracts and other details of the test Client

func NewClientSetupExample

func NewClientSetupExample() *ClientSetup

NewClientSetupExample returns a ClientSetup example with hardcoded realistic values. With this setup, the rollup genesis will be block 1, and block 0 and 1 will be premined.

type EthereumBlock

type EthereumBlock struct {
	BlockNum   int64
	Time       int64
	Hash       ethCommon.Hash
	ParentHash ethCommon.Hash
	Tokens     map[ethCommon.Address]eth.ERC20Consts
	Nonce      uint64
}

EthereumBlock stores all the generic data related to the an ethereum block

type RollupBlock

type RollupBlock struct {
	State     eth.RollupState
	Vars      common.RollupVariables
	Events    eth.RollupEvents
	Txs       map[ethCommon.Hash]*types.Transaction
	Constants *common.RollupConstants
	Eth       *EthereumBlock
}

RollupBlock stores all the data related to the Rollup SC from an ethereum block

type Timer

type Timer interface {
	Time() int64
}

Timer is an interface to simulate a source of time, useful to advance time virtually.

type WDelayerBlock

type WDelayerBlock struct {
	// State     eth.WDelayerState // TODO
	Vars      common.WDelayerVariables
	Events    eth.WDelayerEvents
	Txs       map[ethCommon.Hash]*types.Transaction
	Constants *common.WDelayerConstants
	Eth       *EthereumBlock
}

WDelayerBlock stores all the data related to the WDelayer SC from an ethereum block

Directories

Path Synopsis
proofserver
cmd

Jump to

Keyboard shortcuts

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