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

Commit

Permalink
feat: enable setting fresh and latest via config (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetrun5 committed Feb 2, 2023
1 parent 587da11 commit e65c87a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
21 changes: 15 additions & 6 deletions config/chain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type GeneralChainConfig struct {
Id *uint8 `mapstructure:"id"`
Endpoint string `mapstructure:"endpoint"`
Type string `mapstructure:"type"`
BlockstorePath string `mapstructure:"blockstorePath"`
FreshStart bool `mapstructure:"fresh"`
LatestBlock bool `mapstructure:"latest"`
Key string
Insecure bool
BlockstorePath string
FreshStart bool
LatestBlock bool
}

func (c *GeneralChainConfig) Validate() error {
Expand All @@ -34,7 +34,16 @@ func (c *GeneralChainConfig) Validate() error {
}

func (c *GeneralChainConfig) ParseFlags() {
c.BlockstorePath = viper.GetString(flags.BlockstoreFlagName)
c.FreshStart = viper.GetBool(flags.FreshStartFlagName)
c.LatestBlock = viper.GetBool(flags.LatestBlockFlagName)
blockstore := viper.GetString(flags.BlockstoreFlagName)
if blockstore != "" {
c.BlockstorePath = blockstore
}
freshStart := viper.GetBool(flags.FreshStartFlagName)
if freshStart {
c.FreshStart = freshStart
}
latestBlock := viper.GetBool(flags.LatestBlockFlagName)
if latestBlock {
c.LatestBlock = latestBlock
}
}
27 changes: 14 additions & 13 deletions config/chain/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ func TestRunNewEVMConfigTestSuite(t *testing.T) {
suite.Run(t, new(NewEVMConfigTestSuite))
}

func (s *NewEVMConfigTestSuite) SetupSuite() {}
func (s *NewEVMConfigTestSuite) TearDownSuite() {}
func (s *NewEVMConfigTestSuite) SetupTest() {}
func (s *NewEVMConfigTestSuite) TearDownTest() {}

func (s *NewEVMConfigTestSuite) Test_FailedDecode() {
_, err := chain.NewEVMConfig(map[string]interface{}{
"gasLimit": "invalid",
Expand Down Expand Up @@ -63,11 +58,14 @@ func (s *NewEVMConfigTestSuite) Test_InvalidBlockConfirmation() {

func (s *NewEVMConfigTestSuite) Test_ValidConfig() {
rawConfig := map[string]interface{}{
"id": 1,
"endpoint": "ws://domain.com",
"name": "evm1",
"from": "address",
"bridge": "bridgeAddress",
"id": 1,
"endpoint": "ws://domain.com",
"name": "evm1",
"from": "address",
"bridge": "bridgeAddress",
"blockstorePath": "./blockstore",
"latest": true,
"fresh": true,
}

actualConfig, err := chain.NewEVMConfig(rawConfig)
Expand All @@ -77,9 +75,12 @@ func (s *NewEVMConfigTestSuite) Test_ValidConfig() {
s.Nil(err)
s.Equal(*actualConfig, chain.EVMConfig{
GeneralChainConfig: chain.GeneralChainConfig{
Name: "evm1",
Endpoint: "ws://domain.com",
Id: id,
Name: "evm1",
Endpoint: "ws://domain.com",
Id: id,
BlockstorePath: "./blockstore",
FreshStart: true,
LatestBlock: true,
},
Bridge: "bridgeAddress",
Erc20Handler: "",
Expand Down

0 comments on commit e65c87a

Please sign in to comment.