-
Notifications
You must be signed in to change notification settings - Fork 993
/
Copy pathheader_test.go
64 lines (49 loc) · 1.83 KB
/
header_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package core
import (
"context"
"fmt"
"net"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/rand"
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
"github.com/celestiaorg/celestia-node/share"
)
func TestMakeExtendedHeaderForEmptyBlock(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
host, port, err := net.SplitHostPort(StartTestNode(t).GRPCClient.Target())
require.NoError(t, err)
fetcher, err := newTestBlockFetcher(t, host, port)
require.NoError(t, err)
sub, err := fetcher.SubscribeNewBlockEvent(ctx)
require.NoError(t, err)
dataBlock := <-sub
height := dataBlock.Header.Height
b, err := fetcher.GetBlock(ctx, height)
require.NoError(t, err)
comm, val, err := fetcher.GetBlockInfo(ctx, height)
require.NoError(t, err)
eds, err := extendBlock(b.Data, b.Header.Version.App)
require.NoError(t, err)
headerExt, err := header.MakeExtendedHeader(b.Header, comm, val, eds)
require.NoError(t, err)
assert.Equal(t, share.EmptyEDSRoots(), headerExt.DAH)
}
func TestMismatchedDataHash_ComputedRoot(t *testing.T) {
header := headertest.RandExtendedHeader(t)
header.DataHash = rand.Bytes(32)
err := header.Validate()
assert.Contains(t, err.Error(), "mismatch between data hash commitment from"+
" core header and computed data root")
}
func TestBadAppVersion(t *testing.T) {
header := headertest.RandExtendedHeader(t)
header.RawHeader.Version.App = appconsts.LatestVersion + 1
err := header.Validate()
assert.Contains(t, err.Error(), fmt.Sprintf("has version %d, this node supports up to version %d. Please "+
"upgrade to support new version", header.RawHeader.Version.App, appconsts.LatestVersion))
}