github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/unicast/cache/unicastConfigEntity_test.go (about)

     1  package unicastcache_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  
     8  	"github.com/onflow/flow-go/model/flow"
     9  	"github.com/onflow/flow-go/network/p2p/unicast"
    10  	unicastcache "github.com/onflow/flow-go/network/p2p/unicast/cache"
    11  	"github.com/onflow/flow-go/utils/unittest"
    12  )
    13  
    14  // TestUnicastConfigEntity tests the UnicastConfigEntity struct and its methods.
    15  func TestUnicastConfigEntity(t *testing.T) {
    16  	peerID := unittest.PeerIdFixture(t)
    17  
    18  	d := &unicastcache.UnicastConfigEntity{
    19  		PeerId: peerID,
    20  		Config: unicast.Config{
    21  			StreamCreationRetryAttemptBudget: 20,
    22  			ConsecutiveSuccessfulStream:      30,
    23  		},
    24  		EntityId: flow.MakeID(peerID),
    25  	}
    26  
    27  	t.Run(
    28  		"Test ID and Checksum", func(t *testing.T) {
    29  			// id and checksum methods must return the same value as expected.
    30  			expectedID := flow.MakeID(peerID)
    31  			require.Equal(t, expectedID, d.ID())
    32  			require.Equal(t, expectedID, d.Checksum())
    33  
    34  			// id and checksum methods must always return the same value.
    35  			require.Equal(t, expectedID, d.ID())
    36  			require.Equal(t, expectedID, d.Checksum())
    37  		},
    38  	)
    39  
    40  	t.Run("ID is only calculated from peer.ID", func(t *testing.T) {
    41  		peerId := unittest.PeerIdFixture(t)
    42  		d2 := &unicastcache.UnicastConfigEntity{
    43  			PeerId:   peerId,
    44  			Config:   d.Config,
    45  			EntityId: flow.MakeID(peerId),
    46  		}
    47  		require.NotEqual(t, d.ID(), d2.ID()) // different peer id, different id.
    48  
    49  		d3 := &unicastcache.UnicastConfigEntity{
    50  			PeerId: d.PeerId,
    51  			Config: unicast.Config{
    52  				StreamCreationRetryAttemptBudget: 200,
    53  			},
    54  			EntityId: d.EntityId,
    55  		}
    56  		require.Equal(t, d.ID(), d3.ID()) // same peer id, same id, even though the unicast config is different.
    57  	})
    58  }