github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/app/core/chain_test.go (about)

     1  package core
     2  
     3  // NOTE: A bulk of these unit tests will change and evolve as the context and
     4  // implementation of ChainConext evolves.
     5  
     6  import (
     7  	"math/big"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  
    12  	ethcmn "github.com/ethereum/go-ethereum/common"
    13  	ethcons "github.com/ethereum/go-ethereum/consensus"
    14  	ethcore "github.com/ethereum/go-ethereum/core"
    15  	ethtypes "github.com/ethereum/go-ethereum/core/types"
    16  )
    17  
    18  func TestChainContextInterface(t *testing.T) {
    19  	require.Implements(t, (*ethcore.ChainContext)(nil), new(ChainContext))
    20  	require.Implements(t, (*ethcons.Engine)(nil), new(ChainContext))
    21  }
    22  
    23  func TestNewChainContext(t *testing.T) {
    24  	cc := NewChainContext()
    25  	require.NotNil(t, cc.headersByNumber)
    26  }
    27  
    28  func TestChainContextEngine(t *testing.T) {
    29  	cc := NewChainContext()
    30  	require.Equal(t, cc, cc.Engine())
    31  }
    32  
    33  func TestChainContextSetHeader(t *testing.T) {
    34  	cc := NewChainContext()
    35  	header := &ethtypes.Header{
    36  		Number: big.NewInt(64),
    37  	}
    38  
    39  	cc.SetHeader(uint64(header.Number.Int64()), header)
    40  	require.Equal(t, header, cc.headersByNumber[uint64(header.Number.Int64())])
    41  }
    42  
    43  func TestChainContextGetHeader(t *testing.T) {
    44  	cc := NewChainContext()
    45  	header := &ethtypes.Header{
    46  		Number: big.NewInt(64),
    47  	}
    48  
    49  	cc.SetHeader(uint64(header.Number.Int64()), header)
    50  	require.Equal(t, header, cc.GetHeader(ethcmn.Hash{}, uint64(header.Number.Int64())))
    51  	require.Nil(t, cc.GetHeader(ethcmn.Hash{}, 0))
    52  }
    53  
    54  func TestChainContextAuthor(t *testing.T) {
    55  	cc := NewChainContext()
    56  
    57  	cb, err := cc.Author(nil)
    58  	require.Nil(t, err)
    59  	require.Equal(t, cc.Coinbase, cb)
    60  }
    61  
    62  func TestChainContextAPIs(t *testing.T) {
    63  	cc := NewChainContext()
    64  	require.Nil(t, cc.APIs(nil))
    65  }
    66  
    67  func TestChainContextCalcDifficulty(t *testing.T) {
    68  	cc := NewChainContext()
    69  	require.Nil(t, cc.CalcDifficulty(nil, 0, nil))
    70  }
    71  
    72  func TestChainContextFinalize(t *testing.T) {
    73  	cc := NewChainContext()
    74  
    75  	cc.Finalize(nil, nil, nil, nil, nil)
    76  }
    77  
    78  func TestChainContextPrepare(t *testing.T) {
    79  	cc := NewChainContext()
    80  
    81  	err := cc.Prepare(nil, nil)
    82  	require.Nil(t, err)
    83  }
    84  
    85  func TestChainContextSeal(t *testing.T) {
    86  	cc := NewChainContext()
    87  
    88  	err := cc.Seal(nil, nil, nil, nil)
    89  	require.Nil(t, err)
    90  }
    91  
    92  func TestChainContextVerifyHeader(t *testing.T) {
    93  	cc := NewChainContext()
    94  
    95  	err := cc.VerifyHeader(nil, nil, false)
    96  	require.Nil(t, err)
    97  }
    98  
    99  func TestChainContextVerifyHeaders(t *testing.T) {
   100  	cc := NewChainContext()
   101  
   102  	ch, err := cc.VerifyHeaders(nil, nil, []bool{false})
   103  	require.Nil(t, err)
   104  	require.Nil(t, ch)
   105  }
   106  
   107  func TestChainContextVerifySeal(t *testing.T) {
   108  	cc := NewChainContext()
   109  
   110  	err := cc.VerifySeal(nil, nil)
   111  	require.Nil(t, err)
   112  }
   113  
   114  func TestChainContextVerifyUncles(t *testing.T) {
   115  	cc := NewChainContext()
   116  
   117  	err := cc.VerifyUncles(nil, nil)
   118  	require.Nil(t, err)
   119  }