Skip to content

Commit

Permalink
e2e: fix TestGouging
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Mar 5, 2024
1 parent 1bed43a commit 7bbafb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions autopilot/autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,30 +815,35 @@ func evaluateConfig(cfg api.AutopilotConfig, cs api.ConsensusState, fee types.Cu

// MaxRPCPrice
tmpGS := maxGS()
tmpGS.MaxRPCPrice = gs.MaxRPCPrice
if optimiseGougingSetting(&tmpGS, &tmpGS.MaxRPCPrice, cfg, cs, fee, currentPeriod, rs, hosts) {
optimisedGS.MaxRPCPrice = tmpGS.MaxRPCPrice
success = true
}
// MaxContractPrice
tmpGS = maxGS()
tmpGS.MaxContractPrice = gs.MaxContractPrice
if optimiseGougingSetting(&tmpGS, &tmpGS.MaxContractPrice, cfg, cs, fee, currentPeriod, rs, hosts) {
optimisedGS.MaxContractPrice = tmpGS.MaxContractPrice
success = true
}
// MaxDownloadPrice
tmpGS = maxGS()
tmpGS.MaxDownloadPrice = gs.MaxDownloadPrice
if optimiseGougingSetting(&tmpGS, &tmpGS.MaxDownloadPrice, cfg, cs, fee, currentPeriod, rs, hosts) {
optimisedGS.MaxDownloadPrice = tmpGS.MaxDownloadPrice
success = true
}
// MaxUploadPrice
tmpGS = maxGS()
tmpGS.MaxUploadPrice = gs.MaxUploadPrice
if optimiseGougingSetting(&tmpGS, &tmpGS.MaxUploadPrice, cfg, cs, fee, currentPeriod, rs, hosts) {
optimisedGS.MaxUploadPrice = tmpGS.MaxUploadPrice
success = true
}
// MaxStoragePrice
tmpGS = maxGS()
tmpGS.MaxStoragePrice = gs.MaxStoragePrice
if optimiseGougingSetting(&tmpGS, &tmpGS.MaxStoragePrice, cfg, cs, fee, currentPeriod, rs, hosts) {
optimisedGS.MaxStoragePrice = tmpGS.MaxStoragePrice
success = true
Expand Down
16 changes: 10 additions & 6 deletions internal/test/e2e/gouging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ func TestGouging(t *testing.T) {
t.Fatal("unexpected data")
}

// update the gouging settings to limit the max storage price to 100H
gs := test.GougingSettings
gs.MaxStoragePrice = types.NewCurrency64(100)
if err := b.UpdateSetting(context.Background(), api.SettingGouging, gs); err != nil {
t.Fatal(err)
}
// fetch current contract set
contracts, err := b.Contracts(context.Background(), api.ContractsOpts{ContractSet: cfg.Set})
tt.OK(err)

// update the host settings so it's gouging
// update one host's settings so it's gouging
hk := contracts[0].HostKey
host := hostsMap[hk.String()]
settings := host.settings.Settings()
settings.IngressPrice = types.Siacoins(1)
settings.EgressPrice = types.Siacoins(1)
settings.ContractPrice = types.Siacoins(11)
settings.StoragePrice = types.NewCurrency64(101) // gouging
tt.OK(host.UpdateSettings(settings))

// make sure the price table expires so the worker is forced to fetch it
Expand All @@ -76,7 +80,7 @@ func TestGouging(t *testing.T) {
// update all host settings so they're gouging
for _, h := range cluster.hosts {
settings := h.settings.Settings()
settings.EgressPrice = types.Siacoins(1)
settings.StoragePrice = types.NewCurrency64(101)
if err := h.UpdateSettings(settings); err != nil {
t.Fatal(err)
}
Expand All @@ -93,7 +97,7 @@ func TestGouging(t *testing.T) {
}

// try optimising gouging settings
resp, err := cluster.Autopilot.EvaluateConfig(context.Background(), test.AutopilotConfig, test.GougingSettings, test.RedundancySettings)
resp, err := cluster.Autopilot.EvaluateConfig(context.Background(), test.AutopilotConfig, gs, test.RedundancySettings)
tt.OK(err)
if resp.Recommendation == nil {
t.Fatal("expected recommendation")
Expand Down

0 comments on commit 7bbafb0

Please sign in to comment.