Skip to content

Commit

Permalink
fix tests linting
Browse files Browse the repository at this point in the history
  • Loading branch information
xmariachi committed Nov 30, 2024
1 parent 2b4cb86 commit f3bfbe3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
30 changes: 15 additions & 15 deletions usecase/build_commit_reputer_payload_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// nolint:all // TODO: fix
package usecase

import (
Expand All @@ -10,14 +9,15 @@ import (
emissionstypes "github.com/allora-network/allora-chain/x/emissions/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func TestComputeLossBundle(t *testing.T) {
reputerOptions := map[string]string{
"method": "sqe",
}
reputerConfig := lib.ReputerConfig{
LossFunctionParameters: lib.LossFunctionParameters{
reputerConfig := lib.ReputerConfig{ // nolint: exhaustruct
LossFunctionParameters: lib.LossFunctionParameters{ // nolint: exhaustruct
LossMethodOptions: reputerOptions,
IsNeverNegative: &[]bool{false}[0],
},
Expand All @@ -33,15 +33,15 @@ func TestComputeLossBundle(t *testing.T) {
expectError bool
errorContains string
}{
{
{ // nolint: exhaustruct
name: "Happy path - all positive values",
sourceTruth: "10.0",
valueBundle: func() *emissionstypes.ValueBundle {
combined, _ := alloraMath.NewDecFromString("9.5")
naive, _ := alloraMath.NewDecFromString("9.0")
inferer, _ := alloraMath.NewDecFromString("9.7")
forecaster, _ := alloraMath.NewDecFromString("9.8")
return &emissionstypes.ValueBundle{
return &emissionstypes.ValueBundle{ // nolint: exhaustruct
CombinedValue: combined,
NaiveValue: naive,
InfererValues: []*emissionstypes.WorkerAttributedValue{
Expand All @@ -68,12 +68,12 @@ func TestComputeLossBundle(t *testing.T) {
},
expectError: false,
},
{
{ // nolint: exhaustruct
name: "Error in LossFunction",
sourceTruth: "10.0",
valueBundle: func() *emissionstypes.ValueBundle {
combined, _ := alloraMath.NewDecFromString("9.5")
return &emissionstypes.ValueBundle{
return &emissionstypes.ValueBundle{ // nolint: exhaustruct
CombinedValue: combined,
}
}(),
Expand All @@ -84,12 +84,12 @@ func TestComputeLossBundle(t *testing.T) {
expectError: true,
errorContains: "error computing loss for combined value",
},
{
{ // nolint: exhaustruct
name: "Invalid loss value",
sourceTruth: "10.0",
valueBundle: func() *emissionstypes.ValueBundle {
combined, _ := alloraMath.NewDecFromString("9.5")
return &emissionstypes.ValueBundle{
return &emissionstypes.ValueBundle{ // nolint: exhaustruct
CombinedValue: combined,
}
}(),
Expand All @@ -100,7 +100,7 @@ func TestComputeLossBundle(t *testing.T) {
expectError: true,
errorContains: "error parsing loss",
},
{
{ // nolint: exhaustruct
name: "Nil ValueBundle",
sourceTruth: "10.0",
valueBundle: nil,
Expand All @@ -109,10 +109,10 @@ func TestComputeLossBundle(t *testing.T) {
expectError: true,
errorContains: "nil ValueBundle",
},
{
{ // nolint: exhaustruct
name: "Empty ValueBundle",
sourceTruth: "10.0",
valueBundle: &emissionstypes.ValueBundle{},
valueBundle: &emissionstypes.ValueBundle{}, // nolint: exhaustruct
reputerConfig: reputerConfig,
mockSetup: func(m *MockAlloraAdapter) {},
expectError: true,
Expand All @@ -127,14 +127,14 @@ func TestComputeLossBundle(t *testing.T) {
tt.reputerConfig.GroundTruthEntrypoint = mockAdapter
tt.reputerConfig.LossFunctionEntrypoint = mockAdapter

suite := &UseCaseSuite{}
suite := &UseCaseSuite{} // nolint: exhaustruct
result, err := suite.ComputeLossBundle(tt.sourceTruth, tt.valueBundle, tt.reputerConfig)

if tt.expectError {
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.errorContains)
} else {
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.expectedLossStrings["CombinedValue"], result.CombinedValue.String(), "Mismatch for CombinedValue")
assert.Equal(t, tt.expectedLossStrings["NaiveValue"], result.NaiveValue.String(), "Mismatch for NaiveValue")
for i, inferer := range result.InfererValues {
Expand Down
22 changes: 11 additions & 11 deletions usecase/build_commit_worker_payload_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// nolint:all // TODO: fix
package usecase

import (
Expand All @@ -8,6 +7,7 @@ import (
alloraMath "github.com/allora-network/allora-chain/math"
emissionstypes "github.com/allora-network/allora-chain/x/emissions/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func (suite *UseCaseSuite) SetupTest() {
Expand Down Expand Up @@ -48,13 +48,13 @@ func TestComputeWorkerBundle(t *testing.T) {
mockSetup: func(m *MockAlloraAdapter) {
},
expectedResponse: emissionstypes.InferenceForecastBundle{
Inference: &emissionstypes.Inference{
Inference: &emissionstypes.Inference{ // nolint: exhaustruct
TopicId: uint64(1),
BlockHeight: 1,
Inferer: "worker1",
Value: alloraMath.MustNewDecFromString("9.5"),
},
Forecast: &emissionstypes.Forecast{
Forecast: &emissionstypes.Forecast{ // nolint: exhaustruct
TopicId: uint64(1),
BlockHeight: 1,
Forecaster: "worker1",
Expand All @@ -66,11 +66,11 @@ func TestComputeWorkerBundle(t *testing.T) {
},
},
},
expectError: false,
address: "worker1",
expectError: false,
errorContains: "",
address: "worker1",
},
// Add more test cases here
{
{ // nolint: exhaustruct
name: "Invalid inference value",
workerConfig: lib.WorkerResponse{
WorkerConfig: lib.WorkerConfig{
Expand All @@ -91,7 +91,7 @@ func TestComputeWorkerBundle(t *testing.T) {
errorContains: "invalid decimal string",
address: "worker1",
},
{
{ // nolint: exhaustruct
name: "Invalid forecast value",
workerConfig: lib.WorkerResponse{
WorkerConfig: lib.WorkerConfig{
Expand Down Expand Up @@ -121,14 +121,14 @@ func TestComputeWorkerBundle(t *testing.T) {
tt.workerConfig.InferenceEntrypoint = mockAdapter
tt.workerConfig.ForecastEntrypoint = mockAdapter

suite := &UseCaseSuite{}
suite := &UseCaseSuite{} // nolint: exhaustruct
suite.Node.Wallet.Address = tt.address
response, err := suite.BuildWorkerPayload(tt.workerConfig, 1)
if tt.expectError {
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), tt.errorContains)
} else {
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tt.expectedResponse.Inference.BlockHeight, response.Inference.BlockHeight)
assert.Equal(t, tt.expectedResponse.Inference.Inferer, response.Inference.Inferer)
assert.Equal(t, tt.expectedResponse.Inference.TopicId, response.Inference.TopicId)
Expand Down
1 change: 0 additions & 1 deletion usecase/mock_allora_adapter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package usecase

// nolint:all // TODO: fix
import (
"allora_offchain_node/lib"

Expand Down
2 changes: 0 additions & 2 deletions usecase/spawn_actor_processes_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// nolint:all // TODO: fix

package usecase

import (
Expand Down

0 comments on commit f3bfbe3

Please sign in to comment.