forked from loomnetwork/loomchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_test.go
69 lines (62 loc) · 1.95 KB
/
app_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
package loomchain
import (
"context"
"testing"
"time"
cctypes "github.com/loomnetwork/go-loom/builtin/types/chainconfig"
"github.com/loomnetwork/loomchain/db"
"github.com/loomnetwork/loomchain/store"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
)
var (
blockHeight = int64(34)
blockTime = time.Unix(123456789, 0)
)
func TestOnChainConfig(t *testing.T) {
kvStore, err := mockMultiWriterStore(10)
require.NoError(t, err)
// This is the first version of on chain-config
originalConfig := &cctypes.Config{
AppStore: &cctypes.AppStoreConfig{
NumEvmKeysToPrune: 777,
IAVLFlushInterval: 50,
},
}
require.NoError(t, store.SaveOnChainConfig(kvStore, originalConfig))
curCfg, err := store.LoadOnChainConfig(kvStore)
require.NoError(t, err)
header := abci.Header{
Height: blockHeight,
Time: blockTime,
}
state := NewStoreState(
context.Background(), kvStore, header, nil, nil,
).WithOnChainConfig(curCfg)
// check default config
require.Equal(t, uint64(777), state.Config().AppStore.NumEvmKeysToPrune)
require.Equal(t, uint64(50), state.Config().AppStore.IAVLFlushInterval)
require.NotNil(t, state.Config().GetEvm())
require.Equal(t, uint64(0), state.Config().GetEvm().GasLimit)
// change config setting
err = state.ChangeConfigSetting("Evm.GasLimit", "5000")
require.NoError(t, err)
// reload config
curCfg, err = store.LoadOnChainConfig(kvStore)
require.NoError(t, err)
require.Equal(t, uint64(5000), state.WithOnChainConfig(curCfg).Config().Evm.GasLimit)
}
func mockMultiWriterStore(flushInterval int64) (*store.MultiWriterAppStore, error) {
memDb, _ := db.LoadMemDB()
iavlStore, err := store.NewIAVLStore(memDb, 0, 0, flushInterval)
if err != nil {
return nil, err
}
memDb, _ = db.LoadMemDB()
evmStore := store.NewEvmStore(memDb, 100)
multiWriterStore, err := store.NewMultiWriterAppStore(iavlStore, evmStore, false)
if err != nil {
return nil, err
}
return multiWriterStore, nil
}