diff --git a/modules/maintainers/auxiliaries/deputize/keeper_test.go b/modules/maintainers/auxiliaries/deputize/keeper_test.go new file mode 100644 index 000000000..514aaba13 --- /dev/null +++ b/modules/maintainers/auxiliaries/deputize/keeper_test.go @@ -0,0 +1,169 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package deputize + +import ( + "fmt" + "github.com/AssetMantle/modules/modules/classifications/auxiliaries/member" + "github.com/AssetMantle/modules/modules/maintainers/internal/key" + "github.com/AssetMantle/modules/modules/maintainers/internal/mappable" + "github.com/AssetMantle/modules/modules/maintainers/internal/parameters" + maintainerUtilities "github.com/AssetMantle/modules/modules/maintainers/internal/utilities" + "github.com/AssetMantle/modules/schema" + baseData "github.com/AssetMantle/modules/schema/data/base" + baseDocuments "github.com/AssetMantle/modules/schema/documents/base" + "github.com/AssetMantle/modules/schema/helpers" + baseHelpers "github.com/AssetMantle/modules/schema/helpers/base" + baseIDs "github.com/AssetMantle/modules/schema/ids/base" + "github.com/AssetMantle/modules/schema/lists/base" + "github.com/AssetMantle/modules/schema/lists/utilities" + baseProperties "github.com/AssetMantle/modules/schema/properties/base" + baseQualified "github.com/AssetMantle/modules/schema/qualified/base" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/params" + "github.com/stretchr/testify/require" + abciTypes "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tendermintDB "github.com/tendermint/tm-db" + "reflect" + "testing" +) + +type TestKeepers struct { + DeputizeKeeper helpers.AuxiliaryKeeper +} + +var ( + memberAuxiliary helpers.Auxiliary + immutables = baseQualified.NewImmutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("Data2")))) + mutables = baseQualified.NewMutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("Data1")))) + testClassificationID = baseIDs.NewClassificationID(immutables, mutables) + testFromID = baseIDs.NewIdentityID(testClassificationID, immutables) + maintainedProperty = "maintainedProperty:S|maintainedProperty" + maintainedProperties, _ = utilities.ReadMetaPropertyList(maintainedProperty) + permissions = maintainerUtilities.SetPermissions(true, true, true, true, true, true) +) + +func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, helpers.Parameters) { + var Codec = codec.New() + schema.RegisterCodec(Codec) + types.RegisterCodec(Codec) + codec.RegisterCrypto(Codec) + codec.RegisterEvidences(Codec) + vesting.RegisterCodec(Codec) + Codec.Seal() + + storeKey := types.NewKVStoreKey("test") + paramsStoreKey := types.NewKVStoreKey("testParams") + paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") + Mapper := baseHelpers.NewMapper(key.Prototype, mappable.Prototype).Initialize(storeKey) + paramsKeeper := params.NewKeeper( + Codec, + paramsStoreKey, + paramsTransientStoreKeys, + ) + Parameters := parameters.Prototype().Initialize(paramsKeeper.Subspace("test")) + + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(storeKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, types.StoreTypeTransient, memDB) + err := commitMultiStore.LoadLatestVersion() + require.Nil(t, err) + + context := types.NewContext(commitMultiStore, abciTypes.Header{ + ChainID: "test", + }, false, log.NewNopLogger()) + + memberAuxiliary = member.AuxiliaryMock.Initialize(Mapper, Parameters) + keepers := TestKeepers{ + DeputizeKeeper: keeperPrototype().Initialize(Mapper, Parameters, []interface{}{}).(helpers.AuxiliaryKeeper), + } + + return context, keepers, Mapper, Parameters +} + +func Test_auxiliaryKeeper_Help(t *testing.T) { + context, keepers, Mapper, _ := createTestInput(t) + keepers.DeputizeKeeper.(auxiliaryKeeper).mapper.NewCollection(context).Add(mappable.NewMappable(baseDocuments.NewMaintainer(testFromID, testClassificationID, maintainedProperties.GetPropertyIDList(), permissions))) + type fields struct { + mapper helpers.Mapper + memberAuxiliary helpers.Auxiliary + } + type args struct { + context types.Context + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + fields fields + args args + want helpers.AuxiliaryResponse + }{ + {"+ve", fields{Mapper, memberAuxiliary}, args{context, NewAuxiliaryRequest(testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true)}, newAuxiliaryResponse(nil)}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryKeeper := auxiliaryKeeper{ + mapper: tt.fields.mapper, + memberAuxiliary: tt.fields.memberAuxiliary, + } + if got := auxiliaryKeeper.Help(tt.args.context, tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Help() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryKeeper_Initialize(t *testing.T) { + _, _, Mapper, Parameters := createTestInput(t) + type fields struct { + mapper helpers.Mapper + memberAuxiliary helpers.Auxiliary + } + type args struct { + mapper helpers.Mapper + in1 helpers.Parameters + auxiliaries []interface{} + } + tests := []struct { + name string + fields fields + args args + want helpers.Keeper + }{ + {"+ve", fields{Mapper, memberAuxiliary}, args{Mapper, Parameters, []interface{}{}}, auxiliaryKeeper{Mapper, memberAuxiliary}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryKeeper := auxiliaryKeeper{ + mapper: tt.fields.mapper, + memberAuxiliary: tt.fields.memberAuxiliary, + } + if got := auxiliaryKeeper.Initialize(tt.args.mapper, tt.args.in1, tt.args.auxiliaries); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { + t.Errorf("Initialize() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_keeperPrototype(t *testing.T) { + tests := []struct { + name string + want helpers.AuxiliaryKeeper + }{ + {"+ve", auxiliaryKeeper{}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := keeperPrototype(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("keeperPrototype() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/deputize/request_test.go b/modules/maintainers/auxiliaries/deputize/request_test.go new file mode 100644 index 000000000..33829dd2e --- /dev/null +++ b/modules/maintainers/auxiliaries/deputize/request_test.go @@ -0,0 +1,103 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package deputize + +import ( + "github.com/AssetMantle/modules/schema/helpers" + "github.com/AssetMantle/modules/schema/ids" + "github.com/AssetMantle/modules/schema/lists" + "reflect" + "testing" +) + +func TestNewAuxiliaryRequest(t *testing.T) { + type args struct { + fromID ids.IdentityID + toID ids.IdentityID + maintainedClassificationID ids.ClassificationID + maintainedProperties lists.PropertyList + canMintAsset bool + canBurnAsset bool + canRenumerateAsset bool + canAddMaintainer bool + canRemoveMaintainer bool + canMutateMaintainer bool + } + tests := []struct { + name string + args args + want helpers.AuxiliaryRequest + }{ + {"+ve", args{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}, auxiliaryRequest{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}}, + {"+ve with nil", args{}, auxiliaryRequest{}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewAuxiliaryRequest(tt.args.fromID, tt.args.toID, tt.args.maintainedClassificationID, tt.args.maintainedProperties, tt.args.canMintAsset, tt.args.canBurnAsset, tt.args.canRenumerateAsset, tt.args.canAddMaintainer, tt.args.canRemoveMaintainer, tt.args.canMutateMaintainer); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewAuxiliaryRequest() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequestFromInterface(t *testing.T) { + type args struct { + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + args args + want auxiliaryRequest + }{ + {"+ve", args{NewAuxiliaryRequest(testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true)}, auxiliaryRequest{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequest_Validate(t *testing.T) { + type fields struct { + FromID ids.IdentityID + ToID ids.IdentityID + MaintainedClassificationID ids.ClassificationID + MaintainedProperties lists.PropertyList + CanMintAsset bool + CanBurnAsset bool + CanRenumerateAsset bool + CanAddMaintainer bool + CanRemoveMaintainer bool + CanMutateMaintainer bool + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + {"+ve", fields{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryRequest := auxiliaryRequest{ + FromID: tt.fields.FromID, + ToID: tt.fields.ToID, + MaintainedClassificationID: tt.fields.MaintainedClassificationID, + MaintainedProperties: tt.fields.MaintainedProperties, + CanMintAsset: tt.fields.CanMintAsset, + CanBurnAsset: tt.fields.CanBurnAsset, + CanRenumerateAsset: tt.fields.CanRenumerateAsset, + CanAddMaintainer: tt.fields.CanAddMaintainer, + CanRemoveMaintainer: tt.fields.CanRemoveMaintainer, + CanMutateMaintainer: tt.fields.CanMutateMaintainer, + } + if err := auxiliaryRequest.Validate(); (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/maintain/keeper_test.go b/modules/maintainers/auxiliaries/maintain/keeper_test.go new file mode 100644 index 000000000..3311ded2d --- /dev/null +++ b/modules/maintainers/auxiliaries/maintain/keeper_test.go @@ -0,0 +1,163 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package maintain + +import ( + "fmt" + "github.com/AssetMantle/modules/modules/maintainers/internal/key" + "github.com/AssetMantle/modules/modules/maintainers/internal/mappable" + "github.com/AssetMantle/modules/modules/maintainers/internal/parameters" + maintainerUtilities "github.com/AssetMantle/modules/modules/maintainers/internal/utilities" + "github.com/AssetMantle/modules/schema" + baseData "github.com/AssetMantle/modules/schema/data/base" + baseDocuments "github.com/AssetMantle/modules/schema/documents/base" + errorConstants "github.com/AssetMantle/modules/schema/errors/constants" + "github.com/AssetMantle/modules/schema/helpers" + baseHelpers "github.com/AssetMantle/modules/schema/helpers/base" + baseIDs "github.com/AssetMantle/modules/schema/ids/base" + "github.com/AssetMantle/modules/schema/lists/base" + baseProperties "github.com/AssetMantle/modules/schema/properties/base" + baseQualified "github.com/AssetMantle/modules/schema/qualified/base" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/params" + "github.com/stretchr/testify/require" + abciTypes "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tendermintDB "github.com/tendermint/tm-db" + "reflect" + "testing" +) + +type TestKeepers struct { + MaintainKeeper helpers.AuxiliaryKeeper +} + +var ( + immutables = baseQualified.NewImmutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("Data2")))) + mutables = baseQualified.NewMutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("Data1")))) + testClassificationID = baseIDs.NewClassificationID(immutables, mutables) + testFromID = baseIDs.NewIdentityID(testClassificationID, immutables) + maintainedProperties = mutables.GetMutablePropertyList() + permissions = maintainerUtilities.SetPermissions(true, true, true, true, true, true) +) + +func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, helpers.Parameters) { + var Codec = codec.New() + schema.RegisterCodec(Codec) + types.RegisterCodec(Codec) + codec.RegisterCrypto(Codec) + codec.RegisterEvidences(Codec) + vesting.RegisterCodec(Codec) + Codec.Seal() + + storeKey := types.NewKVStoreKey("test") + paramsStoreKey := types.NewKVStoreKey("testParams") + paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") + Mapper := baseHelpers.NewMapper(key.Prototype, mappable.Prototype).Initialize(storeKey) + paramsKeeper := params.NewKeeper( + Codec, + paramsStoreKey, + paramsTransientStoreKeys, + ) + Parameters := parameters.Prototype().Initialize(paramsKeeper.Subspace("test")) + + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(storeKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, types.StoreTypeTransient, memDB) + err := commitMultiStore.LoadLatestVersion() + require.Nil(t, err) + + context := types.NewContext(commitMultiStore, abciTypes.Header{ + ChainID: "test", + }, false, log.NewNopLogger()) + + keepers := TestKeepers{ + MaintainKeeper: keeperPrototype().Initialize(Mapper, Parameters, []interface{}{}).(helpers.AuxiliaryKeeper), + } + + return context, keepers, Mapper, Parameters +} + +func Test_auxiliaryKeeper_Help(t *testing.T) { + context, keepers, Mapper, _ := createTestInput(t) + keepers.MaintainKeeper.(auxiliaryKeeper).mapper.NewCollection(context).Add(mappable.NewMappable(baseDocuments.NewMaintainer(testFromID, testClassificationID, maintainedProperties.GetPropertyIDList(), permissions))) + type fields struct { + mapper helpers.Mapper + } + type args struct { + context types.Context + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + fields fields + args args + want helpers.AuxiliaryResponse + }{ + {"+ve", fields{Mapper}, args{context, NewAuxiliaryRequest(testClassificationID, testFromID, mutables)}, newAuxiliaryResponse(nil)}, + {"+ve Not Authorized", fields{Mapper}, args{context, NewAuxiliaryRequest(testClassificationID, testFromID, baseQualified.NewMutables(immutables.GetImmutablePropertyList()))}, newAuxiliaryResponse(errorConstants.NotAuthorized)}, + {"+ve Entity Not Found", fields{Mapper}, args{context, NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), testFromID, mutables)}, newAuxiliaryResponse(errorConstants.EntityNotFound)}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryKeeper := auxiliaryKeeper{ + mapper: tt.fields.mapper, + } + if got := auxiliaryKeeper.Help(tt.args.context, tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Help() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryKeeper_Initialize(t *testing.T) { + _, _, Mapper, Parameters := createTestInput(t) + type fields struct { + mapper helpers.Mapper + } + type args struct { + mapper helpers.Mapper + in1 helpers.Parameters + in2 []interface{} + } + tests := []struct { + name string + fields fields + args args + want helpers.Keeper + }{ + {"+ve", fields{Mapper}, args{Mapper, Parameters, []interface{}{}}, auxiliaryKeeper{Mapper}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + au := auxiliaryKeeper{ + mapper: tt.fields.mapper, + } + if got := au.Initialize(tt.args.mapper, tt.args.in1, tt.args.in2); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { + t.Errorf("Initialize() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_keeperPrototype(t *testing.T) { + tests := []struct { + name string + want helpers.AuxiliaryKeeper + }{ + {"+ve", auxiliaryKeeper{}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := keeperPrototype(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("keeperPrototype() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/maintain/request_test.go b/modules/maintainers/auxiliaries/maintain/request_test.go new file mode 100644 index 000000000..4e8106e58 --- /dev/null +++ b/modules/maintainers/auxiliaries/maintain/request_test.go @@ -0,0 +1,83 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package maintain + +import ( + "github.com/AssetMantle/modules/schema/helpers" + "github.com/AssetMantle/modules/schema/ids" + "github.com/AssetMantle/modules/schema/qualified" + "reflect" + "testing" +) + +func TestNewAuxiliaryRequest(t *testing.T) { + type args struct { + maintainedClassificationID ids.ClassificationID + identityID ids.IdentityID + maintainedMutables qualified.Mutables + } + tests := []struct { + name string + args args + want helpers.AuxiliaryRequest + }{ + {"+ve with nil", args{}, auxiliaryRequest{}}, + {"+ve", args{testClassificationID, testFromID, mutables}, auxiliaryRequest{testClassificationID, testFromID, mutables}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewAuxiliaryRequest(tt.args.maintainedClassificationID, tt.args.identityID, tt.args.maintainedMutables); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewAuxiliaryRequest() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequestFromInterface(t *testing.T) { + type args struct { + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + args args + want auxiliaryRequest + }{ + {"+ve", args{NewAuxiliaryRequest(testClassificationID, testFromID, mutables)}, auxiliaryRequest{testClassificationID, testFromID, mutables}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequest_Validate(t *testing.T) { + type fields struct { + MaintainedClassificationID ids.ClassificationID + IdentityID ids.IdentityID + MaintainedMutables qualified.Mutables + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + {"+ve with nil", fields{}, false}, + {"+ve", fields{testClassificationID, testFromID, mutables}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryRequest := auxiliaryRequest{ + MaintainedClassificationID: tt.fields.MaintainedClassificationID, + IdentityID: tt.fields.IdentityID, + MaintainedMutables: tt.fields.MaintainedMutables, + } + if err := auxiliaryRequest.Validate(); (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/revoke/keeper_test.go b/modules/maintainers/auxiliaries/revoke/keeper_test.go new file mode 100644 index 000000000..3d36b86fb --- /dev/null +++ b/modules/maintainers/auxiliaries/revoke/keeper_test.go @@ -0,0 +1,165 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package revoke + +import ( + "fmt" + "github.com/AssetMantle/modules/modules/maintainers/internal/key" + "github.com/AssetMantle/modules/modules/maintainers/internal/mappable" + "github.com/AssetMantle/modules/modules/maintainers/internal/parameters" + maintainerUtilities "github.com/AssetMantle/modules/modules/maintainers/internal/utilities" + "github.com/AssetMantle/modules/schema" + baseData "github.com/AssetMantle/modules/schema/data/base" + baseDocuments "github.com/AssetMantle/modules/schema/documents/base" + errorConstants "github.com/AssetMantle/modules/schema/errors/constants" + "github.com/AssetMantle/modules/schema/helpers" + baseHelpers "github.com/AssetMantle/modules/schema/helpers/base" + baseIDs "github.com/AssetMantle/modules/schema/ids/base" + "github.com/AssetMantle/modules/schema/lists/base" + "github.com/AssetMantle/modules/schema/lists/utilities" + baseProperties "github.com/AssetMantle/modules/schema/properties/base" + baseQualified "github.com/AssetMantle/modules/schema/qualified/base" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/params" + "github.com/stretchr/testify/require" + abciTypes "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tendermintDB "github.com/tendermint/tm-db" + "reflect" + "testing" +) + +type TestKeepers struct { + RevokeKeeper helpers.AuxiliaryKeeper +} + +var ( + immutables = baseQualified.NewImmutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("Data2")))) + mutables = baseQualified.NewMutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("Data1")))) + testClassificationID = baseIDs.NewClassificationID(immutables, mutables) + testFromID = baseIDs.NewIdentityID(testClassificationID, immutables) + maintainedProperty = "maintainedProperty:S|maintainedProperty" + maintainedProperties, _ = utilities.ReadMetaPropertyList(maintainedProperty) + permissions = maintainerUtilities.SetPermissions(true, true, true, true, true, true) +) + +func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, helpers.Parameters) { + var Codec = codec.New() + schema.RegisterCodec(Codec) + types.RegisterCodec(Codec) + codec.RegisterCrypto(Codec) + codec.RegisterEvidences(Codec) + vesting.RegisterCodec(Codec) + Codec.Seal() + + storeKey := types.NewKVStoreKey("test") + paramsStoreKey := types.NewKVStoreKey("testParams") + paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") + Mapper := baseHelpers.NewMapper(key.Prototype, mappable.Prototype).Initialize(storeKey) + paramsKeeper := params.NewKeeper( + Codec, + paramsStoreKey, + paramsTransientStoreKeys, + ) + Parameters := parameters.Prototype().Initialize(paramsKeeper.Subspace("test")) + + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(storeKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, types.StoreTypeTransient, memDB) + err := commitMultiStore.LoadLatestVersion() + require.Nil(t, err) + + context := types.NewContext(commitMultiStore, abciTypes.Header{ + ChainID: "test", + }, false, log.NewNopLogger()) + + keepers := TestKeepers{ + RevokeKeeper: keeperPrototype().Initialize(Mapper, Parameters, []interface{}{}).(helpers.AuxiliaryKeeper), + } + + return context, keepers, Mapper, Parameters +} + +func Test_auxiliaryKeeper_Help(t *testing.T) { + context, keepers, Mapper, _ := createTestInput(t) + keepers.RevokeKeeper.(auxiliaryKeeper).mapper.NewCollection(context).Add(mappable.NewMappable(baseDocuments.NewMaintainer(testFromID, testClassificationID, maintainedProperties.GetPropertyIDList(), permissions))) + + type fields struct { + mapper helpers.Mapper + } + type args struct { + context types.Context + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + fields fields + args args + want helpers.AuxiliaryResponse + }{ + {"+ve", fields{Mapper}, args{context, NewAuxiliaryRequest(testFromID, testFromID, testClassificationID)}, newAuxiliaryResponse(nil)}, + {"+ve Entity Not Found ", fields{Mapper}, args{context, NewAuxiliaryRequest(testFromID, testFromID, baseIDs.PrototypeClassificationID())}, newAuxiliaryResponse(errorConstants.EntityNotFound)}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryKeeper := auxiliaryKeeper{ + mapper: tt.fields.mapper, + } + if got := auxiliaryKeeper.Help(tt.args.context, tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Help() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryKeeper_Initialize(t *testing.T) { + _, _, Mapper, Parameters := createTestInput(t) + type fields struct { + mapper helpers.Mapper + } + type args struct { + mapper helpers.Mapper + in1 helpers.Parameters + in2 []interface{} + } + tests := []struct { + name string + fields fields + args args + want helpers.Keeper + }{ + {"+ve", fields{Mapper}, args{Mapper, Parameters, []interface{}{}}, auxiliaryKeeper{Mapper}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + au := auxiliaryKeeper{ + mapper: tt.fields.mapper, + } + if got := au.Initialize(tt.args.mapper, tt.args.in1, tt.args.in2); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { + t.Errorf("Initialize() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_keeperPrototype(t *testing.T) { + tests := []struct { + name string + want helpers.AuxiliaryKeeper + }{ + {"+ve", auxiliaryKeeper{}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := keeperPrototype(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("keeperPrototype() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/revoke/request_test.go b/modules/maintainers/auxiliaries/revoke/request_test.go new file mode 100644 index 000000000..d04e28d29 --- /dev/null +++ b/modules/maintainers/auxiliaries/revoke/request_test.go @@ -0,0 +1,81 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package revoke + +import ( + "github.com/AssetMantle/modules/schema/helpers" + "github.com/AssetMantle/modules/schema/ids" + "reflect" + "testing" +) + +func TestNewAuxiliaryRequest(t *testing.T) { + type args struct { + fromID ids.IdentityID + toID ids.IdentityID + maintainedClassificationID ids.ClassificationID + } + tests := []struct { + name string + args args + want helpers.AuxiliaryRequest + }{ + {"+ve", args{testFromID, testFromID, testClassificationID}, auxiliaryRequest{testFromID, testFromID, testClassificationID}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewAuxiliaryRequest(tt.args.fromID, tt.args.toID, tt.args.maintainedClassificationID); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewAuxiliaryRequest() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequestFromInterface(t *testing.T) { + type args struct { + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + args args + want auxiliaryRequest + }{ + {"+ve", args{NewAuxiliaryRequest(testFromID, testFromID, testClassificationID)}, auxiliaryRequest{testFromID, testFromID, testClassificationID}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequest_Validate(t *testing.T) { + type fields struct { + FromID ids.IdentityID + ToID ids.IdentityID + MaintainedClassificationID ids.ClassificationID + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + {"+ve", fields{}, false}, + {"+ve", fields{testFromID, testFromID, testClassificationID}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryRequest := auxiliaryRequest{ + FromID: tt.fields.FromID, + ToID: tt.fields.ToID, + MaintainedClassificationID: tt.fields.MaintainedClassificationID, + } + if err := auxiliaryRequest.Validate(); (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/super/keeper_test.go b/modules/maintainers/auxiliaries/super/keeper_test.go new file mode 100644 index 000000000..ce8289242 --- /dev/null +++ b/modules/maintainers/auxiliaries/super/keeper_test.go @@ -0,0 +1,157 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package super + +import ( + "fmt" + "github.com/AssetMantle/modules/modules/maintainers/internal/key" + "github.com/AssetMantle/modules/modules/maintainers/internal/mappable" + "github.com/AssetMantle/modules/modules/maintainers/internal/parameters" + "github.com/AssetMantle/modules/schema" + baseData "github.com/AssetMantle/modules/schema/data/base" + errorConstants "github.com/AssetMantle/modules/schema/errors/constants" + "github.com/AssetMantle/modules/schema/helpers" + baseHelpers "github.com/AssetMantle/modules/schema/helpers/base" + baseIDs "github.com/AssetMantle/modules/schema/ids/base" + "github.com/AssetMantle/modules/schema/lists/base" + baseProperties "github.com/AssetMantle/modules/schema/properties/base" + baseQualified "github.com/AssetMantle/modules/schema/qualified/base" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + "github.com/cosmos/cosmos-sdk/x/params" + "github.com/stretchr/testify/require" + abciTypes "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tendermintDB "github.com/tendermint/tm-db" + "reflect" + "testing" +) + +type TestKeepers struct { + SuperKeeper helpers.AuxiliaryKeeper +} + +var ( + immutables = baseQualified.NewImmutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("Data2")))) + mutables = baseQualified.NewMutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("Data1")))) + testClassificationID = baseIDs.NewClassificationID(immutables, mutables) + testFromID = baseIDs.NewIdentityID(testClassificationID, immutables) +) + +func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, helpers.Parameters) { + var Codec = codec.New() + schema.RegisterCodec(Codec) + types.RegisterCodec(Codec) + codec.RegisterCrypto(Codec) + codec.RegisterEvidences(Codec) + vesting.RegisterCodec(Codec) + Codec.Seal() + + storeKey := types.NewKVStoreKey("test") + paramsStoreKey := types.NewKVStoreKey("testParams") + paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient") + Mapper := baseHelpers.NewMapper(key.Prototype, mappable.Prototype).Initialize(storeKey) + paramsKeeper := params.NewKeeper( + Codec, + paramsStoreKey, + paramsTransientStoreKeys, + ) + Parameters := parameters.Prototype().Initialize(paramsKeeper.Subspace("test")) + + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(storeKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, types.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, types.StoreTypeTransient, memDB) + err := commitMultiStore.LoadLatestVersion() + require.Nil(t, err) + + context := types.NewContext(commitMultiStore, abciTypes.Header{ + ChainID: "test", + }, false, log.NewNopLogger()) + + keepers := TestKeepers{ + SuperKeeper: keeperPrototype().Initialize(Mapper, Parameters, []interface{}{}).(helpers.AuxiliaryKeeper), + } + + return context, keepers, Mapper, Parameters +} + +func Test_auxiliaryKeeper_Help(t *testing.T) { + context, _, Mapper, _ := createTestInput(t) + type fields struct { + mapper helpers.Mapper + } + type args struct { + context types.Context + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + fields fields + args args + want helpers.AuxiliaryResponse + }{ + {"+ve", fields{Mapper}, args{context, NewAuxiliaryRequest(testClassificationID, testFromID, mutables)}, newAuxiliaryResponse(nil)}, + {"+ve Already exists", fields{Mapper}, args{context, NewAuxiliaryRequest(testClassificationID, testFromID, mutables)}, newAuxiliaryResponse(errorConstants.EntityAlreadyExists)}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryKeeper := auxiliaryKeeper{ + mapper: tt.fields.mapper, + } + if got := auxiliaryKeeper.Help(tt.args.context, tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("Help() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryKeeper_Initialize(t *testing.T) { + _, _, Mapper, Parameters := createTestInput(t) + type fields struct { + mapper helpers.Mapper + } + type args struct { + mapper helpers.Mapper + in1 helpers.Parameters + in2 []interface{} + } + tests := []struct { + name string + fields fields + args args + want helpers.Keeper + }{ + {"+ve", fields{Mapper}, args{Mapper, Parameters, []interface{}{}}, auxiliaryKeeper{Mapper}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + au := auxiliaryKeeper{ + mapper: tt.fields.mapper, + } + if got := au.Initialize(tt.args.mapper, tt.args.in1, tt.args.in2); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { + t.Errorf("Initialize() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_keeperPrototype(t *testing.T) { + tests := []struct { + name string + want helpers.AuxiliaryKeeper + }{ + {"+ve", auxiliaryKeeper{}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := keeperPrototype(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("keeperPrototype() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/super/request_test.go b/modules/maintainers/auxiliaries/super/request_test.go new file mode 100644 index 000000000..f2bf16b5c --- /dev/null +++ b/modules/maintainers/auxiliaries/super/request_test.go @@ -0,0 +1,82 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package super + +import ( + "github.com/AssetMantle/modules/schema/helpers" + "github.com/AssetMantle/modules/schema/ids" + "github.com/AssetMantle/modules/schema/qualified" + "reflect" + "testing" +) + +func TestNewAuxiliaryRequest(t *testing.T) { + type args struct { + maintainedClassificationID ids.ClassificationID + toIdentityID ids.IdentityID + maintainedMutables qualified.Mutables + } + tests := []struct { + name string + args args + want helpers.AuxiliaryRequest + }{ + {"+ve", args{testClassificationID, testFromID, mutables}, auxiliaryRequest{testClassificationID, testFromID, mutables}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewAuxiliaryRequest(tt.args.maintainedClassificationID, tt.args.toIdentityID, tt.args.maintainedMutables); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewAuxiliaryRequest() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequestFromInterface(t *testing.T) { + type args struct { + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + args args + want auxiliaryRequest + }{ + {"+ve", args{NewAuxiliaryRequest(testClassificationID, testFromID, mutables)}, auxiliaryRequest{testClassificationID, testFromID, mutables}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequest_Validate(t *testing.T) { + type fields struct { + MaintainedClassificationID ids.ClassificationID + ToIdentityID ids.IdentityID + MaintainedMutables qualified.Mutables + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + {"+ve with nil", fields{}, false}, + {"+ve", fields{testClassificationID, testFromID, mutables}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryRequest := auxiliaryRequest{ + MaintainedClassificationID: tt.fields.MaintainedClassificationID, + ToIdentityID: tt.fields.ToIdentityID, + MaintainedMutables: tt.fields.MaintainedMutables, + } + if err := auxiliaryRequest.Validate(); (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/modules/maintainers/auxiliaries/verify/request_test.go b/modules/maintainers/auxiliaries/verify/request_test.go new file mode 100644 index 000000000..eba90f266 --- /dev/null +++ b/modules/maintainers/auxiliaries/verify/request_test.go @@ -0,0 +1,92 @@ +// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors +// SPDX-License-Identifier: Apache-2.0 + +package verify + +import ( + baseData "github.com/AssetMantle/modules/schema/data/base" + "github.com/AssetMantle/modules/schema/helpers" + "github.com/AssetMantle/modules/schema/ids" + baseIDs "github.com/AssetMantle/modules/schema/ids/base" + baseLists "github.com/AssetMantle/modules/schema/lists/base" + baseProperties "github.com/AssetMantle/modules/schema/properties/base" + baseQualified "github.com/AssetMantle/modules/schema/qualified/base" + "reflect" + "testing" +) + +var ( + immutableProperty = baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("Data1")) + mutableProperty = baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("Data2")) + immutables = baseQualified.NewImmutables(baseLists.NewPropertyList(immutableProperty)) + mutables = baseQualified.NewMutables(baseLists.NewPropertyList(mutableProperty)) + classificationID = baseIDs.NewClassificationID(immutables, mutables) + identityID = baseIDs.NewIdentityID(classificationID, immutables) +) + +func TestNewAuxiliaryRequest(t *testing.T) { + type args struct { + maintainedClassificationID ids.ClassificationID + maintainedIdentityID ids.IdentityID + } + tests := []struct { + name string + args args + want helpers.AuxiliaryRequest + }{ + {"+ve", args{classificationID, identityID}, auxiliaryRequest{classificationID, identityID}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewAuxiliaryRequest(tt.args.maintainedClassificationID, tt.args.maintainedIdentityID); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewAuxiliaryRequest() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequestFromInterface(t *testing.T) { + type args struct { + request helpers.AuxiliaryRequest + } + tests := []struct { + name string + args args + want auxiliaryRequest + }{ + {"+ve", args{NewAuxiliaryRequest(classificationID, identityID)}, auxiliaryRequest{classificationID, identityID}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) { + t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_auxiliaryRequest_Validate(t *testing.T) { + type fields struct { + MaintainedClassificationID ids.ClassificationID + MaintainerIdentityID ids.IdentityID + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + {"+ve", fields{classificationID, identityID}, false}, + {"+ve", fields{}, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + auxiliaryRequest := auxiliaryRequest{ + MaintainedClassificationID: tt.fields.MaintainedClassificationID, + MaintainerIdentityID: tt.fields.MaintainerIdentityID, + } + if err := auxiliaryRequest.Validate(); (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}