-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathminiblocks_test.go
More file actions
124 lines (107 loc) · 3.64 KB
/
miniblocks_test.go
File metadata and controls
124 lines (107 loc) · 3.64 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//go:build integrationtests
package integrationtests
import (
"context"
"testing"
dataBlock "github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/marshal"
indexerdata "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer"
"github.com/stretchr/testify/require"
)
func TestIndexMiniBlocksOnSourceAndDestination(t *testing.T) {
setLogLevelDebug()
esClient, err := createESClient(esURL)
require.Nil(t, err)
esProc, err := CreateElasticProcessor(esClient)
require.Nil(t, err)
// index on the source shard
header := &dataBlock.Header{
ShardID: 1,
TimeStamp: 1234,
}
miniBlocks := []*dataBlock.MiniBlock{
{
SenderShardID: 1,
ReceiverShardID: 2,
},
}
err = esProc.SaveMiniblocks(header, miniBlocks, 1234000)
require.Nil(t, err)
mbHash := "11a1bb4065e16a2e93b2b5ac5957b7b69f1cfba7579b170b24f30dab2d3162e0"
ids := []string{mbHash}
genericResponse := &GenericResponse{}
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.MiniblocksIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/miniblocks/cross-miniblock-on-source.json"), string(genericResponse.Docs[0].Source))
// index on the destination shard
mbhr := &dataBlock.MiniBlockHeaderReserved{
ExecutionType: dataBlock.ProcessingType(1),
}
marshaller := &marshal.GogoProtoMarshalizer{}
mbhrBytes, _ := marshaller.Marshal(mbhr)
header = &dataBlock.Header{
ShardID: 2,
TimeStamp: 1234,
MiniBlockHeaders: []dataBlock.MiniBlockHeader{
{
Reserved: mbhrBytes,
},
},
}
err = esProc.SaveMiniblocks(header, miniBlocks, 1234000)
require.Nil(t, err)
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.MiniblocksIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/miniblocks/cross-miniblock-on-destination.json"), string(genericResponse.Docs[0].Source))
}
func TestIndexMiniBlockFirstOnDestinationAndAfterSource(t *testing.T) {
setLogLevelDebug()
esClient, err := createESClient(esURL)
require.Nil(t, err)
esProc, err := CreateElasticProcessor(esClient)
require.Nil(t, err)
// index on destination
mbhr := &dataBlock.MiniBlockHeaderReserved{
ExecutionType: dataBlock.ProcessingType(2),
}
marshaller := &marshal.GogoProtoMarshalizer{}
mbhrBytes, _ := marshaller.Marshal(mbhr)
header := &dataBlock.Header{
ShardID: 0,
TimeStamp: 54321,
MiniBlockHeaders: []dataBlock.MiniBlockHeader{
{
Reserved: mbhrBytes,
},
},
}
miniBlocks := []*dataBlock.MiniBlock{
{
SenderShardID: 2,
ReceiverShardID: 0,
},
}
err = esProc.SaveMiniblocks(header, miniBlocks, 54321000)
require.Nil(t, err)
genericResponse := &GenericResponse{}
ids := []string{"2f3ee0ff3b6426916df3b123a10f425b7e2027e2ae8d231229d27b12aa522ade"}
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.MiniblocksIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/miniblocks/cross-miniblock-on-destination-first.json"), string(genericResponse.Docs[0].Source))
// index on source
mbhr = &dataBlock.MiniBlockHeaderReserved{
ExecutionType: dataBlock.ProcessingType(0),
}
mbhrBytes, _ = marshaller.Marshal(mbhr)
header.ShardID = 2
header.MiniBlockHeaders = []dataBlock.MiniBlockHeader{
{
Reserved: mbhrBytes,
},
}
err = esProc.SaveMiniblocks(header, miniBlocks, 54321000)
require.Nil(t, err)
err = esClient.DoMultiGet(context.Background(), ids, indexerdata.MiniblocksIndex, true, genericResponse)
require.Nil(t, err)
require.JSONEq(t, readExpectedResult("./testdata/miniblocks/cross-miniblock-on-source-second.json"), string(genericResponse.Docs[0].Source))
}