Skip to content

Commit

Permalink
Merge pull request #151 from AssetMantle/0xankit/maintainerKeepers
Browse files Browse the repository at this point in the history
add maintainer tests for auxiliaries
  • Loading branch information
deepanshutr authored Dec 1, 2022
2 parents 9a6ea7a + f3e7c44 commit f00c00d
Show file tree
Hide file tree
Showing 9 changed files with 1,095 additions and 0 deletions.
169 changes: 169 additions & 0 deletions modules/maintainers/auxiliaries/deputize/keeper_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
103 changes: 103 additions & 0 deletions modules/maintainers/auxiliaries/deputize/request_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading

0 comments on commit f00c00d

Please sign in to comment.