forked from maticnetwork/heimdall
-
Notifications
You must be signed in to change notification settings - Fork 1
/
genesis_test.go
57 lines (46 loc) · 1.5 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
package topup_test
import (
"math/rand"
"strconv"
"testing"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/maticnetwork/heimdall/app"
"github.com/maticnetwork/heimdall/topup"
"github.com/maticnetwork/heimdall/topup/types"
"github.com/maticnetwork/heimdall/types/simulation"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
)
// GenesisTestSuite integrate test suite context object
type GenesisTestSuite struct {
suite.Suite
app *app.HeimdallApp
ctx sdk.Context
}
// SetupTest setup necessary things for genesis test
func (suite *GenesisTestSuite) SetupTest() {
suite.app = app.SetupTopupGenesis()
suite.ctx = suite.app.BaseApp.NewContext(true, abci.Header{})
}
// TestGenesisTestSuite
func TestGenesisTestSuite(t *testing.T) {
suite.Run(t, new(GenesisTestSuite))
}
//TestInitExportGenesis test import and export genesis state
func (suite *GenesisTestSuite) TestInitExportGenesis() {
t, app, ctx := suite.T(), suite.app, suite.ctx
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
topupSequences := make([]string, 5)
for i, _ := range topupSequences {
topupSequences[i] = strconv.Itoa(simulation.RandIntBetween(r1, 1000, 100000))
}
genesisState := types.GenesisState{
TopupSequences: topupSequences,
}
topup.InitGenesis(ctx, app.TopupKeeper, genesisState)
actualParams := topup.ExportGenesis(ctx, app.TopupKeeper)
require.LessOrEqual(t, len(topupSequences), len(actualParams.TopupSequences))
}