github.com/iotexproject/iotex-core@v1.14.1-rc1/blockchain/block/blockstore_test.go (about)

     1  // Copyright (c) 2019 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package block
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/require"
    12  
    13  	"github.com/iotexproject/go-pkgs/hash"
    14  
    15  	"github.com/iotexproject/iotex-core/action"
    16  	"github.com/iotexproject/iotex-core/test/identityset"
    17  	"github.com/iotexproject/iotex-core/testutil"
    18  )
    19  
    20  func TestStoreProto(t *testing.T) {
    21  	require := require.New(t)
    22  	store, err := makeStore()
    23  	require.NoError(err)
    24  
    25  	storeProto := store.ToProto()
    26  
    27  	require.NotNil(storeProto)
    28  	require.Equal(0, len(storeProto.Receipts))
    29  
    30  }
    31  
    32  func makeStore() (*Store, error) {
    33  	receipts := []*action.Receipt{
    34  		{
    35  			BlockHeight: 1,
    36  		},
    37  		{
    38  			BlockHeight: 2,
    39  		},
    40  	}
    41  	nblk, err := NewTestingBuilder().
    42  		SetHeight(1).
    43  		SetPrevBlockHash(hash.ZeroHash256).
    44  		SetTimeStamp(testutil.TimestampNow()).
    45  		SetReceipts(receipts).
    46  		SignAndBuild(identityset.PrivateKey(29))
    47  
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  
    52  	return &Store{
    53  		Block: &nblk,
    54  	}, nil
    55  }