Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(bid): add tests for bid gspec match #96

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions go/node/deployment/v1beta3/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestGroupSpecValidation(t *testing.T) {
gspec: types.GroupSpec{
Name: "",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
},
expErr: types.ErrInvalidGroups,
},
Expand All @@ -117,7 +117,7 @@ func TestGroupSpecValidation(t *testing.T) {
gspec: types.GroupSpec{
Name: "hihi",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
},
expErr: nil,
},
Expand All @@ -137,7 +137,7 @@ func TestGroupPlacementRequirementsNoSigners(t *testing.T) {
group := types.GroupSpec{
Name: "spec",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
}

providerAttr := []atypes.Provider{
Expand All @@ -154,7 +154,7 @@ func TestGroupPlacementRequirementsSignerAllOf(t *testing.T) {
group := types.GroupSpec{
Name: "spec",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
}

group.Requirements.SignedBy.AllOf = append(group.Requirements.SignedBy.AllOf, "auditor1")
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestGroupPlacementRequirementsSignerAnyOf(t *testing.T) {
group := types.GroupSpec{
Name: "spec",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
}

group.Requirements.SignedBy.AnyOf = append(group.Requirements.SignedBy.AnyOf, "auditor1")
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestGroupPlacementRequirementsSignerAllOfAnyOf(t *testing.T) {
group := types.GroupSpec{
Name: "spec",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
}

group.Requirements.SignedBy.AllOf = append(group.Requirements.SignedBy.AllOf, "auditor1")
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestGroupSpec_MatchResourcesAttributes(t *testing.T) {
group := types.GroupSpec{
Name: "spec",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
}

group.Resources[0].Storage[0].Attributes = akashtypes.Attributes{
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestGroupSpec_MatchGPUAttributes(t *testing.T) {
group := types.GroupSpec{
Name: "spec",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
}

group.Resources[0].GPU.Attributes = akashtypes.Attributes{
Expand Down Expand Up @@ -376,7 +376,7 @@ func TestGroupSpec_MatchGPUAttributesWildcard(t *testing.T) {
group := types.GroupSpec{
Name: "spec",
Requirements: testutil.PlacementRequirements(t),
Resources: testutil.ResourcesList(t),
Resources: testutil.ResourcesList(t, 1),
}

group.Resources[0].GPU.Attributes = akashtypes.Attributes{
Expand Down
46 changes: 46 additions & 0 deletions go/node/market/v1beta4/bid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package v1beta4

import (
"testing"

"github.com/stretchr/testify/require"

testutil "github.com/akash-network/akash-api/go/testutil/v1beta3"
)

func TestBid_GSpecMatch_Valid(t *testing.T) {
gspec := testutil.GroupSpec(t)

rOffer := ResourceOfferFromRU(gspec.Resources)

require.True(t, rOffer.MatchGSpec(gspec))
}

func TestBid_GSpecMatch_Valid2(t *testing.T) {
gspec := testutil.GroupSpec(t)

if len(gspec.Resources) == 1 {
rl := testutil.ResourcesList(t, 2)
rl[0].Count = 4
gspec.Resources = append(gspec.Resources, rl...)
}

rOffer := ResourceOfferFromRU(gspec.Resources)

require.True(t, rOffer.MatchGSpec(gspec))
}

func TestBid_GSpecMatch_InvalidCount(t *testing.T) {
gspec := testutil.GroupSpec(t)

if len(gspec.Resources) == 1 {
rl := testutil.ResourcesList(t, 2)
gspec.Resources = append(gspec.Resources, rl...)
}

rOffer := ResourceOfferFromRU(gspec.Resources)

gspec.Resources[0].Count = 2

require.False(t, rOffer.MatchGSpec(gspec))
}
11 changes: 8 additions & 3 deletions go/testutil/v1beta3/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/rand"

dtypes "github.com/akash-network/akash-api/go/node/deployment/v1beta3"
Expand Down Expand Up @@ -66,16 +67,17 @@ func RandStorageQuantity() uint64 {

// ResourcesList produces an attribute list for populating a Group's
// 'Resources' fields.
func ResourcesList(t testing.TB) dtypes.ResourceUnits {
t.Helper()
func ResourcesList(t testing.TB, startID uint32) dtypes.ResourceUnits {
require.GreaterOrEqual(t, uint32(1), startID)

count := uint32(rand.Intn(10)) + 1

vals := make(dtypes.ResourceUnits, 0, count)
for i := uint32(0); i < count; i++ {
coin := sdk.NewDecCoin(testutil.CoinDenom, sdk.NewInt(rand.Int63n(9999)+1))
res := dtypes.ResourceUnit{
Resources: types.Resources{
ID: i + 1,
ID: i + startID,
CPU: &types.CPU{
Units: types.NewResourceValue(uint64(dtypes.GetValidationConfig().Unit.Min.CPU)),
},
Expand All @@ -95,6 +97,9 @@ func ResourcesList(t testing.TB) dtypes.ResourceUnits {
Count: 1,
Price: coin,
}

startID++

vals = append(vals, res)
}
return vals
Expand Down
4 changes: 2 additions & 2 deletions go/testutil/v1beta3/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func DeploymentGroup(t testing.TB, did dtypes.DeploymentID, gseq uint32) dtypes.
GroupSpec: dtypes.GroupSpec{
Name: testutil.Name(t, "dgroup"),
Requirements: PlacementRequirements(t),
Resources: ResourcesList(t),
Resources: ResourcesList(t, 1),
},
}
}
Expand All @@ -46,7 +46,7 @@ func GroupSpec(t testing.TB) dtypes.GroupSpec {
return dtypes.GroupSpec{
Name: testutil.Name(t, "dgroup"),
Requirements: PlacementRequirements(t),
Resources: ResourcesList(t),
Resources: ResourcesList(t, 1),
}
}

Expand Down