lotus/chain/beacon/drand/drand_test.go

48 lines
1.4 KiB
Go
Raw Normal View History

2022-08-29 14:25:30 +00:00
// stm: ignore
// Only tests external library behavior, therefore it should not be annotated
package drand
import (
2023-03-08 17:13:58 +00:00
"context"
"os"
"testing"
dchain "github.com/drand/drand/chain"
hclient "github.com/drand/drand/client/http"
"github.com/stretchr/testify/assert"
2022-06-14 15:00:51 +00:00
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/lotus/build"
)
func TestPrintGroupInfo(t *testing.T) {
server := build.DrandConfigs[build.DrandTestnet].Servers[0]
c, err := hclient.New(server, nil, nil)
assert.NoError(t, err)
cg := c.(interface {
2023-03-08 17:13:58 +00:00
FetchChainInfo(ctx context.Context, groupHash []byte) (*dchain.Info, error)
})
2023-03-08 17:13:58 +00:00
chain, err := cg.FetchChainInfo(context.Background(), nil)
assert.NoError(t, err)
2023-03-08 04:24:48 +00:00
err = chain.ToJSON(os.Stdout, nil)
assert.NoError(t, err)
}
func TestMaxBeaconRoundForEpoch(t *testing.T) {
todayTs := uint64(1652222222)
db, err := NewDrandBeacon(todayTs, build.BlockDelaySecs, nil, build.DrandConfigs[build.DrandTestnet])
assert.NoError(t, err)
assert.True(t, db.IsChained())
mbr15 := db.MaxBeaconRoundForEpoch(network.Version15, 100)
mbr16 := db.MaxBeaconRoundForEpoch(network.Version16, 100)
assert.Equal(t, mbr15+1, mbr16)
}
func TestQuicknetIsChained(t *testing.T) {
todayTs := uint64(1652222222)
db, err := NewDrandBeacon(todayTs, build.BlockDelaySecs, nil, build.DrandConfigs[build.DrandQuicknet])
assert.NoError(t, err)
assert.False(t, db.IsChained())
}