Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit e65c87a

Browse files
authored
feat: enable setting fresh and latest via config (#327)
1 parent 587da11 commit e65c87a

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

config/chain/config.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ type GeneralChainConfig struct {
1212
Id *uint8 `mapstructure:"id"`
1313
Endpoint string `mapstructure:"endpoint"`
1414
Type string `mapstructure:"type"`
15+
BlockstorePath string `mapstructure:"blockstorePath"`
16+
FreshStart bool `mapstructure:"fresh"`
17+
LatestBlock bool `mapstructure:"latest"`
1518
Key string
1619
Insecure bool
17-
BlockstorePath string
18-
FreshStart bool
19-
LatestBlock bool
2020
}
2121

2222
func (c *GeneralChainConfig) Validate() error {
@@ -34,7 +34,16 @@ func (c *GeneralChainConfig) Validate() error {
3434
}
3535

3636
func (c *GeneralChainConfig) ParseFlags() {
37-
c.BlockstorePath = viper.GetString(flags.BlockstoreFlagName)
38-
c.FreshStart = viper.GetBool(flags.FreshStartFlagName)
39-
c.LatestBlock = viper.GetBool(flags.LatestBlockFlagName)
37+
blockstore := viper.GetString(flags.BlockstoreFlagName)
38+
if blockstore != "" {
39+
c.BlockstorePath = blockstore
40+
}
41+
freshStart := viper.GetBool(flags.FreshStartFlagName)
42+
if freshStart {
43+
c.FreshStart = freshStart
44+
}
45+
latestBlock := viper.GetBool(flags.LatestBlockFlagName)
46+
if latestBlock {
47+
c.LatestBlock = latestBlock
48+
}
4049
}

config/chain/evm_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ func TestRunNewEVMConfigTestSuite(t *testing.T) {
1717
suite.Run(t, new(NewEVMConfigTestSuite))
1818
}
1919

20-
func (s *NewEVMConfigTestSuite) SetupSuite() {}
21-
func (s *NewEVMConfigTestSuite) TearDownSuite() {}
22-
func (s *NewEVMConfigTestSuite) SetupTest() {}
23-
func (s *NewEVMConfigTestSuite) TearDownTest() {}
24-
2520
func (s *NewEVMConfigTestSuite) Test_FailedDecode() {
2621
_, err := chain.NewEVMConfig(map[string]interface{}{
2722
"gasLimit": "invalid",
@@ -63,11 +58,14 @@ func (s *NewEVMConfigTestSuite) Test_InvalidBlockConfirmation() {
6358

6459
func (s *NewEVMConfigTestSuite) Test_ValidConfig() {
6560
rawConfig := map[string]interface{}{
66-
"id": 1,
67-
"endpoint": "ws://domain.com",
68-
"name": "evm1",
69-
"from": "address",
70-
"bridge": "bridgeAddress",
61+
"id": 1,
62+
"endpoint": "ws://domain.com",
63+
"name": "evm1",
64+
"from": "address",
65+
"bridge": "bridgeAddress",
66+
"blockstorePath": "./blockstore",
67+
"latest": true,
68+
"fresh": true,
7169
}
7270

7371
actualConfig, err := chain.NewEVMConfig(rawConfig)
@@ -77,9 +75,12 @@ func (s *NewEVMConfigTestSuite) Test_ValidConfig() {
7775
s.Nil(err)
7876
s.Equal(*actualConfig, chain.EVMConfig{
7977
GeneralChainConfig: chain.GeneralChainConfig{
80-
Name: "evm1",
81-
Endpoint: "ws://domain.com",
82-
Id: id,
78+
Name: "evm1",
79+
Endpoint: "ws://domain.com",
80+
Id: id,
81+
BlockstorePath: "./blockstore",
82+
FreshStart: true,
83+
LatestBlock: true,
8384
},
8485
Bridge: "bridgeAddress",
8586
Erc20Handler: "",

0 commit comments

Comments
 (0)