github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/avalanche/vertex/parser_test.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package vertex
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/MetalBlockchain/metalgo/codec"
    12  	"github.com/MetalBlockchain/metalgo/ids"
    13  )
    14  
    15  func TestParseInvalid(t *testing.T) {
    16  	vtxBytes := []byte{1, 2, 3, 4, 5}
    17  	_, err := Parse(vtxBytes)
    18  	require.ErrorIs(t, err, codec.ErrUnknownVersion)
    19  }
    20  
    21  func TestParseValid(t *testing.T) {
    22  	require := require.New(t)
    23  
    24  	chainID := ids.ID{1}
    25  	height := uint64(2)
    26  	parentIDs := []ids.ID{{4}, {5}}
    27  	txs := [][]byte{{6}, {7}}
    28  	vtx, err := Build(
    29  		chainID,
    30  		height,
    31  		parentIDs,
    32  		txs,
    33  	)
    34  	require.NoError(err)
    35  
    36  	vtxBytes := vtx.Bytes()
    37  	parsedVtx, err := Parse(vtxBytes)
    38  	require.NoError(err)
    39  	require.Equal(vtx, parsedVtx)
    40  }