forked from dymensionxyz/dymint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_test.go
136 lines (116 loc) · 3.96 KB
/
node_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
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
125
126
127
128
129
130
131
132
133
134
135
136
package node_test
import (
"context"
"crypto/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/dymensionxyz/dymint/mempool"
"github.com/dymensionxyz/dymint/node"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/testutil"
"github.com/dymensionxyz/dymint/types/pb/dymensionxyz/dymension/rollapp"
"github.com/dymensionxyz/dymint/version"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proxy"
tmcfg "github.com/tendermint/tendermint/config"
"github.com/dymensionxyz/dymint/config"
tmmocks "github.com/dymensionxyz/dymint/mocks/github.com/tendermint/tendermint/abci/types"
)
// simply check that node is starting and stopping without panicking
func TestStartup(t *testing.T) {
version.DRS = "0"
assert := assert.New(t)
require := require.New(t)
// TODO(omritoptix): Test with and without sequencer mode.
node, err := testutil.CreateNode(false, nil, testutil.GenerateGenesis(0))
require.NoError(err)
require.NotNil(node)
assert.False(node.IsRunning())
err = node.Start()
assert.NoError(err)
defer func() {
err := node.Stop()
assert.NoError(err)
}()
assert.True(node.IsRunning())
}
func TestMempoolDirectly(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
app := &tmmocks.MockApplication{}
gbdBz, _ := tmjson.Marshal(rollapp.GenesisBridgeData{})
app.On("InitChain", mock.Anything).Return(abci.ResponseInitChain{GenesisBridgeDataBytes: gbdBz}, nil)
app.On("CheckTx", mock.Anything).Return(abci.ResponseCheckTx{})
app.On("Info", mock.Anything).Return(abci.ResponseInfo{})
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
signingKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
anotherKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
nodeConfig := config.NodeConfig{
RootDir: "",
DBPath: "",
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BootstrapNodes: "",
BlockSyncRequestIntervalTime: 30 * time.Second,
},
RPC: config.RPCConfig{},
MempoolConfig: *tmcfg.DefaultMempoolConfig(),
BlockManagerConfig: config.BlockManagerConfig{
BlockTime: 1 * time.Second,
BatchSubmitTime: 60 * time.Second,
BatchSubmitBytes: 100000,
MaxSkewTime: 24 * 7 * time.Hour,
SequencerSetUpdateInterval: config.DefaultSequencerSetUpdateInterval,
},
DAConfig: "",
SettlementLayer: "mock",
SettlementConfig: settlement.Config{},
}
node, err := node.NewNode(
context.Background(),
nodeConfig,
key,
signingKey,
proxy.NewLocalClientCreator(app),
testutil.GenerateGenesis(0),
"",
log.TestingLogger(),
mempool.NopMetrics(),
)
require.NoError(err)
require.NotNil(node)
err = node.Start()
require.NoError(err)
pid, err := peer.IDFromPrivateKey(anotherKey)
require.NoError(err)
err = node.Mempool.CheckTx([]byte("tx1"), func(r *abci.Response) {}, mempool.TxInfo{
SenderID: node.MempoolIDs.GetForPeer(pid),
})
require.NoError(err)
err = node.Mempool.CheckTx([]byte("tx2"), func(r *abci.Response) {}, mempool.TxInfo{
SenderID: node.MempoolIDs.GetForPeer(pid),
})
require.NoError(err)
time.Sleep(100 * time.Millisecond)
err = node.Mempool.CheckTx([]byte("tx3"), func(r *abci.Response) {}, mempool.TxInfo{
SenderID: node.MempoolIDs.GetForPeer(pid),
})
require.NoError(err)
err = node.Mempool.CheckTx([]byte("tx4"), func(r *abci.Response) {}, mempool.TxInfo{
SenderID: node.MempoolIDs.GetForPeer(pid),
})
require.NoError(err)
time.Sleep(1 * time.Second)
assert.Equal(int64(4*len("tx*")), node.Mempool.SizeBytes())
err = node.Stop()
require.NoError(err)
}