Skip to content

Commit f00c00d

Browse files
authored
Merge pull request #151 from AssetMantle/0xankit/maintainerKeepers
add maintainer tests for auxiliaries
2 parents 9a6ea7a + f3e7c44 commit f00c00d

File tree

9 files changed

+1095
-0
lines changed

9 files changed

+1095
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package deputize
5+
6+
import (
7+
"fmt"
8+
"github.com/AssetMantle/modules/modules/classifications/auxiliaries/member"
9+
"github.com/AssetMantle/modules/modules/maintainers/internal/key"
10+
"github.com/AssetMantle/modules/modules/maintainers/internal/mappable"
11+
"github.com/AssetMantle/modules/modules/maintainers/internal/parameters"
12+
maintainerUtilities "github.com/AssetMantle/modules/modules/maintainers/internal/utilities"
13+
"github.com/AssetMantle/modules/schema"
14+
baseData "github.com/AssetMantle/modules/schema/data/base"
15+
baseDocuments "github.com/AssetMantle/modules/schema/documents/base"
16+
"github.com/AssetMantle/modules/schema/helpers"
17+
baseHelpers "github.com/AssetMantle/modules/schema/helpers/base"
18+
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
19+
"github.com/AssetMantle/modules/schema/lists/base"
20+
"github.com/AssetMantle/modules/schema/lists/utilities"
21+
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
22+
baseQualified "github.com/AssetMantle/modules/schema/qualified/base"
23+
"github.com/cosmos/cosmos-sdk/codec"
24+
"github.com/cosmos/cosmos-sdk/store"
25+
"github.com/cosmos/cosmos-sdk/types"
26+
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
27+
"github.com/cosmos/cosmos-sdk/x/params"
28+
"github.com/stretchr/testify/require"
29+
abciTypes "github.com/tendermint/tendermint/abci/types"
30+
"github.com/tendermint/tendermint/libs/log"
31+
tendermintDB "github.com/tendermint/tm-db"
32+
"reflect"
33+
"testing"
34+
)
35+
36+
type TestKeepers struct {
37+
DeputizeKeeper helpers.AuxiliaryKeeper
38+
}
39+
40+
var (
41+
memberAuxiliary helpers.Auxiliary
42+
immutables = baseQualified.NewImmutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID2"), baseData.NewStringData("Data2"))))
43+
mutables = baseQualified.NewMutables(base.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("Data1"))))
44+
testClassificationID = baseIDs.NewClassificationID(immutables, mutables)
45+
testFromID = baseIDs.NewIdentityID(testClassificationID, immutables)
46+
maintainedProperty = "maintainedProperty:S|maintainedProperty"
47+
maintainedProperties, _ = utilities.ReadMetaPropertyList(maintainedProperty)
48+
permissions = maintainerUtilities.SetPermissions(true, true, true, true, true, true)
49+
)
50+
51+
func createTestInput(t *testing.T) (types.Context, TestKeepers, helpers.Mapper, helpers.Parameters) {
52+
var Codec = codec.New()
53+
schema.RegisterCodec(Codec)
54+
types.RegisterCodec(Codec)
55+
codec.RegisterCrypto(Codec)
56+
codec.RegisterEvidences(Codec)
57+
vesting.RegisterCodec(Codec)
58+
Codec.Seal()
59+
60+
storeKey := types.NewKVStoreKey("test")
61+
paramsStoreKey := types.NewKVStoreKey("testParams")
62+
paramsTransientStoreKeys := types.NewTransientStoreKey("testParamsTransient")
63+
Mapper := baseHelpers.NewMapper(key.Prototype, mappable.Prototype).Initialize(storeKey)
64+
paramsKeeper := params.NewKeeper(
65+
Codec,
66+
paramsStoreKey,
67+
paramsTransientStoreKeys,
68+
)
69+
Parameters := parameters.Prototype().Initialize(paramsKeeper.Subspace("test"))
70+
71+
memDB := tendermintDB.NewMemDB()
72+
commitMultiStore := store.NewCommitMultiStore(memDB)
73+
commitMultiStore.MountStoreWithDB(storeKey, types.StoreTypeIAVL, memDB)
74+
commitMultiStore.MountStoreWithDB(paramsStoreKey, types.StoreTypeIAVL, memDB)
75+
commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, types.StoreTypeTransient, memDB)
76+
err := commitMultiStore.LoadLatestVersion()
77+
require.Nil(t, err)
78+
79+
context := types.NewContext(commitMultiStore, abciTypes.Header{
80+
ChainID: "test",
81+
}, false, log.NewNopLogger())
82+
83+
memberAuxiliary = member.AuxiliaryMock.Initialize(Mapper, Parameters)
84+
keepers := TestKeepers{
85+
DeputizeKeeper: keeperPrototype().Initialize(Mapper, Parameters, []interface{}{}).(helpers.AuxiliaryKeeper),
86+
}
87+
88+
return context, keepers, Mapper, Parameters
89+
}
90+
91+
func Test_auxiliaryKeeper_Help(t *testing.T) {
92+
context, keepers, Mapper, _ := createTestInput(t)
93+
keepers.DeputizeKeeper.(auxiliaryKeeper).mapper.NewCollection(context).Add(mappable.NewMappable(baseDocuments.NewMaintainer(testFromID, testClassificationID, maintainedProperties.GetPropertyIDList(), permissions)))
94+
type fields struct {
95+
mapper helpers.Mapper
96+
memberAuxiliary helpers.Auxiliary
97+
}
98+
type args struct {
99+
context types.Context
100+
request helpers.AuxiliaryRequest
101+
}
102+
tests := []struct {
103+
name string
104+
fields fields
105+
args args
106+
want helpers.AuxiliaryResponse
107+
}{
108+
{"+ve", fields{Mapper, memberAuxiliary}, args{context, NewAuxiliaryRequest(testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true)}, newAuxiliaryResponse(nil)},
109+
}
110+
for _, tt := range tests {
111+
t.Run(tt.name, func(t *testing.T) {
112+
auxiliaryKeeper := auxiliaryKeeper{
113+
mapper: tt.fields.mapper,
114+
memberAuxiliary: tt.fields.memberAuxiliary,
115+
}
116+
if got := auxiliaryKeeper.Help(tt.args.context, tt.args.request); !reflect.DeepEqual(got, tt.want) {
117+
t.Errorf("Help() = %v, want %v", got, tt.want)
118+
}
119+
})
120+
}
121+
}
122+
123+
func Test_auxiliaryKeeper_Initialize(t *testing.T) {
124+
_, _, Mapper, Parameters := createTestInput(t)
125+
type fields struct {
126+
mapper helpers.Mapper
127+
memberAuxiliary helpers.Auxiliary
128+
}
129+
type args struct {
130+
mapper helpers.Mapper
131+
in1 helpers.Parameters
132+
auxiliaries []interface{}
133+
}
134+
tests := []struct {
135+
name string
136+
fields fields
137+
args args
138+
want helpers.Keeper
139+
}{
140+
{"+ve", fields{Mapper, memberAuxiliary}, args{Mapper, Parameters, []interface{}{}}, auxiliaryKeeper{Mapper, memberAuxiliary}},
141+
}
142+
for _, tt := range tests {
143+
t.Run(tt.name, func(t *testing.T) {
144+
auxiliaryKeeper := auxiliaryKeeper{
145+
mapper: tt.fields.mapper,
146+
memberAuxiliary: tt.fields.memberAuxiliary,
147+
}
148+
if got := auxiliaryKeeper.Initialize(tt.args.mapper, tt.args.in1, tt.args.auxiliaries); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
149+
t.Errorf("Initialize() = %v, want %v", got, tt.want)
150+
}
151+
})
152+
}
153+
}
154+
155+
func Test_keeperPrototype(t *testing.T) {
156+
tests := []struct {
157+
name string
158+
want helpers.AuxiliaryKeeper
159+
}{
160+
{"+ve", auxiliaryKeeper{}},
161+
}
162+
for _, tt := range tests {
163+
t.Run(tt.name, func(t *testing.T) {
164+
if got := keeperPrototype(); !reflect.DeepEqual(got, tt.want) {
165+
t.Errorf("keeperPrototype() = %v, want %v", got, tt.want)
166+
}
167+
})
168+
}
169+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package deputize
5+
6+
import (
7+
"github.com/AssetMantle/modules/schema/helpers"
8+
"github.com/AssetMantle/modules/schema/ids"
9+
"github.com/AssetMantle/modules/schema/lists"
10+
"reflect"
11+
"testing"
12+
)
13+
14+
func TestNewAuxiliaryRequest(t *testing.T) {
15+
type args struct {
16+
fromID ids.IdentityID
17+
toID ids.IdentityID
18+
maintainedClassificationID ids.ClassificationID
19+
maintainedProperties lists.PropertyList
20+
canMintAsset bool
21+
canBurnAsset bool
22+
canRenumerateAsset bool
23+
canAddMaintainer bool
24+
canRemoveMaintainer bool
25+
canMutateMaintainer bool
26+
}
27+
tests := []struct {
28+
name string
29+
args args
30+
want helpers.AuxiliaryRequest
31+
}{
32+
{"+ve", args{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}, auxiliaryRequest{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}},
33+
{"+ve with nil", args{}, auxiliaryRequest{}},
34+
}
35+
for _, tt := range tests {
36+
t.Run(tt.name, func(t *testing.T) {
37+
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) {
38+
t.Errorf("NewAuxiliaryRequest() = %v, want %v", got, tt.want)
39+
}
40+
})
41+
}
42+
}
43+
44+
func Test_auxiliaryRequestFromInterface(t *testing.T) {
45+
type args struct {
46+
request helpers.AuxiliaryRequest
47+
}
48+
tests := []struct {
49+
name string
50+
args args
51+
want auxiliaryRequest
52+
}{
53+
{"+ve", args{NewAuxiliaryRequest(testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true)}, auxiliaryRequest{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}},
54+
}
55+
for _, tt := range tests {
56+
t.Run(tt.name, func(t *testing.T) {
57+
if got := auxiliaryRequestFromInterface(tt.args.request); !reflect.DeepEqual(got, tt.want) {
58+
t.Errorf("auxiliaryRequestFromInterface() = %v, want %v", got, tt.want)
59+
}
60+
})
61+
}
62+
}
63+
64+
func Test_auxiliaryRequest_Validate(t *testing.T) {
65+
type fields struct {
66+
FromID ids.IdentityID
67+
ToID ids.IdentityID
68+
MaintainedClassificationID ids.ClassificationID
69+
MaintainedProperties lists.PropertyList
70+
CanMintAsset bool
71+
CanBurnAsset bool
72+
CanRenumerateAsset bool
73+
CanAddMaintainer bool
74+
CanRemoveMaintainer bool
75+
CanMutateMaintainer bool
76+
}
77+
tests := []struct {
78+
name string
79+
fields fields
80+
wantErr bool
81+
}{
82+
{"+ve", fields{testFromID, testFromID, testClassificationID, maintainedProperties, true, true, true, true, true, true}, false},
83+
}
84+
for _, tt := range tests {
85+
t.Run(tt.name, func(t *testing.T) {
86+
auxiliaryRequest := auxiliaryRequest{
87+
FromID: tt.fields.FromID,
88+
ToID: tt.fields.ToID,
89+
MaintainedClassificationID: tt.fields.MaintainedClassificationID,
90+
MaintainedProperties: tt.fields.MaintainedProperties,
91+
CanMintAsset: tt.fields.CanMintAsset,
92+
CanBurnAsset: tt.fields.CanBurnAsset,
93+
CanRenumerateAsset: tt.fields.CanRenumerateAsset,
94+
CanAddMaintainer: tt.fields.CanAddMaintainer,
95+
CanRemoveMaintainer: tt.fields.CanRemoveMaintainer,
96+
CanMutateMaintainer: tt.fields.CanMutateMaintainer,
97+
}
98+
if err := auxiliaryRequest.Validate(); (err != nil) != tt.wantErr {
99+
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
100+
}
101+
})
102+
}
103+
}

0 commit comments

Comments
 (0)