forked from lavanet/lava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lavanet#619 from lavanet/CNS-503-cleanup-unit-tests
CNS-503 cleanup unit tests (part 1)
- Loading branch information
Showing
12 changed files
with
1,307 additions
and
1,279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package types | ||
|
||
const ( | ||
STALE_ENTRY_TIME int64 = 1440 // 1440 blocks (equivalent to 24 hours when block_time = 1min) | ||
STALE_ENTRY_TIME = 1440 // 1440 blocks (equivalent to 24 hours when block_time = 1min) | ||
MODULE_NAME string = "common" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFindMin(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
slice []int | ||
min int | ||
}{ | ||
{"empty", []int{}, 0}, | ||
{"one element", []int{1}, 1}, | ||
{"min is first", []int{1, 2, 3}, 1}, | ||
{"min is middle", []int{2, 1, 3}, 1}, | ||
{"min is last", []int{3, 2, 1}, 1}, | ||
{"min is zero", []int{3, 0, 1}, 0}, | ||
{"min < zero", []int{3, -2, 1}, -2}, | ||
{"min twice", []int{3, 1, 1}, 1}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
min := FindMin(tt.slice) | ||
require.Equal(t, tt.min, min) | ||
}) | ||
} | ||
} | ||
|
||
func TestFindMax(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
slice []int | ||
max int | ||
}{ | ||
{"empty", []int{}, 0}, | ||
{"one element", []int{1}, 1}, | ||
{"max is first", []int{3, 2, 1}, 3}, | ||
{"max is middle", []int{2, 1, 3}, 3}, | ||
{"max is last", []int{1, 2, 3}, 3}, | ||
{"max is zero", []int{-3, 0, -1}, 0}, | ||
{"max < zero", []int{-3, -2, -5}, -2}, | ||
{"max twice", []int{1, 3, 3}, 3}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
max := FindMax(tt.slice) | ||
require.Equal(t, tt.max, max) | ||
}) | ||
} | ||
} | ||
|
||
func TestIntersection(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
slices [][]int | ||
result []int | ||
}{ | ||
{"zero slices", [][]int{}, []int{}}, | ||
{"one slice", [][]int{{1, 2}}, []int{1, 2}}, | ||
{"two slices, one empty", [][]int{{1, 2}, {}}, []int{}}, | ||
{"two slices, non empty", [][]int{{1, 2, 3}, {1, 3}}, []int{1, 3}}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
res := Intersection(tt.slices...) | ||
require.Subset(t, tt.result, res) | ||
require.Subset(t, res, tt.result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package common | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
epochstoragetypes "github.com/lavanet/lava/x/epochstorage/types" | ||
plantypes "github.com/lavanet/lava/x/plans/types" | ||
spectypes "github.com/lavanet/lava/x/spec/types" | ||
) | ||
|
||
func CreateMockSpec() spectypes.Spec { | ||
specName := "mock_spec" | ||
spec := spectypes.Spec{} | ||
spec.Name = specName | ||
spec.Index = specName | ||
spec.Enabled = true | ||
spec.ReliabilityThreshold = 4294967295 | ||
spec.BlockDistanceForFinalizedData = 0 | ||
spec.DataReliabilityEnabled = true | ||
spec.MinStakeClient = sdk.NewCoin(epochstoragetypes.TokenDenom, sdk.NewInt(100)) | ||
spec.MinStakeProvider = sdk.NewCoin(epochstoragetypes.TokenDenom, sdk.NewInt(1000)) | ||
spec.ApiCollections = []*spectypes.ApiCollection{{Enabled: true, CollectionData: spectypes.CollectionData{ApiInterface: "stub", Type: "GET"}, Apis: []*spectypes.Api{{Name: specName + "API", ComputeUnits: 100, Enabled: true}}}} | ||
spec.BlockDistanceForFinalizedData = 0 | ||
return spec | ||
} | ||
|
||
func CreateMockPlan() plantypes.Plan { | ||
plan := plantypes.Plan{ | ||
Index: "mock_plan", | ||
Description: "plan for testing", | ||
Type: "rpc", | ||
Block: 100, | ||
Price: sdk.NewCoin("ulava", sdk.NewInt(100)), | ||
AllowOveruse: true, | ||
OveruseRate: 10, | ||
AnnualDiscountPercentage: 20, | ||
PlanPolicy: CreateMockPolicy(), | ||
} | ||
|
||
return plan | ||
} | ||
|
||
func CreateMockPolicy() plantypes.Policy { | ||
policy := plantypes.Policy{ | ||
TotalCuLimit: 100000, | ||
EpochCuLimit: 10000, | ||
MaxProvidersToPair: 3, | ||
GeolocationProfile: 1, | ||
} | ||
|
||
return policy | ||
} |
Oops, something went wrong.