Skip to content

Commit

Permalink
testing: add config.go
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Feb 27, 2024
1 parent 990feac commit 9798d64
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 126 deletions.
64 changes: 64 additions & 0 deletions internal/test/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package test

import (
"time"

"github.com/minio/minio-go/v7/pkg/credentials"
rhpv2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
)

var (
// AutopilotConfig is the autopilot used for testing unless a different
// one is explicitly set.
AutopilotConfig = api.AutopilotConfig{
Contracts: api.ContractsConfig{
Allowance: types.Siacoins(1).Mul64(1e3),
Amount: 3,
Period: 144,
RenewWindow: 72,

Download: rhpv2.SectorSize * 500,
Upload: rhpv2.SectorSize * 500,
Storage: rhpv2.SectorSize * 5e3,

Set: ContractSet,
Prune: false,
},
Hosts: api.HostsConfig{
MaxDowntimeHours: 10,
MinRecentScanFailures: 10,
AllowRedundantIPs: true, // allow for integration tests by default
},
}

ContractSet = "testset"
ContractSetSettings = api.ContractSetSetting{
Default: ContractSet,
}

GougingSettings = api.GougingSettings{
MinMaxCollateral: types.Siacoins(10), // at least up to 10 SC per contract
MaxRPCPrice: types.Siacoins(1).Div64(1000), // 1mS per RPC
MaxContractPrice: types.Siacoins(10), // 10 SC per contract
MaxDownloadPrice: types.Siacoins(1).Mul64(1000), // 1000 SC per 1 TiB
MaxUploadPrice: types.Siacoins(1).Mul64(1000), // 1000 SC per 1 TiB
MaxStoragePrice: types.Siacoins(1000).Div64(144 * 30), // 1000 SC per month

HostBlockHeightLeeway: 240, // amount of leeway given to host block height

MinPriceTableValidity: 10 * time.Second, // minimum value for price table validity
MinAccountExpiry: time.Hour, // minimum value for account expiry
MinMaxEphemeralAccountBalance: types.Siacoins(1), // 1SC
}

RedundancySettings = api.RedundancySettings{
MinShards: 2,
TotalShards: 3,
}

S3AccessKeyID = "TESTINGYNHUWCPKOPSYQ"
S3SecretAccessKey = "Rh30BNyj+qNI4ftYRteoZbHJ3X4Ln71QtZkRXzJ9"
S3Credentials = credentials.NewStaticV4(S3AccessKeyID, S3SecretAccessKey, "")
)
9 changes: 5 additions & 4 deletions internal/test/e2e/blocklist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"go.sia.tech/core/types"
"go.sia.tech/renterd/api"
"go.sia.tech/renterd/internal/test"
)

func TestBlocklist(t *testing.T) {
Expand All @@ -26,7 +27,7 @@ func TestBlocklist(t *testing.T) {
tt := cluster.tt

// fetch contracts
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 3 {
t.Fatalf("unexpected number of contracts, %v != 3", len(contracts))
Expand All @@ -40,7 +41,7 @@ func TestBlocklist(t *testing.T) {

// assert h3 is no longer in the contract set
tt.Retry(5, time.Second, func() error {
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 2 {
return fmt.Errorf("unexpected number of contracts, %v != 2", len(contracts))
Expand All @@ -60,7 +61,7 @@ func TestBlocklist(t *testing.T) {

// assert h1 is no longer in the contract set
tt.Retry(5, time.Second, func() error {
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 1 {
return fmt.Errorf("unexpected number of contracts, %v != 1", len(contracts))
Expand All @@ -77,7 +78,7 @@ func TestBlocklist(t *testing.T) {
tt.OK(b.UpdateHostAllowlist(ctx, nil, []types.PublicKey{hk1, hk2}, false))
tt.OK(b.UpdateHostBlocklist(ctx, nil, []string{h1.NetAddress}, false))
tt.Retry(5, time.Second, func() error {
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: testAutopilotConfig.Contracts.Set})
contracts, err := b.Contracts(ctx, api.ContractsOpts{ContractSet: test.AutopilotConfig.Contracts.Set})
tt.OK(err)
if len(contracts) != 3 {
return fmt.Errorf("unexpected number of contracts, %v != 3", len(contracts))
Expand Down
80 changes: 13 additions & 67 deletions internal/test/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"time"

"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"go.sia.tech/core/consensus"
rhpv2 "go.sia.tech/core/rhp/v2"
"go.sia.tech/core/types"
"go.sia.tech/jape"
"go.sia.tech/renterd/api"
Expand All @@ -36,66 +34,14 @@ import (
)

const (
testBusFlushInterval = 100 * time.Millisecond
testContractSet = "testset"
testPersistInterval = 2 * time.Second
latestHardforkHeight = 50 // foundation hardfork height in testing
testBusFlushInterval = 100 * time.Millisecond
testBusPersistInterval = 2 * time.Second
latestHardforkHeight = 50 // foundation hardfork height in testing
)

var (
clusterOptsDefault = testClusterOptions{}
clusterOptNoFunding = false

// testAutopilotConfig is the autopilot used for testing unless a different
// one is explicitly set.
testAutopilotConfig = api.AutopilotConfig{
Contracts: api.ContractsConfig{
Allowance: types.Siacoins(1).Mul64(1e3),
Amount: 3,
Period: 144,
RenewWindow: 72,

Download: rhpv2.SectorSize * 500,
Upload: rhpv2.SectorSize * 500,
Storage: rhpv2.SectorSize * 5e3,

Set: testContractSet,
Prune: false,
},
Hosts: api.HostsConfig{
MaxDowntimeHours: 10,
MinRecentScanFailures: 10,
AllowRedundantIPs: true, // allow for integration tests by default
},
}

testContractSetSettings = api.ContractSetSetting{
Default: testContractSet,
}

testGougingSettings = api.GougingSettings{
MinMaxCollateral: types.Siacoins(10), // at least up to 10 SC per contract
MaxRPCPrice: types.Siacoins(1).Div64(1000), // 1mS per RPC
MaxContractPrice: types.Siacoins(10), // 10 SC per contract
MaxDownloadPrice: types.Siacoins(1).Mul64(1000), // 1000 SC per 1 TiB
MaxUploadPrice: types.Siacoins(1).Mul64(1000), // 1000 SC per 1 TiB
MaxStoragePrice: types.Siacoins(1000).Div64(144 * 30), // 1000 SC per month

HostBlockHeightLeeway: 240, // amount of leeway given to host block height

MinPriceTableValidity: 10 * time.Second, // minimum value for price table validity
MinAccountExpiry: time.Hour, // minimum value for account expiry
MinMaxEphemeralAccountBalance: types.Siacoins(1), // 1SC
}

testRedundancySettings = api.RedundancySettings{
MinShards: 2,
TotalShards: 3,
}

testS3AccessKeyID = "TESTINGYNHUWCPKOPSYQ"
testS3SecretAccessKey = "Rh30BNyj+qNI4ftYRteoZbHJ3X4Ln71QtZkRXzJ9"
testS3Credentials = credentials.NewStaticV4(testS3AccessKeyID, testS3SecretAccessKey, "")
)

// TestCluster is a helper type that allows for easily creating a number of
Expand Down Expand Up @@ -287,7 +233,7 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {
if opts.uploadPacking {
enableUploadPacking = opts.uploadPacking
}
apSettings := testAutopilotConfig
apSettings := test.AutopilotConfig
if opts.autopilotSettings != nil {
apSettings = *opts.autopilotSettings
}
Expand Down Expand Up @@ -340,14 +286,14 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {
busClient := bus.NewClient(busAddr, busPassword)
workerClient := worker.NewClient(workerAddr, workerPassword)
s3Client, err := minio.New(s3Addr, &minio.Options{
Creds: testS3Credentials,
Creds: test.S3Credentials,
Secure: false,
})
tt.OK(err)

url := s3Client.EndpointURL()
s3Core, err := minio.NewCore(url.Host+url.Path, &minio.Options{
Creds: testS3Credentials,
Creds: test.S3Credentials,
})
tt.OK(err)

Expand Down Expand Up @@ -455,7 +401,7 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {

// Set the test contract set to make sure we can add objects at the
// beginning of a test right away.
tt.OK(busClient.SetContractSet(ctx, testContractSet, []types.FileContractID{}))
tt.OK(busClient.SetContractSet(ctx, test.ContractSet, []types.FileContractID{}))

// Update the autopilot to use test settings
if !opts.skipSettingAutopilot {
Expand All @@ -466,11 +412,11 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {
}

// Update the bus settings.
tt.OK(busClient.UpdateSetting(ctx, api.SettingGouging, testGougingSettings))
tt.OK(busClient.UpdateSetting(ctx, api.SettingRedundancy, testRedundancySettings))
tt.OK(busClient.UpdateSetting(ctx, api.SettingContractSet, testContractSetSettings))
tt.OK(busClient.UpdateSetting(ctx, api.SettingGouging, test.GougingSettings))
tt.OK(busClient.UpdateSetting(ctx, api.SettingRedundancy, test.RedundancySettings))
tt.OK(busClient.UpdateSetting(ctx, api.SettingContractSet, test.ContractSetSettings))
tt.OK(busClient.UpdateSetting(ctx, api.SettingS3Authentication, api.S3AuthenticationSettings{
V4Keypairs: map[string]string{testS3AccessKeyID: testS3SecretAccessKey},
V4Keypairs: map[string]string{test.S3AccessKeyID: test.S3SecretAccessKey},
}))
tt.OK(busClient.UpdateSetting(ctx, api.SettingUploadPacking, api.UploadPackingSettings{Enabled: enableUploadPacking}))

Expand Down Expand Up @@ -501,7 +447,7 @@ func newTestCluster(t *testing.T, opts testClusterOptions) *TestCluster {
if nHosts > 0 {
cluster.AddHostsBlocking(nHosts)
cluster.WaitForContracts()
cluster.WaitForContractSet(testContractSet, nHosts)
cluster.WaitForContractSet(test.ContractSet, nHosts)
_ = cluster.WaitForAccounts()
}

Expand Down Expand Up @@ -926,7 +872,7 @@ func testBusCfg() node.BusConfig {
AnnouncementMaxAgeHours: 24 * 7 * 52, // 1 year
Bootstrap: false,
GatewayAddr: "127.0.0.1:0",
PersistInterval: testPersistInterval,
PersistInterval: testBusPersistInterval,
UsedUTXOExpiry: time.Minute,
SlabBufferCompletionThreshold: 0,
},
Expand Down
Loading

0 comments on commit 9798d64

Please sign in to comment.