diff --git a/go/node/deployment/v1beta3/types_test.go b/go/node/deployment/v1beta3/types_test.go index 1b5fdc06..e390e134 100644 --- a/go/node/deployment/v1beta3/types_test.go +++ b/go/node/deployment/v1beta3/types_test.go @@ -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, }, @@ -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, }, @@ -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{ @@ -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") @@ -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") @@ -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") @@ -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{ @@ -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{ @@ -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{ diff --git a/go/node/market/v1beta4/bid_test.go b/go/node/market/v1beta4/bid_test.go new file mode 100644 index 00000000..a9ee578e --- /dev/null +++ b/go/node/market/v1beta4/bid_test.go @@ -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)) +} diff --git a/go/testutil/v1beta3/base.go b/go/testutil/v1beta3/base.go index 40210b6a..656ae253 100644 --- a/go/testutil/v1beta3/base.go +++ b/go/testutil/v1beta3/base.go @@ -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" @@ -66,8 +67,9 @@ 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) @@ -75,7 +77,7 @@ func ResourcesList(t testing.TB) dtypes.ResourceUnits { 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)), }, @@ -95,6 +97,9 @@ func ResourcesList(t testing.TB) dtypes.ResourceUnits { Count: 1, Price: coin, } + + startID++ + vals = append(vals, res) } return vals diff --git a/go/testutil/v1beta3/deployment.go b/go/testutil/v1beta3/deployment.go index e02294d4..cda6ee27 100644 --- a/go/testutil/v1beta3/deployment.go +++ b/go/testutil/v1beta3/deployment.go @@ -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), }, } } @@ -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), } }