github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/model/messages/convert_test.go (about)

     1  package messages_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/onflow/flow-go/model/cluster"
     9  	"github.com/onflow/flow-go/model/messages"
    10  	"github.com/onflow/flow-go/utils/unittest"
    11  )
    12  
    13  func TestBlockProposal(t *testing.T) {
    14  	block := unittest.FullBlockFixture()
    15  	proposal := messages.NewBlockProposal(&block)
    16  	converted := proposal.Block.ToInternal()
    17  	assert.Equal(t, &block, converted)
    18  }
    19  
    20  func TestClusterBlockProposal(t *testing.T) {
    21  	block := unittest.ClusterBlockFixture()
    22  	proposal := messages.NewClusterBlockProposal(&block)
    23  	converted := proposal.Block.ToInternal()
    24  	assert.Equal(t, &block, converted)
    25  }
    26  
    27  func TestBlockResponse(t *testing.T) {
    28  	expected := unittest.BlockFixtures(2)
    29  	res := messages.BlockResponse{
    30  		Blocks: []messages.UntrustedBlock{
    31  			messages.UntrustedBlockFromInternal(expected[0]),
    32  			messages.UntrustedBlockFromInternal(expected[1]),
    33  		},
    34  	}
    35  	converted := res.BlocksInternal()
    36  	assert.Equal(t, expected, converted)
    37  }
    38  
    39  func TestClusterBlockResponse(t *testing.T) {
    40  	b1 := unittest.ClusterBlockFixture()
    41  	b2 := unittest.ClusterBlockFixture()
    42  	expected := []*cluster.Block{&b1, &b2}
    43  	res := messages.ClusterBlockResponse{
    44  		Blocks: []messages.UntrustedClusterBlock{
    45  			messages.UntrustedClusterBlockFromInternal(expected[0]),
    46  			messages.UntrustedClusterBlockFromInternal(expected[1]),
    47  		},
    48  	}
    49  	converted := res.BlocksInternal()
    50  	assert.Equal(t, expected, converted)
    51  }