Skip to content

Commit

Permalink
Additional config settings (#1530)
Browse files Browse the repository at this point in the history
* Temp commit files with identical content.

* Adding new settings for features and payments.

* Adding new settings for features and payments.

* Revert "Temp commit files with identical content."

This reverts commit f23c28a.

* Fix issues.
  • Loading branch information
irina-pereiaslavskaia authored Nov 6, 2024
1 parent ee55592 commit 5b796a9
Show file tree
Hide file tree
Showing 7 changed files with 598 additions and 107 deletions.
113 changes: 113 additions & 0 deletions itests/config/additional_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package config

import (
"encoding/json"
stderrs "errors"
"os"
"path/filepath"

"github.com/pkg/errors"
)

const (
testdataFolder = "testdata"
)

func readSettingsFromFile(path ...string) (*os.File, error) {
var pwd string
var err error
var f *os.File

pwd, err = os.Getwd()
if err != nil {
return nil, errors.Wrap(err, "could not get current working directory")
}
settingPath := filepath.Join(pwd, filepath.Join(path...))

f, err = os.Open(filepath.Clean(settingPath))
if err != nil {
return nil, errors.Wrap(err, "could not open settings file")
}
return f, nil
}

// PaymentSettings stores parts of genesis configuration related to payments.
// It's used to modify the blockchain settings.
type PaymentSettings struct {
PaymentsFixAfterHeight uint64 `json:"payments_fix_after_height"`
InternalInvokePaymentsValidationAfterHeight uint64 `json:"internal_invoke_payments_validation_after_height"`
InternalInvokeCorrectFailRejectBehaviourAfterHeight uint64 `json:"internal_invoke_correct_fail_reject_behaviour_after_height"` //nolint:lll
InvokeNoZeroPaymentsAfterHeight uint64 `json:"invoke_no_zero_payments_after_height"`
}

// NewPaymentSettingsFromFile reads payment settings from file.
// The `path` is a relative path to the configuration JSON file.
func NewPaymentSettingsFromFile(path ...string) (_ *PaymentSettings, err error) {
f, err := readSettingsFromFile(testdataFolder, filepath.Join(path...))
defer func() {
if cErr := f.Close(); cErr != nil {
err = stderrs.Join(err, errors.Wrapf(cErr, "could not close settings file %q", f.Name()))
}
}()
js := json.NewDecoder(f)
s := &PaymentSettings{}
if jsErr := js.Decode(s); jsErr != nil {
return nil, errors.Wrap(jsErr, "failed to read payment settings")
}
return s, nil
}

// FeatureSettings stores parts of genesis configuration related to features.
// It's used to modify the blockchain settings.
type FeatureSettings struct {
PreactivatedFeatures []FeatureInfo `json:"preactivated_features"`
SupportedFeatures []int16 `json:"supported_features"`
}

// NewFeatureSettingsFromFile reads features settings from file.
// The `path` is a relative path to the configuration JSON file.
func NewFeatureSettingsFromFile(path ...string) (_ *FeatureSettings, err error) {
f, err := readSettingsFromFile(testdataFolder, filepath.Join(path...))
defer func() {
if cErr := f.Close(); cErr != nil {
err = stderrs.Join(err, errors.Wrapf(cErr, "could not close settings file %q", f.Name()))
}
}()
js := json.NewDecoder(f)
s := &FeatureSettings{}
if jsErr := js.Decode(s); jsErr != nil {
return nil, errors.Wrap(jsErr, "failed to read features settings")
}
return s, nil
}

// RewardSettings stores parts of genesis configuration related to rewards.
// It's used to modify the blockchain settings in test on rewards.
type RewardSettings struct {
BlockRewardVotingPeriod uint64 `json:"voting_interval"`
BlockRewardTerm uint64 `json:"term"`
BlockRewardTermAfter20 uint64 `json:"term_after_capped_reward_feature"`
InitialBlockReward uint64 `json:"initial_block_reward"`
BlockRewardIncrement uint64 `json:"block_reward_increment"`
DesiredBlockReward uint64 `json:"desired_reward"`
DaoAddress string `json:"dao_address"`
XtnBuybackAddress string `json:"xtn_buyback_address"`
MinXTNBuyBackPeriod uint64 `json:"min_xtn_buy_back_period"`
}

// NewRewardSettingsFromFile reads reward settings from file.
// The `path` is a relative path to the configuration JSON file inside the project's "rewards_settings_testdata" folder.
func NewRewardSettingsFromFile(path ...string) (_ *RewardSettings, err error) {
f, err := readSettingsFromFile(testdataFolder, filepath.Join(path...))
defer func() {
if cErr := f.Close(); cErr != nil {
err = stderrs.Join(err, errors.Wrapf(cErr, "could not close settings file %q", f.Name()))
}
}()
js := json.NewDecoder(f)
s := &RewardSettings{}
if jsErr := js.Decode(s); jsErr != nil {
return nil, errors.Wrap(jsErr, "failed to read reward settings")
}
return s, nil
}
43 changes: 35 additions & 8 deletions itests/config/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,44 @@ func (c *BlockchainConfig) TestConfig() TestConfig {
}
}

// WithFeatureSettingFromFile is a BlockchainOption that allows to set feature settings from configuration file.
// Feature settings configuration file is a JSON file with the structure of `featureSettings`.
func WithFeatureSettingFromFile(path ...string) BlockchainOption {
return func(cfg *BlockchainConfig) error {
fs, err := NewFeatureSettingsFromFile(path...)
if err != nil {
return errors.Wrap(err, "failed to modify features settings")
}
cfg.supported = fs.SupportedFeatures
if ftErr := cfg.UpdatePreactivatedFeatures(fs.PreactivatedFeatures); ftErr != nil {
return errors.Wrap(ftErr, "failed to modify preactivated features")
}
return nil
}
}

// WithPaymentsSettingFromFile is a BlockchainOption that allows to set payment settings from configuration file.
// Payment settings configuration file is a JSON file with the structure of `paymentSettings`.
func WithPaymentsSettingFromFile(path ...string) BlockchainOption {
return func(cfg *BlockchainConfig) error {
fs, err := NewPaymentSettingsFromFile(path...)
if err != nil {
return errors.Wrap(err, "failed to modify payments settings")
}
cfg.Settings.PaymentsFixAfterHeight = fs.PaymentsFixAfterHeight
cfg.Settings.InternalInvokePaymentsValidationAfterHeight = fs.InternalInvokePaymentsValidationAfterHeight
cfg.Settings.InternalInvokeCorrectFailRejectBehaviourAfterHeight =
fs.InternalInvokeCorrectFailRejectBehaviourAfterHeight
cfg.Settings.InvokeNoZeroPaymentsAfterHeight = fs.InvokeNoZeroPaymentsAfterHeight
return nil
}
}

// WithRewardSettingFromFile is a BlockchainOption that allows to set reward settings from configuration file.
// Reward settings configuration file is a JSON file with the structure of `rewardSettings`.
func WithRewardSettingFromFile(dir, file string) BlockchainOption {
func WithRewardSettingFromFile(path ...string) BlockchainOption {
return func(cfg *BlockchainConfig) error {
rs, err := NewRewardSettingsFromFile(dir, file)
rs, err := NewRewardSettingsFromFile(path...)
if err != nil {
return errors.Wrap(err, "failed to modify reward settings")
}
Expand All @@ -196,13 +229,7 @@ func WithRewardSettingFromFile(dir, file string) BlockchainOption {
cfg.RewardAddresses = ras
cfg.Settings.RewardAddresses = ras.Addresses()
cfg.Settings.RewardAddressesAfter21 = ras.AddressesAfter21()

cfg.supported = rs.SupportedFeatures
cfg.desiredReward = rs.DesiredBlockReward

if ftErr := cfg.UpdatePreactivatedFeatures(rs.PreactivatedFeatures); ftErr != nil {
return errors.Wrap(ftErr, "failed to modify preactivated features")
}
return nil
}
}
Expand Down
60 changes: 0 additions & 60 deletions itests/config/reward.go

This file was deleted.

19 changes: 19 additions & 0 deletions itests/fixtures/lite_node_feature_fixture.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fixtures

import "github.com/wavesplatform/gowaves/itests/config"

const (
baseSettingsConfigFolder = "base_feature_settings"
)

type BaseSettingSuite struct {
BaseSuite
}

func (suite *BaseSettingSuite) SetupSuite() {
suite.BaseSetup(
config.WithScalaMining(),
config.WithFeatureSettingFromFile(baseSettingsConfigFolder, "lite_node_feature_fixture.json"),
config.WithPaymentsSettingFromFile(baseSettingsConfigFolder, "lite_node_feature_fixture.json"),
)
}
Loading

0 comments on commit 5b796a9

Please sign in to comment.