github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/powchain/testing/mock_faulty_powchain.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"math/big"
     7  
     8  	"github.com/ethereum/go-ethereum/common"
     9  	"github.com/prysmaticlabs/prysm/beacon-chain/powchain/types"
    10  	iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
    11  	"github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
    12  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    13  	"github.com/prysmaticlabs/prysm/shared/event"
    14  	"github.com/prysmaticlabs/prysm/shared/trieutil"
    15  )
    16  
    17  // FaultyMockPOWChain defines an incorrectly functioning powchain service.
    18  type FaultyMockPOWChain struct {
    19  	ChainFeed      *event.Feed
    20  	HashesByHeight map[int][]byte
    21  }
    22  
    23  // Eth2GenesisPowchainInfo --
    24  func (f *FaultyMockPOWChain) Eth2GenesisPowchainInfo() (uint64, *big.Int) {
    25  	return 0, big.NewInt(0)
    26  }
    27  
    28  // LatestBlockHeight --
    29  func (f *FaultyMockPOWChain) LatestBlockHeight() *big.Int {
    30  	return big.NewInt(0)
    31  }
    32  
    33  // BlockExists --
    34  func (f *FaultyMockPOWChain) BlockExists(_ context.Context, _ common.Hash) (bool, *big.Int, error) {
    35  	if f.HashesByHeight == nil {
    36  		return false, big.NewInt(1), errors.New("failed")
    37  	}
    38  
    39  	return true, big.NewInt(1), nil
    40  }
    41  
    42  // BlockHashByHeight --
    43  func (f *FaultyMockPOWChain) BlockHashByHeight(_ context.Context, _ *big.Int) (common.Hash, error) {
    44  	return [32]byte{}, errors.New("failed")
    45  }
    46  
    47  // BlockTimeByHeight --
    48  func (f *FaultyMockPOWChain) BlockTimeByHeight(_ context.Context, _ *big.Int) (uint64, error) {
    49  	return 0, errors.New("failed")
    50  }
    51  
    52  // BlockByTimestamp --
    53  func (f *FaultyMockPOWChain) BlockByTimestamp(_ context.Context, _ uint64) (*types.HeaderInfo, error) {
    54  	return &types.HeaderInfo{Number: big.NewInt(0)}, nil
    55  }
    56  
    57  // DepositRoot --
    58  func (f *FaultyMockPOWChain) DepositRoot() [32]byte {
    59  	return [32]byte{}
    60  }
    61  
    62  // DepositTrie --
    63  func (f *FaultyMockPOWChain) DepositTrie() *trieutil.SparseMerkleTrie {
    64  	return &trieutil.SparseMerkleTrie{}
    65  }
    66  
    67  // ChainStartDeposits --
    68  func (f *FaultyMockPOWChain) ChainStartDeposits() []*ethpb.Deposit {
    69  	return []*ethpb.Deposit{}
    70  }
    71  
    72  // ChainStartEth1Data --
    73  func (f *FaultyMockPOWChain) ChainStartEth1Data() *ethpb.Eth1Data {
    74  	return &ethpb.Eth1Data{}
    75  }
    76  
    77  // PreGenesisState --
    78  func (f *FaultyMockPOWChain) PreGenesisState() iface.BeaconState {
    79  	return &v1.BeaconState{}
    80  }
    81  
    82  // ClearPreGenesisData --
    83  func (f *FaultyMockPOWChain) ClearPreGenesisData() {
    84  	// no-op
    85  }
    86  
    87  // IsConnectedToETH1 --
    88  func (f *FaultyMockPOWChain) IsConnectedToETH1() bool {
    89  	return true
    90  }
    91  
    92  // BlockExistsWithCache --
    93  func (f *FaultyMockPOWChain) BlockExistsWithCache(ctx context.Context, hash common.Hash) (bool, *big.Int, error) {
    94  	return f.BlockExists(ctx, hash)
    95  }