forked from dymensionxyz/dymint
/
testutils.go
46 lines (39 loc) · 1.36 KB
/
testutils.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
package node
import (
"context"
"crypto/rand"
"encoding/hex"
"time"
"github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
)
func CreateNode(isAggregator bool, blockManagerConfig *config.BlockManagerConfig) (*Node, error) {
app := testutil.GetAppMock()
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, pubkey, _ := crypto.GenerateEd25519Key(rand.Reader)
pubkeyBytes, _ := pubkey.Raw()
// Node config
nodeConfig := config.DefaultNodeConfig
if blockManagerConfig == nil {
blockManagerConfig = &config.BlockManagerConfig{
BlockBatchSize: 1,
BlockTime: 100 * time.Millisecond,
BatchSubmitMaxTime: 60 * time.Second,
BlockBatchMaxSizeBytes: 1000,
}
}
nodeConfig.BlockManagerConfig = *blockManagerConfig
nodeConfig.Aggregator = isAggregator
// SL config
nodeConfig.SettlementConfig = settlement.Config{ProposerPubKey: hex.EncodeToString(pubkeyBytes)}
node, err := NewNode(context.Background(), nodeConfig, key, signingKey, proxy.NewLocalClientCreator(app), &types.GenesisDoc{ChainID: "test"}, log.TestingLogger(), nil)
if err != nil {
return nil, err
}
return node, nil
}