forked from maticnetwork/heimdall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenesis_test.go
84 lines (67 loc) · 2.13 KB
/
genesis_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package checkpoint_test
import (
"math/rand"
"testing"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/maticnetwork/heimdall/app"
"github.com/maticnetwork/heimdall/checkpoint"
"github.com/maticnetwork/heimdall/checkpoint/types"
hmTypes "github.com/maticnetwork/heimdall/types"
"github.com/maticnetwork/heimdall/types/simulation"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type GenesisTestSuite struct {
suite.Suite
app *app.HeimdallApp
ctx sdk.Context
}
// SetupTest setup necessary things for genesis test
func (suite *GenesisTestSuite) SetupTest() {
suite.app, suite.ctx, _ = createTestApp(true)
}
// TestGenesisTestSuite
func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(GenesisTestSuite))
}
func (suite *GenesisTestSuite) TestInitExportGenesis() {
t, app, ctx := suite.T(), suite.app, suite.ctx
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
lastNoACK := simulation.RandIntBetween(r1, 1, 5)
ackCount := simulation.RandIntBetween(r1, 1, 5)
startBlock := uint64(0)
endBlock := uint64(256)
rootHash := hmTypes.HexToHeimdallHash("123")
proposerAddress := hmTypes.HexToHeimdallAddress("123")
timestamp := uint64(time.Now().Unix())
borChainId := "1234"
bufferedCheckpoint := hmTypes.CreateBlock(
startBlock,
endBlock,
rootHash,
proposerAddress,
borChainId,
timestamp,
)
checkpoints := make([]hmTypes.Checkpoint, ackCount)
for i := range checkpoints {
checkpoints[i] = bufferedCheckpoint
}
params := types.DefaultParams()
genesisState := types.NewGenesisState(
params,
&bufferedCheckpoint,
uint64(lastNoACK),
uint64(ackCount),
checkpoints,
)
checkpoint.InitGenesis(ctx, app.CheckpointKeeper, genesisState)
actualParams := checkpoint.ExportGenesis(ctx, app.CheckpointKeeper)
require.Equal(t, genesisState.AckCount, actualParams.AckCount)
require.Equal(t, genesisState.BufferedCheckpoint, actualParams.BufferedCheckpoint)
require.Equal(t, genesisState.LastNoACK, actualParams.LastNoACK)
require.Equal(t, genesisState.Params, actualParams.Params)
require.LessOrEqual(t, len(actualParams.Checkpoints), len(genesisState.Checkpoints))
}