Skip to content

Commit

Permalink
Fixed compilation and implementation issues with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
durkmurder committed Oct 4, 2023
1 parent 23cec18 commit 38ffeee
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
14 changes: 7 additions & 7 deletions engine/collection/ingest/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (suite *Suite) SetupTest() {
return herocache.NewTransactions(1000, log, metrics)
})

assignments := unittest.ClusterAssignment(suite.N_CLUSTERS, collectors)
suite.clusters, err = factory.NewClusterList(assignments, collectors)
assignments := unittest.ClusterAssignment(suite.N_CLUSTERS, collectors.ToSkeleton())
suite.clusters, err = factory.NewClusterList(assignments, collectors.ToSkeleton())
suite.Require().NoError(err)

suite.root = unittest.GenesisFixture()
Expand Down Expand Up @@ -352,7 +352,7 @@ func (suite *Suite) TestRoutingToRemoteClusterWithNoNodes() {
suite.Require().True(ok)

// set the next cluster to be empty
emptyIdentityList := flow.IdentityList{}
emptyIdentityList := flow.IdentitySkeletonList{}
nextClusterIndex := (index + 1) % suite.N_CLUSTERS
suite.clusters[nextClusterIndex] = emptyIdentityList

Expand Down Expand Up @@ -384,7 +384,7 @@ func (suite *Suite) TestRoutingLocalClusterFromOtherNode() {
suite.Require().True(ok)

// another node will send us the transaction
sender := local.Filter(filter.Not(filter.HasNodeID[flow.Identity](suite.me.NodeID())))[0]
sender := local.Filter(filter.Not(filter.HasNodeID[flow.IdentitySkeleton](suite.me.NodeID())))[0]

// get a transaction that will be routed to local cluster
tx := unittest.TransactionBodyFixture()
Expand Down Expand Up @@ -476,7 +476,7 @@ func (suite *Suite) TestRouting_ClusterAssignmentRemoved() {
// remove ourselves from the cluster assignment for epoch 2
withoutMe := suite.identities.
Filter(filter.Not(filter.HasNodeID[flow.Identity](suite.me.NodeID()))).
Filter(filter.HasRole[flow.Identity](flow.RoleCollection))
Filter(filter.HasRole[flow.Identity](flow.RoleCollection)).ToSkeleton()
epoch2Assignment := unittest.ClusterAssignment(suite.N_CLUSTERS, withoutMe)
epoch2Clusters, err := factory.NewClusterList(epoch2Assignment, withoutMe)
suite.Require().NoError(err)
Expand Down Expand Up @@ -515,7 +515,7 @@ func (suite *Suite) TestRouting_ClusterAssignmentAdded() {
// remove ourselves from the cluster assignment for epoch 2
withoutMe := suite.identities.
Filter(filter.Not(filter.HasNodeID[flow.Identity](suite.me.NodeID()))).
Filter(filter.HasRole[flow.Identity](flow.RoleCollection))
Filter(filter.HasRole[flow.Identity](flow.RoleCollection)).ToSkeleton()
epoch2Assignment := unittest.ClusterAssignment(suite.N_CLUSTERS, withoutMe)
epoch2Clusters, err := factory.NewClusterList(epoch2Assignment, withoutMe)
suite.Require().NoError(err)
Expand Down Expand Up @@ -544,7 +544,7 @@ func (suite *Suite) TestRouting_ClusterAssignmentAdded() {
// EPOCH 3:

// include ourselves in cluster assignment
withMe := suite.identities.Filter(filter.HasRole[flow.Identity](flow.RoleCollection))
withMe := suite.identities.Filter(filter.HasRole[flow.Identity](flow.RoleCollection)).ToSkeleton()
epoch3Assignment := unittest.ClusterAssignment(suite.N_CLUSTERS, withMe)
epoch3Clusters, err := factory.NewClusterList(epoch3Assignment, withMe)
suite.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion engine/consensus/ingestion/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (suite *IngestionCoreSuite) SetupTest() {
)
ref.On("Epochs").Return(suite.query)
suite.query.On("Current").Return(suite.epoch)
cluster.On("Members").Return(suite.clusterMembers)
cluster.On("Members").Return(suite.clusterMembers.ToSkeleton())
suite.epoch.On("ClusterByChainID", mock.Anything).Return(
func(chainID flow.ChainID) protocol.Cluster {
if chainID == suite.clusterID {
Expand Down
26 changes: 21 additions & 5 deletions storage/badger/protocol_state_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package badger

import (
"github.com/onflow/flow-go/model/flow/mapfunc"
"testing"

"github.com/dgraph-io/badger/v2"
Expand Down Expand Up @@ -107,6 +108,8 @@ func TestProtocolStateMergeParticipants(t *testing.T) {
nodeID := stateEntry.CurrentEpochSetup.Participants[1].NodeID
stateEntry.CurrentEpochSetup.Participants[1].Address = newAddress
stateEntry.CurrentEpoch.SetupID = stateEntry.CurrentEpochSetup.ID()
identity, _ := stateEntry.CurrentEpochIdentityTable.ByNodeID(nodeID)
identity.Address = newAddress
protocolStateID := stateEntry.ID()

// store protocol state and auxiliary info
Expand Down Expand Up @@ -201,15 +204,28 @@ func assertRichProtocolStateValidity(t *testing.T, state *flow.RichProtocolState
assert.Equal(t, state.PreviousEpochSetup.ID(), state.ProtocolStateEntry.PreviousEpochEventIDs.SetupID, "epoch setup should be for correct event ID")
assert.Equal(t, state.PreviousEpochCommit.ID(), state.ProtocolStateEntry.PreviousEpochEventIDs.CommitID, "epoch commit should be for correct event ID")

previousEpochParticipants = state.PreviousEpochSetup.Participants
for _, participant := range state.PreviousEpochSetup.Participants {
if identity, found := state.CurrentEpochIdentityTable.ByNodeID(participant.NodeID); found {
previousEpochParticipants = append(previousEpochParticipants, identity)
}
}
}

participantsFromCurrentEpochSetup := state.CurrentEpochIdentityTable.Filter(func(i *flow.Identity) bool {
_, exists := state.CurrentEpochSetup.Participants.ByNodeID(i.NodeID)
return exists
})

// invariant: Identities is a full identity table for the current epoch. Identities are sorted in canonical order. Without duplicates. Never nil.
var allIdentities flow.IdentityList
var allIdentities, participantsFromNextEpochSetup flow.IdentityList
if state.NextEpoch != nil {
allIdentities = state.CurrentEpochSetup.Participants.Union(state.NextEpochSetup.Participants)
participantsFromNextEpochSetup = state.NextEpochIdentityTable.Filter(func(i *flow.Identity) bool {
_, exists := state.NextEpochSetup.Participants.ByNodeID(i.NodeID)
return exists
})
allIdentities = participantsFromCurrentEpochSetup.Union(participantsFromNextEpochSetup.Map(mapfunc.WithWeight(0)))
} else {
allIdentities = state.CurrentEpochSetup.Participants.Union(previousEpochParticipants)
allIdentities = participantsFromCurrentEpochSetup.Union(previousEpochParticipants.Map(mapfunc.WithWeight(0)))
}

assert.Equal(t, allIdentities, state.CurrentEpochIdentityTable, "identities should be a full identity table for the current epoch, without duplicates")
Expand All @@ -230,7 +246,7 @@ func assertRichProtocolStateValidity(t *testing.T, state *flow.RichProtocolState
assert.Equal(t, state.NextEpochCommit.ID(), nextEpoch.CommitID, "epoch commit should be for correct event ID")

// invariant: Identities is a full identity table for the current epoch. Identities are sorted in canonical order. Without duplicates. Never nil.
allIdentities = state.NextEpochSetup.Participants.Union(state.CurrentEpochSetup.Participants)
allIdentities = participantsFromNextEpochSetup.Union(participantsFromCurrentEpochSetup.Map(mapfunc.WithWeight(0)))

assert.Equal(t, allIdentities, state.NextEpochIdentityTable, "identities should be a full identity table for the next epoch, without duplicates")
}
6 changes: 6 additions & 0 deletions utils/unittest/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,12 @@ func ProtocolStateFixture(options ...func(*flow.RichProtocolStateEntry)) *flow.R
},
})
}
allIdentities = allIdentities.Map(func(identity flow.Identity) flow.Identity {
if _, found := prevEpochSetup.Participants.ByNodeID(identity.NodeID); found {
identity.Weight = 0
}
return identity
})
entry := &flow.RichProtocolStateEntry{
ProtocolStateEntry: &flow.ProtocolStateEntry{
CurrentEpoch: flow.EpochStateContainer{
Expand Down

0 comments on commit 38ffeee

Please sign in to comment.