Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Flakey DKG Tests #1432

Merged
merged 6 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions integration/dkg/dkg_client_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
dkgmod "github.com/onflow/flow-go/module/dkg"
)

var errClientDisabled = fmt.Errorf("dkg client artifically disabled for tests")

// DKGClientWrapper implements the DKGContractClient interface , and provides a
// mechanism to simulate a situations where the DKG node cannot access the DKG
// smart-contract. The client can be disabled so that all requests to the
Expand Down Expand Up @@ -59,23 +61,23 @@ func (c *DKGClientWrapper) WaitForSealed(ctx context.Context, txID sdk.Identifie
// Broadcast implements the DKGContractClient interface
func (c *DKGClientWrapper) Broadcast(msg model.BroadcastDKGMessage) error {
if !c.enabled {
return fmt.Errorf("failed to broadcast DKG message")
return fmt.Errorf("failed to broadcast DKG message: %w", errClientDisabled)
}
return c.client.Broadcast(msg)
}

// ReadBroadcast implements the DKGContractClient interface
func (c *DKGClientWrapper) ReadBroadcast(fromIndex uint, referenceBlock flow.Identifier) ([]messages.BroadcastDKGMessage, error) {
if !c.enabled {
return []messages.BroadcastDKGMessage{}, fmt.Errorf("failed to read DKG broadcast messages")
return []messages.BroadcastDKGMessage{}, fmt.Errorf("failed to read DKG broadcast messages: %w", errClientDisabled)
}
return c.client.ReadBroadcast(fromIndex, referenceBlock)
}

// SubmitResult implements the DKGContractClient interface
func (c *DKGClientWrapper) SubmitResult(groupPubKey crypto.PublicKey, pubKeys []crypto.PublicKey) error {
if !c.enabled {
return fmt.Errorf("failed to submit DKG result")
return fmt.Errorf("failed to submit DKG result: %w", errClientDisabled)
}
return c.client.SubmitResult(groupPubKey, pubKeys)
}
6 changes: 4 additions & 2 deletions integration/dkg/dkg_emulator_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dkg

import (
"fmt"
"github.com/onflow/flow-go/module"
"os"

"github.com/rs/zerolog"
Expand All @@ -20,12 +19,14 @@ import (
sdkcrypto "github.com/onflow/flow-go-sdk/crypto"
sdktemplates "github.com/onflow/flow-go-sdk/templates"
"github.com/onflow/flow-go-sdk/test"

dkgeng "github.com/onflow/flow-go/engine/consensus/dkg"
"github.com/onflow/flow-go/engine/testutil"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/integration/tests/common"
"github.com/onflow/flow-go/model/bootstrap"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/dkg"
emulatormod "github.com/onflow/flow-go/module/emulator"
"github.com/onflow/flow-go/network/stub"
Expand Down Expand Up @@ -309,7 +310,8 @@ func (s *DKGSuite) startDKGWithParticipants(accounts []*nodeAccount) {

// sanity check: verify that DKG was started with correct node IDs
result := s.executeScript(templates.GenerateGetConsensusNodesScript(s.env), nil)
assert.Equal(s.T(), cadence.NewArray(valueNodeIDs), result)
require.IsType(s.T(), cadence.Array{}, result)
assert.ElementsMatch(s.T(), valueNodeIDs, result.(cadence.Array).Values)
}

func (s *DKGSuite) claimDKGParticipant(node *node) {
Expand Down
6 changes: 6 additions & 0 deletions integration/dkg/dkg_emulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func (s *DKGSuite) runTest(goodNodes int, emulatorProblems bool) {
}
}

// before ending the test and awaiting successful completion, ensure we leave
// the dkg client in an enabled state
for _, node := range nodes {
node.dkgContractClient.Enable()
}

for _, n := range nodes {
n.Done()
}
Expand Down