github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/state/protocol/inmem/initial_protocol_state_test.go (about) 1 package inmem_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 9 "github.com/onflow/flow-go/model/flow/filter" 10 "github.com/onflow/flow-go/state/protocol/inmem" 11 "github.com/onflow/flow-go/utils/unittest" 12 ) 13 14 // TestInitialProtocolStateAdapter tests if the InitialProtocolStateAdapter returns expected values when created 15 // using constructor passing a RichProtocolStateEntry. 16 func TestInitialProtocolStateAdapter(t *testing.T) { 17 // construct a valid protocol state entry that has semantically correct DKGParticipantKeys 18 entry := unittest.EpochStateFixture(unittest.WithValidDKG()) 19 20 adapter := inmem.NewInitialProtocolStateAdapter(entry) 21 22 t.Run("clustering", func(t *testing.T) { 23 clustering, err := inmem.ClusteringFromSetupEvent(entry.CurrentEpochSetup) 24 require.NoError(t, err) 25 actual, err := adapter.Clustering() 26 require.NoError(t, err) 27 assert.Equal(t, clustering, actual) 28 }) 29 t.Run("epoch", func(t *testing.T) { 30 assert.Equal(t, entry.CurrentEpochSetup.Counter, adapter.Epoch()) 31 }) 32 t.Run("setup", func(t *testing.T) { 33 assert.Equal(t, entry.CurrentEpochSetup, adapter.EpochSetup()) 34 }) 35 t.Run("commit", func(t *testing.T) { 36 assert.Equal(t, entry.CurrentEpochCommit, adapter.EpochCommit()) 37 }) 38 t.Run("dkg", func(t *testing.T) { 39 dkg, err := adapter.DKG() 40 require.NoError(t, err) 41 assert.Equal(t, entry.CurrentEpochCommit.DKGGroupKey, dkg.GroupKey()) 42 assert.Equal(t, len(entry.CurrentEpochCommit.DKGParticipantKeys), int(dkg.Size())) 43 dkgParticipants := entry.CurrentEpochSetup.Participants.Filter(filter.IsValidDKGParticipant) 44 for _, identity := range dkgParticipants { 45 keyShare, err := dkg.KeyShare(identity.NodeID) 46 require.NoError(t, err) 47 index, err := dkg.Index(identity.NodeID) 48 require.NoError(t, err) 49 assert.Equal(t, entry.CurrentEpochCommit.DKGParticipantKeys[index], keyShare) 50 } 51 }) 52 t.Run("entry", func(t *testing.T) { 53 actualEntry := adapter.Entry() 54 assert.Equal(t, entry, actualEntry, "entry should be equal to the one passed to the constructor") 55 assert.NotSame(t, entry, actualEntry, "entry should be a copy of the one passed to the constructor") 56 }) 57 }