Skip to content

Commit

Permalink
Merge pull request #423 from AssetMantle/deepanshu
Browse files Browse the repository at this point in the history
Deepanshu
  • Loading branch information
deepanshutr authored Aug 18, 2023
2 parents 334bb3a + f3bb1c8 commit c2a811f
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/AssetMantle/modules
go 1.19

require (
github.com/AssetMantle/schema/go v0.0.0-20230818005323-13dfca1fcce5
github.com/AssetMantle/schema/go v0.0.0-20230818041933-0e4158d6c895
github.com/CosmWasm/wasmd v0.30.0
github.com/Shopify/sarama v1.19.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ git.sr.ht/~sircmpwn/go-bare v0.0.0-20210406120253-ab86bc2846d9/go.mod h1:BVJwbDf
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/AssetMantle/schema/go v0.0.0-20230818005323-13dfca1fcce5 h1:rI+Vu8CCfJipAXmgh7rMQQhzTzA8Fqm+foKFIHr2TaM=
github.com/AssetMantle/schema/go v0.0.0-20230818005323-13dfca1fcce5/go.mod h1:+b+pr5ek9on9CiojcnJQAncPfCqSMeC78XpG+n/VX7o=
github.com/AssetMantle/schema/go v0.0.0-20230818041933-0e4158d6c895 h1:pFhzFuDO8S10lJ/NteojopbevgQx0ULhfR1kh9fcK9M=
github.com/AssetMantle/schema/go v0.0.0-20230818041933-0e4158d6c895/go.mod h1:+b+pr5ek9on9CiojcnJQAncPfCqSMeC78XpG+n/VX7o=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo=
Expand Down
2 changes: 1 addition & 1 deletion x/assets/parameters/unwrap_allowed_coins/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var ID = constantProperties.UnwrapAllowedCoinsProperty.GetKey()
var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewListData(baseData.NewStringData("umntl"))))
var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewListData()))

func validator(i interface{}) error {
switch value := i.(type) {
Expand Down
2 changes: 1 addition & 1 deletion x/assets/parameters/wrap_allowed_coins/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var ID = constantProperties.WrapAllowedCoinsProperty.GetKey()
var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewListData(baseData.NewStringData("umntl"))))
var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewListData()))

func validator(i interface{}) error {
switch value := i.(type) {
Expand Down
4 changes: 4 additions & 0 deletions x/classifications/auxiliaries/define/auxiliary_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type auxiliaryKeeper struct {
var _ helpers.AuxiliaryKeeper = (*auxiliaryKeeper)(nil)

func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) {
if !auxiliaryKeeper.parameterManager.Fetch(context).GetParameter(constantProperties.DefineEnabledProperty.GetID()).GetMetaProperty().GetData().Get().(data.BooleanData).Get() {
return nil, errorConstants.NotAuthorized.Wrapf("classification defining is not enabled")
}

auxiliaryRequest := auxiliaryRequestFromInterface(request)

totalWeight := sdkTypes.ZeroInt()
Expand Down
29 changes: 29 additions & 0 deletions x/classifications/parameters/define_enabled/parameter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0

package define_enabled

import (
baseData "github.com/AssetMantle/schema/go/data/base"
errorConstants "github.com/AssetMantle/schema/go/errors/constants"
baseParameters "github.com/AssetMantle/schema/go/parameters/base"
"github.com/AssetMantle/schema/go/properties/base"
constantProperties "github.com/AssetMantle/schema/go/properties/constants"

baseHelpers "github.com/AssetMantle/modules/helpers/base"
)

var ID = constantProperties.DefineEnabledProperty.GetKey()
var Parameter = baseParameters.NewParameter(base.NewMetaProperty(ID, baseData.NewBooleanData(false)))

func validator(i interface{}) error {
switch value := i.(type) {
case string:
_, err := baseData.PrototypeBooleanData().FromString(value)
return err
default:
return errorConstants.IncorrectFormat.Wrapf("incorrect type for defineEnabled parameter, expected %s type as string, got %T", baseData.NewBooleanData(false).GetTypeID().AsString(), i)
}
}

var ValidatableParameter = baseHelpers.NewValidatableParameter(Parameter, validator)
41 changes: 41 additions & 0 deletions x/classifications/parameters/define_enabled/parameter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
// SPDX-License-Identifier: Apache-2.0

package define_enabled

import (
"testing"

baseData "github.com/AssetMantle/schema/go/data/base"
baseIDs "github.com/AssetMantle/schema/go/ids/base"
baseParameters "github.com/AssetMantle/schema/go/parameters/base"
baseProperties "github.com/AssetMantle/schema/go/properties/base"
)

func Test_validator(t *testing.T) {
type args struct {
i interface{}
}
tests := []struct {
name string
args args
wantError bool
}{
{"-ve incorrectFormat", args{baseIDs.NewStringID("")}, true},
{"+ve", args{Parameter}, false},
{"-ve InvalidParameter", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID(""), baseData.NewStringData("")))}, true},
{"+ve with booleanData", args{baseData.NewBooleanData(false)}, false},
{"-ve with different type of Data", args{baseData.NewStringData("stringData")}, true},
{"+ve with true booleanData", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID("defineEnabled"), baseData.NewBooleanData(true)))}, false},
{"+ve with false booleanData", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID("defineEnabled"), baseData.NewBooleanData(false)))}, false},
{"+ve with incorrect ID", args{baseParameters.NewParameter(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID"), baseData.NewBooleanData(false)))}, true},
{"-ve nil", args{}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := validator(tt.args.i); (err != nil) != tt.wantError {
t.Errorf("validator() error = %v, wantErr %v", err, tt.wantError)
}
})
}
}
3 changes: 2 additions & 1 deletion x/classifications/parameters/prototype.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
baseHelpers "github.com/AssetMantle/modules/helpers/base"
"github.com/AssetMantle/modules/x/classifications/constants"
"github.com/AssetMantle/modules/x/classifications/parameters/bond_rate"
"github.com/AssetMantle/modules/x/classifications/parameters/define_enabled"
"github.com/AssetMantle/modules/x/classifications/parameters/max_property_count"
)

func Prototype() helpers.ParameterManager {
return baseHelpers.NewParameterManager(constants.ModuleName, bond_rate.ValidatableParameter, max_property_count.ValidatableParameter)
return baseHelpers.NewParameterManager(constants.ModuleName, bond_rate.ValidatableParameter, define_enabled.ValidatableParameter, max_property_count.ValidatableParameter)
}
29 changes: 27 additions & 2 deletions x/maintainers/auxiliaries/deputize/auxiliary_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
baseData "github.com/AssetMantle/schema/go/data/base"
"github.com/AssetMantle/schema/go/documents/base"
errorConstants "github.com/AssetMantle/schema/go/errors/constants"
"github.com/AssetMantle/schema/go/ids"
baseIDs "github.com/AssetMantle/schema/go/ids/base"
"github.com/AssetMantle/schema/go/lists"
baseLists "github.com/AssetMantle/schema/go/lists/base"
baseProperties "github.com/AssetMantle/schema/go/properties/base"
constantProperties "github.com/AssetMantle/schema/go/properties/constants"
Expand Down Expand Up @@ -103,8 +105,11 @@ func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, request hel
return nil, errorConstants.NotAuthorized.Wrapf("maintainer does not have the permission to mutate maintainers")
}

maintainedProperties := mappable.GetMaintainer(Mappable).GetMutables().GetMutablePropertyList().Add(baseLists.AnyPropertiesToProperties(auxiliaryRequest.MaintainedProperties.Get()...)...).Remove(baseLists.AnyPropertiesToProperties(removeMaintainedPropertyList.Get()...)...)
maintainer := base.NewMaintainer(auxiliaryRequest.ToIdentityID, auxiliaryRequest.MaintainedClassificationID, maintainedProperties.GetPropertyIDList(), internalUtilities.SetModulePermissions(auxiliaryRequest.CanAddMaintainer, auxiliaryRequest.CanMutateMaintainer, auxiliaryRequest.CanRemoveMaintainer).Add(baseIDs.StringIDsToIDs(auxiliaryRequest.PermissionIDs)...))
maintainedProperties := mappable.GetMaintainer(Mappable).GetMaintainedProperties().
Add(idListToListData(auxiliaryRequest.MaintainedProperties.GetPropertyIDList())...).
Remove(idListToListData(removeMaintainedPropertyList.GetPropertyIDList())...)

maintainer := base.NewMaintainer(auxiliaryRequest.ToIdentityID, auxiliaryRequest.MaintainedClassificationID, listDataToIDList(maintainedProperties), internalUtilities.SetModulePermissions(auxiliaryRequest.CanAddMaintainer, auxiliaryRequest.CanMutateMaintainer, auxiliaryRequest.CanRemoveMaintainer).Add(baseIDs.StringIDsToIDs(auxiliaryRequest.PermissionIDs)...))

if err := maintainer.ValidateBasic(); err != nil {
return nil, err
Expand Down Expand Up @@ -136,3 +141,23 @@ func (auxiliaryKeeper auxiliaryKeeper) Initialize(mapper helpers.Mapper, paramet
func keeperPrototype() helpers.AuxiliaryKeeper {
return auxiliaryKeeper{}
}

func idListToListData(idList lists.IDList) []data.ListableData {
listableData := make([]data.ListableData, len(idList.GetList()))

for i, id := range idList.GetList() {
listableData[i] = baseData.NewIDData(id)
}

return listableData
}

func listDataToIDList(listData data.ListData) lists.IDList {
idList := make([]ids.ID, len(listData.Get()))

for i, datum := range listData.Get() {
idList[i] = datum.Get().(data.IDData).Get()
}

return baseLists.NewIDList(idList...)
}

0 comments on commit c2a811f

Please sign in to comment.