Skip to content

Commit

Permalink
remove fixed beacon id for testing and replace it with an env var
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelm41 committed Oct 22, 2021
1 parent b0b5bde commit bf25abe
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 46 deletions.
18 changes: 9 additions & 9 deletions chain/beacon/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

"github.com/drand/drand/common/constants"

"github.com/drand/drand/common/scheme"

"github.com/drand/drand/chain"
Expand All @@ -30,8 +32,6 @@ import (

// TODO make beacon tests not dependant on key.Scheme

const BeaconIDForTesting = "test_beacon"

// testBeaconServer implements a barebone service to be plugged in a net.DefaultService
type testBeaconServer struct {
disable bool
Expand Down Expand Up @@ -135,7 +135,7 @@ type BeaconTest struct {
}

func NewBeaconTest(t *testing.T, n, thr int, period time.Duration, genesisTime int64, sch scheme.Scheme, beaconID string) *BeaconTest {
prefix, err := os.MkdirTemp(os.TempDir(), "beacon-test")
prefix, err := os.MkdirTemp(os.TempDir(), beaconID)
checkErr(err)
paths := createBoltStores(prefix, n)
shares, commits := dkgShares(t, n, thr)
Expand Down Expand Up @@ -399,9 +399,9 @@ func TestBeaconSync(t *testing.T) {

genesisOffset := 2 * time.Second
genesisTime := clock.NewFakeClock().Now().Add(genesisOffset).Unix()
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

bt := NewBeaconTest(t, n, thr, period, genesisTime, sch, BeaconIDForTesting)
bt := NewBeaconTest(t, n, thr, period, genesisTime, sch, beaconID)
defer bt.CleanUp()

verifier := chain.NewVerifier(sch)
Expand Down Expand Up @@ -478,9 +478,9 @@ func TestBeaconSimple(t *testing.T) {
period := 2 * time.Second

genesisTime := clock.NewFakeClock().Now().Unix() + 2
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

bt := NewBeaconTest(t, n, thr, period, genesisTime, sch, BeaconIDForTesting)
bt := NewBeaconTest(t, n, thr, period, genesisTime, sch, beaconID)
defer bt.CleanUp()

verifier := chain.NewVerifier(sch)
Expand Down Expand Up @@ -539,9 +539,9 @@ func TestBeaconThreshold(t *testing.T) {

offsetGenesis := 2 * time.Second
genesisTime := clock.NewFakeClock().Now().Add(offsetGenesis).Unix()
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

bt := NewBeaconTest(t, n, thr, period, genesisTime, sch, BeaconIDForTesting)
bt := NewBeaconTest(t, n, thr, period, genesisTime, sch, beaconID)
defer func() { go bt.CleanUp() }()

verifier := chain.NewVerifier(sch)
Expand Down
6 changes: 4 additions & 2 deletions core/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"
"time"

"github.com/drand/drand/common/constants"

"github.com/drand/drand/common/scheme"
"github.com/drand/drand/key"
"github.com/drand/drand/protobuf/drand"
Expand Down Expand Up @@ -64,9 +66,9 @@ func TestBroadcastSet(t *testing.T) {

func TestBroadcast(t *testing.T) {
n := 5
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

drands, group, dir, _ := BatchNewDrand(t, n, true, sch, BeaconIDForTesting)
drands, group, dir, _ := BatchNewDrand(t, n, true, sch, beaconID)
defer os.RemoveAll(dir)
defer CloseAllDrands(drands)

Expand Down
6 changes: 4 additions & 2 deletions core/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"os"
"testing"

"github.com/drand/drand/common/constants"

"github.com/drand/drand/common/scheme"
"github.com/stretchr/testify/require"
)

func TestClientPrivate(t *testing.T) {
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

drands, _, dir, _ := BatchNewDrand(t, 1, false, sch, BeaconIDForTesting, WithPrivateRandomness())
drands, _, dir, _ := BatchNewDrand(t, 1, false, sch, beaconID, WithPrivateRandomness())
defer CloseAllDrands(drands)
defer os.RemoveAll(dir)

Expand Down
3 changes: 0 additions & 3 deletions core/constants_test.go

This file was deleted.

62 changes: 32 additions & 30 deletions core/drand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"
"time"

"github.com/drand/drand/common/constants"

"github.com/stretchr/testify/assert"

"github.com/drand/drand/chain"
Expand Down Expand Up @@ -37,9 +39,9 @@ var testDkgTimeout = 2 * time.Second
func TestRunDKG(t *testing.T) {
n := 4
expectedBeaconPeriod := 5 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), expectedBeaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), expectedBeaconPeriod, sch, beaconID)
defer dt.Cleanup()

group := dt.RunDKG()
Expand All @@ -63,9 +65,9 @@ func TestRunDKGLarge(t *testing.T) {

n := 22
expectedBeaconPeriod := 5 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), expectedBeaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), expectedBeaconPeriod, sch, beaconID)
defer dt.Cleanup()

group := dt.RunDKG()
Expand All @@ -85,9 +87,9 @@ func TestRunDKGLarge(t *testing.T) {
func TestDrandDKGFresh(t *testing.T) {
n := 4
beaconPeriod := 1 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), beaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), beaconPeriod, sch, beaconID)
defer dt.Cleanup()

// Run DKG
Expand Down Expand Up @@ -134,9 +136,9 @@ func TestRunDKGBroadcastDeny(t *testing.T) {
n := 4
thr := 3
beaconPeriod := 1 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, thr, beaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, thr, beaconPeriod, sch, beaconID)
defer dt.Cleanup()

// close connection between a pair of nodes
Expand Down Expand Up @@ -169,9 +171,9 @@ func TestRunDKGReshareForce(t *testing.T) {
oldThreshold := 3
timeout := 1 * time.Second
beaconPeriod := 2 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, oldNodes, oldThreshold, beaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, oldNodes, oldThreshold, beaconPeriod, sch, beaconID)
defer dt.Cleanup()

group1 := dt.RunDKG()
Expand Down Expand Up @@ -214,9 +216,9 @@ func TestRunDKGReshareAbsentNode(t *testing.T) {
oldNodes, newNodes := 3, 4
oldThreshold, newThreshold := 2, 3
timeout, beaconPeriod := 1*time.Second, 2*time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, oldNodes, oldThreshold, beaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, oldNodes, oldThreshold, beaconPeriod, sch, beaconID)
defer dt.Cleanup()

group1 := dt.RunDKG()
Expand Down Expand Up @@ -267,9 +269,9 @@ func TestRunDKGReshareTimeout(t *testing.T) {
oldNodes, newNodes, oldThreshold, newThreshold := 3, 4, 2, 3
timeout, beaconPeriod := 1*time.Second, 2*time.Second
offline := 1
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, oldNodes, oldThreshold, beaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, oldNodes, oldThreshold, beaconPeriod, sch, beaconID)
defer dt.Cleanup()

group1 := dt.RunDKG()
Expand Down Expand Up @@ -376,9 +378,9 @@ func TestRunDKGResharePreempt(t *testing.T) {
Thr := 2
timeout := 1 * time.Second
beaconPeriod := 2 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, oldN, Thr, beaconPeriod, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, oldN, Thr, beaconPeriod, sch, beaconID)
defer dt.Cleanup()

group1 := dt.RunDKG()
Expand Down Expand Up @@ -471,9 +473,9 @@ func TestDrandPublicChainInfo(t *testing.T) {
n := 10
thr := key.DefaultThreshold(n)
p := 1 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, thr, p, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, thr, p, sch, beaconID)
defer dt.Cleanup()

group := dt.RunDKG()
Expand Down Expand Up @@ -527,9 +529,9 @@ func TestDrandPublicRand(t *testing.T) {
n := 4
thr := key.DefaultThreshold(n)
p := 1 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, thr, p, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, thr, p, sch, beaconID)
defer dt.Cleanup()

group := dt.RunDKG()
Expand Down Expand Up @@ -592,9 +594,9 @@ func TestDrandPublicStream(t *testing.T) {
n := 4
thr := key.DefaultThreshold(n)
p := 1 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, thr, p, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, thr, p, sch, beaconID)
defer dt.Cleanup()

group := dt.RunDKG()
Expand Down Expand Up @@ -692,9 +694,9 @@ func TestDrandPublicStream(t *testing.T) {
// This test makes sure the "FollowChain" grpc method works fine
func TestDrandFollowChain(t *testing.T) {
n, p := 4, 1*time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), p, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, key.DefaultThreshold(n), p, sch, beaconID)
defer dt.Cleanup()

group := dt.RunDKG()
Expand Down Expand Up @@ -735,7 +737,7 @@ func TestDrandFollowChain(t *testing.T) {
t.Logf("Trying to follow with an invalid address\n")

ctx, cancel = context.WithCancel(context.Background())
_, errCh, _ := newClient.StartFollowChain(ctx, "deadbeef", addrToFollow, tls, 10000, BeaconIDForTesting)
_, errCh, _ := newClient.StartFollowChain(ctx, "deadbeef", addrToFollow, tls, 10000, beaconID)

select {
case <-errCh:
Expand All @@ -745,7 +747,7 @@ func TestDrandFollowChain(t *testing.T) {
panic("should have errored")
}

_, errCh, _ = newClient.StartFollowChain(ctx, "tutu", addrToFollow, tls, 10000, BeaconIDForTesting)
_, errCh, _ = newClient.StartFollowChain(ctx, "tutu", addrToFollow, tls, 10000, beaconID)
select {
case <-errCh:
t.Logf("An error was received as the address is invalid")
Expand All @@ -759,7 +761,7 @@ func TestDrandFollowChain(t *testing.T) {

t.Logf("Starting to follow chain with a valid address\n")
t.Logf("%s", hash)
progress, errCh, err := newClient.StartFollowChain(ctx, hash, addrToFollow, tls, upTo, BeaconIDForTesting)
progress, errCh, err := newClient.StartFollowChain(ctx, hash, addrToFollow, tls, upTo, beaconID)
require.NoError(t, err)

var goon = true
Expand All @@ -785,7 +787,7 @@ func TestDrandFollowChain(t *testing.T) {
cancel()

// check if the beacon is in the database
store, err := newNode.drand.createBoltStore(BeaconIDForTesting)
store, err := newNode.drand.createBoltStore(beaconID)
require.NoError(t, err)
defer store.Close()

Expand All @@ -803,9 +805,9 @@ func TestDrandPublicStreamProxy(t *testing.T) {
n := 4
thr := key.DefaultThreshold(n)
p := 1 * time.Second
sch := scheme.GetSchemeFromEnv()
sch, beaconID := scheme.GetSchemeFromEnv(), constants.GetBeaconIDFromEnv()

dt := NewDrandTestScenario(t, n, thr, p, sch, BeaconIDForTesting)
dt := NewDrandTestScenario(t, n, thr, p, sch, beaconID)
defer dt.Cleanup()

group := dt.RunDKG()
Expand Down

0 comments on commit bf25abe

Please sign in to comment.