Skip to content

Commit

Permalink
Error returned if group flag needed for dkg but not set (#60)
Browse files Browse the repository at this point in the history
* Error returned if group flag needed for dkg but not set

* Check that we have the right error
  • Loading branch information
PizzaWhisperer authored and nikkolasg committed Aug 8, 2018
1 parent b48350a commit 6be4cc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ func runCmd(c *cli.Context) error {
slog.Print("Starting the dkg first.")
runDkg(c, drand, fs)
} else {
_, errG := fs.LoadGroup()
_, errS := fs.LoadShare()
_, errD := fs.LoadDistPublic()
if errG != nil || errS != nil || errD != nil {
slog.Fatalf("The DKG has not been run before, please provide a group file to do the setup.")
}
slog.Print("No group file given, drand will try to run as a beacon.")
drand, err = core.LoadDrand(fs, conf)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"path"
"strconv"
"strings"
"testing"

"github.com/dedis/drand/core"
Expand Down Expand Up @@ -226,6 +227,22 @@ func TestResetBeacon(t *testing.T) {
/*}*/
}

// TestRunWhitoutGroupfileBeforeDKG tests the behavior of the run command whithout the flag --group-init
// in a situation where the dkg was not ran before ()
func TestRunWhitoutGroupfileBeforeDKG(t *testing.T) {
tmpPath := path.Join(os.TempDir(), "drand")
os.Mkdir(tmpPath, 0777)
defer os.RemoveAll(tmpPath)

//will try to run in beacon mode
cmd := exec.Command("drand", "-c", tmpPath, "run", "--insecure")
out, err := cmd.Output()
expectedErr := "The DKG has not been run before, please provide a group file to do the setup."
output := string(out)
require.Error(t, err)
require.True(t, strings.Contains(output, expectedErr))
}

func TestRunGroupInit(t *testing.T) {
tmpPath := path.Join(os.TempDir(), "drand")
os.Mkdir(tmpPath, 0777)
Expand Down

0 comments on commit 6be4cc8

Please sign in to comment.