Skip to content

Commit

Permalink
feat: validate that DecimalPlaces is not empty in config
Browse files Browse the repository at this point in the history
  • Loading branch information
fkondej committed Oct 18, 2022
1 parent fbd4def commit da844ea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func (cfg *Config) CheckConfig() error {
if len(bot.MarketProposalConfig.Description) == 0 {
return fmt.Errorf("%s: %s", errors.ErrMissingEmptyConfigSection.Error(), "bots.marketProposalConfig.description")
}
if bot.MarketProposalConfig.DecimalPlaces == nil {
return fmt.Errorf("%s: %s", errors.ErrMissingEmptyConfigSection.Error(), "bots.marketProposalConfig.decimalPlaces")
}
}

return nil
Expand Down Expand Up @@ -200,6 +203,6 @@ type MarketProposalConfig struct {
Name string `yaml:"name"`
Title string `yaml:"title"`
Description string `yaml:"description"`
DecimalPlaces uint64 `yaml:"decimalPlaces"`
DecimalPlaces *uint64 `yaml:"decimalPlaces,omitempty"`
Metadata []string `yaml:"metadata"`
}
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestCheckConfig(t *testing.T) {
cfg.Bots = []config.BotConfig{}
err = cfg.CheckConfig()
assert.True(t, strings.HasPrefix(err.Error(), errors.ErrMissingEmptyConfigSection.Error()))
decimalPlaces := uint64(18)

botConfig := config.BotConfig{
Name: "test",
Expand All @@ -60,7 +61,7 @@ func TestCheckConfig(t *testing.T) {
Name: "Apple Monthly (Feb 2024)",
Title: "New USD market",
Description: "New USD market",
DecimalPlaces: 18,
DecimalPlaces: &decimalPlaces,
Metadata: []string{
"class:equities/single-stock-futures",
"sector:tech",
Expand Down
2 changes: 1 addition & 1 deletion market/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (m *Service) sendNewMarketProposal(ctx context.Context) error {
InstrumentCode: m.config.MarketProposalConfig.InstrumentCode,
DataSubmitterPubKey: m.config.MarketProposalConfig.DataSubmitterPubKey,
SettlementVegaAssetId: m.config.SettlementAssetID,
DecimalPlaces: m.config.MarketProposalConfig.DecimalPlaces,
DecimalPlaces: *m.config.MarketProposalConfig.DecimalPlaces,
ExtraMetadata: m.config.MarketProposalConfig.Metadata,
ClosingTime: time.Now().Add(time.Second * 20).Add(proposalParams.MinClose),
EnactmentTime: time.Now().Add(time.Second * 30).Add(proposalParams.MinClose).Add(proposalParams.MinEnact),
Expand Down

0 comments on commit da844ea

Please sign in to comment.