From 6ae05a2f18824b2a49ebfb3ade3fb37feacc2a76 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 23 Jul 2024 12:16:51 +0530 Subject: [PATCH 01/21] mint tk test cases fix v1 --- go.mod | 2 +- go.sum | 1 - x/assets/transactions/mint/message.go | 4 +- x/assets/transactions/mint/message_test.go | 8 +- .../mint/transaction_keeper_test.go | 408 ++++++++++++------ .../transactions/mint/transaction_request.go | 4 +- .../mint/transaction_request_test.go | 6 +- 7 files changed, 279 insertions(+), 154 deletions(-) diff --git a/go.mod b/go.mod index 5d06fce12..9bb027094 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( google.golang.org/grpc v1.62.1 ) -//replace github.com/AssetMantle/schema => ../schema +replace github.com/AssetMantle/schema => ../schema require ( cloud.google.com/go v0.112.0 // indirect diff --git a/go.sum b/go.sum index d16e1ca8b..1d8dbcb6f 100644 --- a/go.sum +++ b/go.sum @@ -209,7 +209,6 @@ git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFN git.sr.ht/~sircmpwn/go-bare v0.0.0-20210406120253-ab86bc2846d9/go.mod h1:BVJwbDfVjCjoFiKrhkei6NdGcZYpkDkdyCdg1ukytRA= 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/AssetMantle/schema v0.0.0-20240206102051-27352b802163/go.mod h1:SindcyQCFIEKPOp4mNrnegXrJ2uwQfq3D1r+G93Gz3Q= 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= diff --git a/x/assets/transactions/mint/message.go b/x/assets/transactions/mint/message.go index 9ab1d900e..d6283a62d 100644 --- a/x/assets/transactions/mint/message.go +++ b/x/assets/transactions/mint/message.go @@ -9,7 +9,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists" baseLists "github.com/AssetMantle/schema/lists/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -60,7 +60,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/mint/message_test.go b/x/assets/transactions/mint/message_test.go index f6e2bf3e0..fa8353995 100644 --- a/x/assets/transactions/mint/message_test.go +++ b/x/assets/transactions/mint/message_test.go @@ -4,6 +4,7 @@ package mint import ( + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "reflect" "testing" @@ -14,7 +15,6 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" - "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -111,15 +111,15 @@ func Test_message_GetSigners(t *testing.T) { func Test_message_RegisterCodec(t *testing.T) { type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve with nil", fields{}, args{codec.NewLegacyAmino()}}, - {"+ve", fields{fromAccAddress.String(), fromID, fromID, classificationID, immutableMetaProperties, immutableProperties, mutableMetaProperties, mutableProperties}, args{codec.NewLegacyAmino()}}, + {"+ve with nil", fields{}, args{sdkCodec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, fromID, classificationID, immutableMetaProperties, immutableProperties, mutableMetaProperties, mutableProperties}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/mint/transaction_keeper_test.go b/x/assets/transactions/mint/transaction_keeper_test.go index 54991a4ff..0bdfb3cfc 100644 --- a/x/assets/transactions/mint/transaction_keeper_test.go +++ b/x/assets/transactions/mint/transaction_keeper_test.go @@ -7,198 +7,324 @@ import ( "context" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/modules/x/assets/constants" + "github.com/AssetMantle/modules/x/assets/key" "github.com/AssetMantle/modules/x/assets/mapper" "github.com/AssetMantle/modules/x/assets/parameters" - "github.com/AssetMantle/modules/x/assets/record" "github.com/AssetMantle/modules/x/classifications/auxiliaries/bond" "github.com/AssetMantle/modules/x/classifications/auxiliaries/conform" "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/authorize" + "github.com/AssetMantle/modules/x/orders/record" "github.com/AssetMantle/modules/x/splits/auxiliaries/mint" baseData "github.com/AssetMantle/schema/data/base" - "github.com/AssetMantle/schema/documents/base" + baseDocuments "github.com/AssetMantle/schema/documents/base" + "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" + "github.com/AssetMantle/schema/lists" baseLists "github.com/AssetMantle/schema/lists/base" + "github.com/AssetMantle/schema/parameters/base" baseProperties "github.com/AssetMantle/schema/properties/base" + constantProperties "github.com/AssetMantle/schema/properties/constants" baseQualified "github.com/AssetMantle/schema/qualified/base" tendermintDB "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - "github.com/stretchr/testify/require" + paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/mock" "reflect" "testing" ) -var ( - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - bondAuxiliary helpers.Auxiliary - conformAuxiliary helpers.Auxiliary - mintAuxiliary helpers.Auxiliary -) +// start +type MockAuxiliary struct { + mock.Mock +} -type TestKeepers struct { - MintKeeper helpers.TransactionKeeper +var _ helpers.Auxiliary = (*MockAuxiliary)(nil) + +func (mockAuxiliary *MockAuxiliary) GetName() string { panic(mockAuxiliary) } +func (mockAuxiliary *MockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper { + args := mockAuxiliary.Called() + return args.Get(0).(helpers.AuxiliaryKeeper) +} +func (mockAuxiliary *MockAuxiliary) Initialize(_ helpers.Mapper, _ helpers.ParameterManager, _ ...interface{}) helpers.Auxiliary { + panic(mockAuxiliary) } -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() +type MockAuxiliaryKeeper struct { + mock.Mock +} - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - codec := baseHelpers.TestCodec() - ParamsKeeper := paramsKeeper.NewKeeper( +var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) + +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, request) + return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) +} +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(m2, manager, i) + return args.Get(0).(helpers.Keeper) +} + +const ( + TestMinterModuleName = "testMinter" + Denom = "stake" + ChainID = "testChain" + GenesisSupply = 1000000000000 +) + +var ( + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) + authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authorizeAuxiliaryFailureClassificationID = baseIDs.NewClassificationID(baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList())) + _ = authorizeAuxiliaryKeeper.On("Help", mock.Anything, authorize.NewAuxiliaryRequest(authorizeAuxiliaryFailureClassificationID, baseIDs.PrototypeIdentityID(), baseIDs.NewStringID(""))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authorizeAuxiliary = new(MockAuxiliary) + _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) + mintAuxiliaryKeeper = new(MockAuxiliaryKeeper) + mintAuxiliaryFailureID = baseIDs.NewIdentityID(baseIDs.NewClassificationID(baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(1)))))), baseQualified.NewImmutables(baseLists.NewPropertyList())) + _ = mintAuxiliaryKeeper.On("Help", mock.Anything, mint.NewAuxiliaryRequest(mintAuxiliaryFailureID, baseDocuments.NewCoinAsset(Denom).GetCoinAssetID(), sdkTypes.OneInt())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = mintAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + mintAuxiliary = new(MockAuxiliary) + _ = mintAuxiliary.On("GetKeeper").Return(mintAuxiliaryKeeper) + bondAuxiliaryKeeper = new(MockAuxiliaryKeeper) + bondAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = bondAuxiliaryKeeper.On("Help", mock.Anything, bond.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), bondAuxiliaryFailureAddress, sdkTypes.OneInt())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = bondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + _ = bondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + bondAuxiliary = new(MockAuxiliary) + _ = bondAuxiliary.On("GetKeeper").Return(bondAuxiliaryKeeper) + conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) + conformAuxiliaryFailureID = baseIDs.PrototypeClassificationID() + _ = conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(conformAuxiliaryFailureID, baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + conformAuxiliary = new(MockAuxiliary) + _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) + + codec = baseHelpers.TestCodec() + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) + paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) + ParamsKeeper = paramsKeeper.NewKeeper( codec, - legacyAmino, + codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys, ) - parameterManager := parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) + authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) + moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) - Context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) + bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) + blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) - authorizeAuxiliary = authorize.Auxiliary.Initialize(Mapper, parameterManager) - authenticateAuxiliary = authenticate.Auxiliary.Initialize(Mapper, parameterManager) - bondAuxiliary = bond.Auxiliary.Initialize(Mapper, parameterManager) - conformAuxiliary = conform.Auxiliary.Initialize(Mapper, parameterManager) - mintAuxiliary = mint.Auxiliary.Initialize(Mapper, parameterManager) + Context = setContext() - keepers := TestKeepers{ - MintKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.TransactionKeeper), - } + coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) + _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) - return Context, keepers, Mapper, parameterManager -} + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) + //parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) + parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) -func Test_keeperPrototype(t *testing.T) { - tests := []struct { - name string - want helpers.TransactionKeeper - }{ - {"+ve", transactionKeeper{}}, - } - 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) - } - }) + TransactionKeeper = transactionKeeper{ + mapper: mapper.Prototype().Initialize(moduleStoreKey), + parameterManager: parameterManager, + authenticateAuxiliary: authenticateAuxiliary, + authorizeAuxiliary: authorizeAuxiliary, + bondAuxiliary: bondAuxiliary, + conformAuxiliary: conformAuxiliary, + mintAuxiliary: mintAuxiliary, } +) + +func setContext() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(authStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(bankStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) } -// func Test_transactionKeeper_Initialize(t *testing.T) { -// _, _, mapper, parameterManager := createTestInput(t) -// type fields struct { -// mapper helpers.Mapper -// parameterManager helpers.ParameterManager -// conformAuxiliary helpers.Auxiliary -// mintAuxiliary helpers.Auxiliary -// authenticateAuxiliary helpers.Auxiliary -// authorizeAuxiliary helpers.Auxiliary -// } -// type args struct { -// mapper helpers.Mapper -// parameterManager helpers.ParameterManager -// auxiliaries []interface{} -// } -// tests := []struct { -// name string -// fields fields -// args args -// want helpers.Keeper -// }{ -// {"+ve", fields{Mapper, Parameters, conformAuxiliary, mintAuxiliary, authenticateAuxiliary, authorizeAuxiliary}, args{Mapper, Parameters, []interface{}{}}, transactionKeeper{Mapper, Parameters, conformAuxiliary, mintAuxiliary, authenticateAuxiliary, authorizeAuxiliary}}, -// } -// for _, tt := range tests { -// t.Run(tt.name, func(t *testing.T) { -// transactionKeeper := transactionKeeper{ -// mapper: tt.fields.mapper, -// parameterManager: tt.fields.parameterManager, -// conformAuxiliary: tt.fields.conformAuxiliary, -// mintAuxiliary: tt.fields.mintAuxiliary, -// authenticateAuxiliary: tt.fields.authenticateAuxiliary, -// authorizeAuxiliary: tt.fields.authorizeAuxiliary, -// } -// if got := transactionKeeper.Initialize(tt.args.mapper, tt.args.parameterManager, tt.args.auxiliaries); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { -// t.Errorf("Initialize() = %v, want %v", got, tt.want) -// } -// }) -// } -// } - -func Test_transactionKeeper_Transact(t *testing.T) { - Context, keepers, Mapper, parameterManager := createTestInput(t) - immutableProperties := baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData"))) - immutableMetaProperties := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData"))) - immutables := baseQualified.NewImmutables(immutableMetaProperties) - mutableProperties := baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())) - mutableMetaProperties := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())) - mutables := baseQualified.NewMutables(mutableMetaProperties) - classificationID := baseIDs.NewClassificationID(immutables, mutables) - testAsset := base.NewAsset(classificationID, immutables, mutables) - fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c" - fromAccAddress, err := sdkTypes.AccAddressFromBech32(fromAddress) - require.Nil(t, err) - fromID := baseIDs.NewIdentityID(classificationID, immutables) - keepers.MintKeeper.(transactionKeeper).mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(record.NewRecord(testAsset)) - - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - bondAuxiliary helpers.Auxiliary - conformAuxiliary helpers.Auxiliary - mintAuxiliary helpers.Auxiliary - } +func TestTransactionKeeperTransact(t *testing.T) { + type args struct { - context context.Context - message helpers.Message + from sdkTypes.AccAddress + fromID ids.IdentityID + toID ids.IdentityID + classificationID ids.ClassificationID + immutableProps lists.PropertyList + mutableProps lists.PropertyList } tests := []struct { name string - fields fields args args - want helpers.TransactionResponse - wantErr bool + setup func(*testing.T) + want *TransactionResponse + wantErr helpers.Error }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, bondAuxiliary, conformAuxiliary, mintAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, fromID, classificationID, immutableMetaProperties, immutableProperties, mutableMetaProperties, mutableProperties).(*Message)}, newTransactionResponse(nil), false}, - {"+ve Entity Already Exists", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, bondAuxiliary, conformAuxiliary, mintAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, fromID, classificationID, immutableMetaProperties, immutableProperties, mutableMetaProperties, mutableProperties).(*Message)}, newTransactionResponse(nil), false}, + { + name: "minting not enabled", + args: args{ + from: genesisAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func(t *testing.T) { + parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(false))))) + }, + wantErr: errorConstants.NotAuthorized, + }, + { + name: "authorization failure", + args: args{ + from: genesisAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: authorizeAuxiliaryFailureClassificationID, + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func(t *testing.T) { + parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))) + }, + wantErr: errorConstants.MockError, + }, + { + name: "authentication failure", + args: args{ + from: authenticateAuxiliaryFailureAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func(t *testing.T) {}, + wantErr: errorConstants.MockError, + }, + { + name: "asset already exists", + args: args{ + from: genesisAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + immutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewStringData("val1"))), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func(t *testing.T) { + assetID := baseIDs.NewAssetID(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewStringData("val1"))))) + assets := TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Fetch(key.NewKey(assetID)) + assets.Add(record.NewRecord( + baseDocuments.NewOrder(baseIDs.PrototypeClassificationID(), + baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewStringData("val1")))), + baseQualified.NewMutables(baseLists.NewPropertyList())))) + }, + wantErr: errorConstants.EntityAlreadyExists, + }, + { + name: "conform auxiliary failure", + args: args{ + from: genesisAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: conformAuxiliaryFailureID, + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func(t *testing.T) {}, + wantErr: errorConstants.MockError, + }, + { + name: "asset supply negative", + args: args{ + from: genesisAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(-1)))), + }, + setup: func(t *testing.T) {}, + wantErr: errorConstants.IncorrectFormat, + }, + { + name: "bond auxiliary failure", + args: args{ + from: bondAuxiliaryFailureAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(1)))), + }, + setup: func(t *testing.T) { + }, + wantErr: errorConstants.MockError, + }, + { + name: "no bond amount property", + args: args{ + from: genesisAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewNumberData(sdkTypes.NewInt(1)))), + }, + setup: func(t *testing.T) {}, + wantErr: errorConstants.MetaDataError, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - parameterManager: tt.fields.parameterManager, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - authorizeAuxiliary: tt.fields.authorizeAuxiliary, - bondAuxiliary: tt.fields.bondAuxiliary, - conformAuxiliary: tt.fields.conformAuxiliary, - mintAuxiliary: tt.fields.mintAuxiliary, - } - got, err := transactionKeeper.Transact(tt.args.context, tt.args.message) - if (err != nil) != tt.wantErr { - t.Errorf("Transact() error = %v, wantErr %v", err, tt.wantErr) - return + + tt.setup(t) + //fmt.Print(tt.args.classificationID) + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), NewMessage( + tt.args.from, + baseIDs.PrototypeIdentityID(), + tt.args.toID, + tt.args.classificationID, + baseLists.NewPropertyList(), + tt.args.immutableProps, + baseLists.NewPropertyList(), + tt.args.mutableProps, + ).(helpers.Message)) + + if (err != nil) && !tt.wantErr.Is(err) { + t.Errorf("unexpected error: %v", err) } + if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Transact() got = %v, want %v", got, tt.want) + t.Error("unexpected response") } }) } diff --git a/x/assets/transactions/mint/transaction_request.go b/x/assets/transactions/mint/transaction_request.go index 0afdb9c80..b31323164 100644 --- a/x/assets/transactions/mint/transaction_request.go +++ b/x/assets/transactions/mint/transaction_request.go @@ -12,7 +12,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -127,7 +127,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { mutableProperties, ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/assets/transactions/mint/transaction_request_test.go b/x/assets/transactions/mint/transaction_request_test.go index d0388e366..80964b396 100644 --- a/x/assets/transactions/mint/transaction_request_test.go +++ b/x/assets/transactions/mint/transaction_request_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "github.com/AssetMantle/modules/utilities/rest" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "reflect" "testing" @@ -15,7 +16,6 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -276,14 +276,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { MutableProperties string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), classificationID.AsString(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), classificationID.AsString(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 541804e03753548485fa4ac8b641b8d220feb617 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Thu, 25 Jul 2024 16:59:24 +0530 Subject: [PATCH 02/21] define tk test cases fix --- x/assets/transactions/define/message.go | 4 +- x/assets/transactions/define/message_test.go | 6 +- .../define/transaction_keeper_test.go | 342 +++++++++++------- .../define/transaction_request.go | 4 +- .../define/transaction_request_test.go | 6 +- x/assets/transactions/send/message.go | 4 +- .../send/transaction_keeper_test.go | 3 +- .../transactions/send/transaction_request.go | 4 +- .../auxiliaries/define/auxiliary_keeper.go | 4 +- .../auxiliaries/define/auxiliary_response.go | 2 +- .../define/auxiliary_response_test.go | 8 +- 11 files changed, 228 insertions(+), 159 deletions(-) diff --git a/x/assets/transactions/define/message.go b/x/assets/transactions/define/message.go index 7a7e2af6e..020db6f25 100644 --- a/x/assets/transactions/define/message.go +++ b/x/assets/transactions/define/message.go @@ -9,7 +9,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists" baseLists "github.com/AssetMantle/schema/lists/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -54,7 +54,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/define/message_test.go b/x/assets/transactions/define/message_test.go index 06fcfd453..eb3843e55 100644 --- a/x/assets/transactions/define/message_test.go +++ b/x/assets/transactions/define/message_test.go @@ -14,7 +14,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -107,14 +107,14 @@ func Test_message_GetSigners(t *testing.T) { func Test_message_RegisterCodec(t *testing.T) { type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress.String(), fromID, immutableMetaProperties, immutableProperties, mutableMetaProperties, mutableProperties}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, immutableMetaProperties, immutableProperties, mutableMetaProperties, mutableProperties}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/define/transaction_keeper_test.go b/x/assets/transactions/define/transaction_keeper_test.go index 3630a4d4c..0de840e37 100644 --- a/x/assets/transactions/define/transaction_keeper_test.go +++ b/x/assets/transactions/define/transaction_keeper_test.go @@ -5,18 +5,31 @@ package define import ( "context" - "fmt" - "github.com/AssetMantle/modules/x/assets/record" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/modules/x/assets/constants" + "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" + "github.com/AssetMantle/modules/x/maintainers/auxiliaries/super" + "github.com/AssetMantle/schema/ids" + "github.com/AssetMantle/schema/lists" + "github.com/AssetMantle/schema/parameters/base" + constantProperties "github.com/AssetMantle/schema/properties/constants" + baseQualified "github.com/AssetMantle/schema/qualified/base" + "github.com/cometbft/cometbft/crypto/ed25519" storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "reflect" + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" + paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/mock" + "math/rand" "testing" baseData "github.com/AssetMantle/schema/data/base" - "github.com/AssetMantle/schema/documents/base" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" - baseQualified "github.com/AssetMantle/schema/qualified/base" tendermintDB "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" @@ -27,165 +40,220 @@ import ( "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" + dataHelper "github.com/AssetMantle/modules/simulation/schema/types/base" "github.com/AssetMantle/modules/x/assets/mapper" "github.com/AssetMantle/modules/x/assets/parameters" + permissionHelper "github.com/AssetMantle/modules/x/assets/utilities" "github.com/AssetMantle/modules/x/classifications/auxiliaries/define" - "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" - "github.com/AssetMantle/modules/x/maintainers/auxiliaries/super" ) -var ( - defineAuxiliary helpers.Auxiliary - superAuxiliary helpers.Auxiliary - authenticateAuxiliary helpers.Auxiliary -) +type MockAuxiliary struct { + mock.Mock +} -type TestKeepers struct { - BurnKeeper helpers.TransactionKeeper +var _ helpers.Auxiliary = (*MockAuxiliary)(nil) + +func (mockAuxiliary *MockAuxiliary) GetName() string { panic(mockAuxiliary) } +func (mockAuxiliary *MockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper { + args := mockAuxiliary.Called() + return args.Get(0).(helpers.AuxiliaryKeeper) +} +func (mockAuxiliary *MockAuxiliary) Initialize(_ helpers.Mapper, _ helpers.ParameterManager, _ ...interface{}) helpers.Auxiliary { + panic(mockAuxiliary) } -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() - - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - codec := baseHelpers.TestCodec() - PramsKeeper := paramsKeeper.NewKeeper( - codec, - legacyAmino, - paramsStoreKey, - paramsTransientStoreKeys, - ) - parameterManager := parameters.Prototype().Initialize(PramsKeeper.Subspace("test")) +type MockAuxiliaryKeeper struct { + mock.Mock +} - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) +var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) - Context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, request) + return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) +} +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(m2, manager, i) + return args.Get(0).(helpers.Keeper) +} - defineAuxiliary = define.Auxiliary.Initialize(Mapper, parameterManager) - superAuxiliary = super.Auxiliary.Initialize(Mapper, parameterManager) - authenticateAuxiliary = authenticate.Auxiliary.Initialize(Mapper, parameterManager) +const ( + TestMinterModuleName = "testMinter" + Denom = "stake" + ChainID = "testChain" + GenesisSupply = 1000000000000 +) - keepers := TestKeepers{ - BurnKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.TransactionKeeper), - } +var ( + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - return Context, keepers, Mapper, parameterManager -} + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) -func Test_keeperPrototype(t *testing.T) { - tests := []struct { - name string - want helpers.TransactionKeeper - }{ - {"+ve", transactionKeeper{}}, - } - 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) - } - }) - } -} + defineAuxiliaryKeeper = new(MockAuxiliaryKeeper) + defineAuxiliaryKeeperFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = defineAuxiliaryKeeper.On("Help", mock.Anything, define.NewAuxiliaryRequest(defineAuxiliaryKeeperFailureAddress, baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = defineAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(define.NewAuxiliaryResponse(baseIDs.PrototypeClassificationID()), nil) + defineAuxiliary = new(MockAuxiliary) + _ = defineAuxiliary.On("GetKeeper").Return(defineAuxiliaryKeeper) -func Test_transactionKeeper_Initialize(t *testing.T) { - _, _, Mapper, parameterManager := createTestInput(t) - type fields struct { - mapper helpers.Mapper - defineAuxiliary helpers.Auxiliary - superAuxiliary helpers.Auxiliary - authenticateAuxiliary helpers.Auxiliary - } - type args struct { - mapper helpers.Mapper - in1 helpers.ParameterManager - auxiliaries []interface{} - } - tests := []struct { - name string - fields fields - args args - want helpers.Keeper - }{ - {"+ve", fields{Mapper, defineAuxiliary, superAuxiliary, authenticateAuxiliary}, args{Mapper, parameterManager, []interface{}{}}, transactionKeeper{Mapper, defineAuxiliary, superAuxiliary, authenticateAuxiliary}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - defineAuxiliary: tt.fields.defineAuxiliary, - superAuxiliary: tt.fields.superAuxiliary, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - } - if got := transactionKeeper.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) - } - }) + superAuxiliaryKeeper = new(MockAuxiliaryKeeper) + superAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) + _ = superAuxiliaryKeeper.On("Help", mock.Anything, super.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), baseIDs.PrototypeIdentityID(), baseQualified.NewMutables(superAuxiliaryMutablesFailure), permissionHelper.SetModulePermissions(true, true, true)...)).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = superAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + superAuxiliary = new(MockAuxiliary) + _ = superAuxiliary.On("GetKeeper").Return(superAuxiliaryKeeper) + + codec = baseHelpers.TestCodec() + + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) + paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) + + authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) + moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) + blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + Context = setContext() + + coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) + _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) + + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) + + parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) + TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), + defineAuxiliary, + superAuxiliary, + authenticateAuxiliary, } +) + +func setContext() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(authStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(bankStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) } -func Test_transactionKeeper_Transact(t *testing.T) { - Context, keepers, Mapper, _ := createTestInput(t) - immutablePropertiesLists := baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData"))) - immutableMetaPropertiesLists := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData"))) - immutables := baseQualified.NewImmutables(immutableMetaPropertiesLists) - mutablePropertiesLists := baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())) - mutableMetaPropertiesLists := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())) - mutables := baseQualified.NewMutables(mutableMetaPropertiesLists) - classificationID := baseIDs.NewClassificationID(immutables, mutables) - // testAssetID := baseIDs.NewAssetID(classificationID, immutables) - testAsset := base.NewAsset(classificationID, immutables, mutables) - fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c" - fromAccAddress, err := sdkTypes.AccAddressFromBech32(fromAddress) - require.Nil(t, err) - fromID := baseIDs.NewIdentityID(classificationID, immutables) - keepers.BurnKeeper.(transactionKeeper).mapper.NewCollection(Context.Context()).Add(record.NewRecord(testAsset)) - - type fields struct { - mapper helpers.Mapper - defineAuxiliary helpers.Auxiliary - superAuxiliary helpers.Auxiliary - authenticateAuxiliary helpers.Auxiliary - } +func TestTransactionKeeperTransact(t *testing.T) { type args struct { - context context.Context - message helpers.Message + from sdkTypes.AccAddress + fromID ids.IdentityID + immutableMetaProps lists.PropertyList + immutableProps lists.PropertyList + mutableMetaProps lists.PropertyList + mutableProps lists.PropertyList } + tests := []struct { name string - fields fields args args - want helpers.TransactionResponse - wantErr bool + setup func() + want *TransactionResponse + wantErr helpers.Error }{ - {"+ve", fields{Mapper, defineAuxiliary, superAuxiliary, authenticateAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, immutableMetaPropertiesLists, immutablePropertiesLists, mutableMetaPropertiesLists, mutablePropertiesLists).(*Message)}, newTransactionResponse(nil), false}, + { + name: "Positive Case", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + immutableMetaProps: baseLists.NewPropertyList(), + immutableProps: baseLists.NewPropertyList(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func() { + }, + want: newTransactionResponse(baseIDs.PrototypeClassificationID()), + wantErr: nil, + }, + { + name: "Authentication Failure", + args: args{ + from: authenticateAuxiliaryFailureAddress, + fromID: baseIDs.PrototypeIdentityID(), + immutableMetaProps: baseLists.NewPropertyList(), + immutableProps: baseLists.NewPropertyList(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func() { + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "Define Auxiliary Failure", + args: args{ + from: defineAuxiliaryKeeperFailureAddress, + fromID: baseIDs.PrototypeIdentityID(), + immutableMetaProps: baseLists.NewPropertyList(), + immutableProps: baseLists.NewPropertyList(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func() { + + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "Super Auxiliary Failure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + immutableMetaProps: baseLists.NewPropertyList(), + immutableProps: baseLists.NewPropertyList(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: superAuxiliaryMutablesFailure, + }, + setup: func() { + + }, + want: nil, + wantErr: errorConstants.MockError, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - defineAuxiliary: tt.fields.defineAuxiliary, - superAuxiliary: tt.fields.superAuxiliary, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - } - got, err := transactionKeeper.Transact(tt.args.context, tt.args.message) - if (err != nil) != tt.wantErr { - t.Errorf("Transact() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Transact() got = %v, want %v", got, tt.want) + tt.setup() + + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), + NewMessage(tt.args.from, + tt.args.fromID, + tt.args.immutableMetaProps.(lists.PropertyList), + tt.args.immutableProps.(lists.PropertyList), + tt.args.mutableMetaProps.(lists.PropertyList), + tt.args.mutableProps.(lists.PropertyList)).(helpers.Message)) + + if tt.wantErr != nil { + require.Error(t, err) + require.Equal(t, tt.wantErr, err) + } else { + require.NoError(t, err) + require.Equal(t, tt.want, got) } }) } diff --git a/x/assets/transactions/define/transaction_request.go b/x/assets/transactions/define/transaction_request.go index d80521ed5..87c33eaf2 100644 --- a/x/assets/transactions/define/transaction_request.go +++ b/x/assets/transactions/define/transaction_request.go @@ -12,7 +12,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -111,7 +111,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { mutableProperties, ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/assets/transactions/define/transaction_request_test.go b/x/assets/transactions/define/transaction_request_test.go index 495748c18..d5b762988 100644 --- a/x/assets/transactions/define/transaction_request_test.go +++ b/x/assets/transactions/define/transaction_request_test.go @@ -15,7 +15,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -254,14 +254,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { MutableProperties string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/send/message.go b/x/assets/transactions/send/message.go index 9b7f2b8f0..7347beb20 100644 --- a/x/assets/transactions/send/message.go +++ b/x/assets/transactions/send/message.go @@ -8,7 +8,7 @@ import ( codecUtilities "github.com/AssetMantle/schema/codec/utilities" "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -60,7 +60,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 718661e1c..962e5d454 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -270,7 +270,8 @@ func TestTransactionKeeperTransact(t *testing.T) { }, nil, errorConstants.MockError, - }, { + }, + { "transferAuxiliaryFailure", args{fromAddress, transferAuxiliaryFailureAssetID, 1}, func() { diff --git a/x/assets/transactions/send/transaction_request.go b/x/assets/transactions/send/transaction_request.go index e29953a7b..e79b71c56 100644 --- a/x/assets/transactions/send/transaction_request.go +++ b/x/assets/transactions/send/transaction_request.go @@ -11,7 +11,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -100,7 +100,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { value, ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/classifications/auxiliaries/define/auxiliary_keeper.go b/x/classifications/auxiliaries/define/auxiliary_keeper.go index e878f74e7..8e3f67836 100644 --- a/x/classifications/auxiliaries/define/auxiliary_keeper.go +++ b/x/classifications/auxiliaries/define/auxiliary_keeper.go @@ -78,7 +78,7 @@ func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRe classificationID := baseIDs.NewClassificationID(auxiliaryRequest.Immutables, auxiliaryRequest.Mutables) classifications := auxiliaryKeeper.mapper.NewCollection(context).Fetch(key.NewKey(classificationID)) if classifications.GetMappable(key.NewKey(classificationID)) != nil { - return newAuxiliaryResponse(classificationID), errorConstants.EntityAlreadyExists.Wrapf("classification with ID %s already exists", classificationID.AsString()) + return NewAuxiliaryResponse(classificationID), errorConstants.EntityAlreadyExists.Wrapf("classification with ID %s already exists", classificationID.AsString()) } if err := auxiliaryKeeper.bankKeeper.SendCoinsFromAccountToModule(sdkTypes.UnwrapSDKContext(context), auxiliaryRequest.AccAddress, constants.ModuleName, sdkTypes.NewCoins(sdkTypes.NewCoin(auxiliaryKeeper.stakingKeeper.BondDenom(sdkTypes.UnwrapSDKContext(context)), bondAmount.Get()))); err != nil { @@ -93,7 +93,7 @@ func (auxiliaryKeeper auxiliaryKeeper) Help(context context.Context, AuxiliaryRe classifications.Add(record.NewRecord(classification)) - return newAuxiliaryResponse(classificationID), nil + return NewAuxiliaryResponse(classificationID), nil } func (auxiliaryKeeper auxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, auxiliaries []interface{}) helpers.Keeper { diff --git a/x/classifications/auxiliaries/define/auxiliary_response.go b/x/classifications/auxiliaries/define/auxiliary_response.go index d1c5d4161..52a35cb1e 100644 --- a/x/classifications/auxiliaries/define/auxiliary_response.go +++ b/x/classifications/auxiliaries/define/auxiliary_response.go @@ -16,7 +16,7 @@ type auxiliaryResponse struct { var _ helpers.AuxiliaryResponse = (*auxiliaryResponse)(nil) -func newAuxiliaryResponse(classificationID ids.ClassificationID) helpers.AuxiliaryResponse { +func NewAuxiliaryResponse(classificationID ids.ClassificationID) helpers.AuxiliaryResponse { return auxiliaryResponse{ ClassificationID: classificationID, } diff --git a/x/classifications/auxiliaries/define/auxiliary_response_test.go b/x/classifications/auxiliaries/define/auxiliary_response_test.go index ad27de223..e714a435d 100644 --- a/x/classifications/auxiliaries/define/auxiliary_response_test.go +++ b/x/classifications/auxiliaries/define/auxiliary_response_test.go @@ -37,8 +37,8 @@ func TestGetClassificationIDFromResponse(t *testing.T) { want ids.ClassificationID wantErr bool }{ - {"+ve", args{newAuxiliaryResponse(classificationID)}, classificationID, false}, - {"+ve", args{newAuxiliaryResponse(nil)}, nil, false}, + {"+ve", args{NewAuxiliaryResponse(classificationID)}, classificationID, false}, + {"+ve", args{NewAuxiliaryResponse(nil)}, nil, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -66,8 +66,8 @@ func Test_newAuxiliaryResponse(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := newAuxiliaryResponse(tt.args.classificationID); !reflect.DeepEqual(got, tt.want) { - t.Errorf("newAuxiliaryResponse() = %v, want %v", got, tt.want) + if got := NewAuxiliaryResponse(tt.args.classificationID); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewAuxiliaryResponse() = %v, want %v", got, tt.want) } }) } From 2acb8d720be20301b91f2ee01fdbe0011df168b3 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Fri, 26 Jul 2024 13:50:48 +0530 Subject: [PATCH 03/21] deputize tk test cases fix --- x/assets/transactions/deputize/message.go | 4 +- .../transactions/deputize/message_test.go | 8 +- .../deputize/transaction_keeper_test.go | 338 +++++++++++------- .../deputize/transaction_request.go | 4 +- .../deputize/transaction_request_test.go | 6 +- 5 files changed, 218 insertions(+), 142 deletions(-) diff --git a/x/assets/transactions/deputize/message.go b/x/assets/transactions/deputize/message.go index 91e7ebd6e..4e664c65e 100644 --- a/x/assets/transactions/deputize/message.go +++ b/x/assets/transactions/deputize/message.go @@ -9,7 +9,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists" baseLists "github.com/AssetMantle/schema/lists/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -51,7 +51,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/deputize/message_test.go b/x/assets/transactions/deputize/message_test.go index 9eaf68fd9..420554cba 100644 --- a/x/assets/transactions/deputize/message_test.go +++ b/x/assets/transactions/deputize/message_test.go @@ -14,7 +14,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -114,15 +114,15 @@ func Test_message_GetSigners(t *testing.T) { func Test_message_RegisterCodec(t *testing.T) { type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve with nil", fields{}, args{codec.NewLegacyAmino()}}, - {"+ve", fields{fromAccAddress.String(), fromID, fromID, classificationID, mutableMetaProperties, true, true, true, true, true, true}, args{codec.NewLegacyAmino()}}, + {"+ve with nil", fields{}, args{sdkCodec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, fromID, classificationID, mutableMetaProperties, true, true, true, true, true, true}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/deputize/transaction_keeper_test.go b/x/assets/transactions/deputize/transaction_keeper_test.go index 202c608e7..68bb612b6 100644 --- a/x/assets/transactions/deputize/transaction_keeper_test.go +++ b/x/assets/transactions/deputize/transaction_keeper_test.go @@ -5,180 +5,256 @@ package deputize import ( "context" - "fmt" - "github.com/AssetMantle/modules/x/assets/record" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "reflect" - "testing" - + baseHelpers "github.com/AssetMantle/modules/helpers/base" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/modules/x/assets/constants" + "github.com/AssetMantle/modules/x/assets/mapper" + "github.com/AssetMantle/modules/x/assets/parameters" + permissionHelper "github.com/AssetMantle/modules/x/assets/utilities" + "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" + "github.com/AssetMantle/modules/x/maintainers/auxiliaries/deputize" baseData "github.com/AssetMantle/schema/data/base" - "github.com/AssetMantle/schema/documents/base" + "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" + "github.com/AssetMantle/schema/parameters/base" baseProperties "github.com/AssetMantle/schema/properties/base" - baseQualified "github.com/AssetMantle/schema/qualified/base" + constantProperties "github.com/AssetMantle/schema/properties/constants" tendermintDB "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "reflect" + "testing" "github.com/AssetMantle/modules/helpers" - baseHelpers "github.com/AssetMantle/modules/helpers/base" - "github.com/AssetMantle/modules/x/assets/mapper" - "github.com/AssetMantle/modules/x/assets/parameters" - "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" - "github.com/AssetMantle/modules/x/maintainers/auxiliaries/deputize" ) -var ( - authenticateAuxiliary helpers.Auxiliary - deputizeAuxiliary helpers.Auxiliary -) +type MockAuxiliary struct { + mock.Mock +} + +var _ helpers.Auxiliary = (*MockAuxiliary)(nil) -type TestKeepers struct { - DeputizeKeeper helpers.TransactionKeeper +func (mockAuxiliary *MockAuxiliary) GetName() string { panic(mockAuxiliary) } +func (mockAuxiliary *MockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper { + args := mockAuxiliary.Called() + return args.Get(0).(helpers.AuxiliaryKeeper) +} +func (mockAuxiliary *MockAuxiliary) Initialize(_ helpers.Mapper, _ helpers.ParameterManager, _ ...interface{}) helpers.Auxiliary { + panic(mockAuxiliary) } -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() - - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - codec := baseHelpers.TestCodec() - ParamsKeeper := paramsKeeper.NewKeeper( - codec, - legacyAmino, - paramsStoreKey, - paramsTransientStoreKeys, - ) - parameterManager := parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) +type MockAuxiliaryKeeper struct { + mock.Mock +} - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) +var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) - Context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, request) + return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) +} +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(m2, manager, i) + return args.Get(0).(helpers.Keeper) +} - deputizeAuxiliary = deputize.Auxiliary.Initialize(Mapper, parameterManager) - authenticateAuxiliary = authenticate.Auxiliary.Initialize(Mapper, parameterManager) +const ( + TestMinterModuleName = "testMinter" + Denom = "stake" + ChainID = "testChain" + GenesisSupply = 1000000000000 +) - keepers := TestKeepers{ - DeputizeKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.TransactionKeeper), - } +var ( + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - return Context, keepers, Mapper, parameterManager -} + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) -func Test_keeperPrototype(t *testing.T) { - tests := []struct { - name string - want helpers.TransactionKeeper - }{ - {"+ve", transactionKeeper{}}, - } - 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) - } - }) - } + deputizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + deputizeAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = deputizeAuxiliaryKeeper.On("Help", mock.Anything, deputize.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseIDs.PrototypeIdentityID(), baseIDs.PrototypeClassificationID(), baseLists.NewPropertyList(), true, true, true, permissionHelper.SetModulePermissions(false, true, true)...)).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = deputizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + deputizeAuxiliary = new(MockAuxiliary) + _ = deputizeAuxiliary.On("GetKeeper").Return(deputizeAuxiliaryKeeper) + + codec = baseHelpers.TestCodec() + + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) + paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) + + authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) + moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) + blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + Context = setContext() + + coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) + _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) + + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) + + parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) + TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), parameterManager, authenticateAuxiliary, deputizeAuxiliary} +) + +func setContext() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(authStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(bankStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) } -func Test_transactionKeeper_Initialize(t *testing.T) { - _, _, Mapper, parameterManager := createTestInput(t) - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - deputizeAuxiliary helpers.Auxiliary - } +func TestTransactionKeeperTransact(t *testing.T) { + type args struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - auxiliaries []interface{} + from sdkTypes.AccAddress + fromID ids.IdentityID + toID ids.IdentityID + canMintAsset bool + canRenumerateAsset bool + canBurnAsset bool + canAddMaintainer bool + CanRemoveMaintainer bool + CanMutateMaintainer bool } + tests := []struct { - name string - fields fields - args args - want helpers.Keeper + name string + args args + setup func() + want *TransactionResponse + wantErr helpers.Error }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, deputizeAuxiliary}, args{Mapper, parameterManager, []interface{}{}}, transactionKeeper{Mapper, parameterManager, authenticateAuxiliary, deputizeAuxiliary}}, + { + name: "Successful Transaction", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + toID: baseIDs.PrototypeIdentityID(), + canMintAsset: true, + canRenumerateAsset: true, + canBurnAsset: true, + canAddMaintainer: true, + CanRemoveMaintainer: true, + CanMutateMaintainer: true, + }, + setup: func() { + }, + want: newTransactionResponse(), + wantErr: nil, + }, + { + name: "Authentication Failure", + args: args{ + from: authenticateAuxiliaryFailureAddress, + fromID: baseIDs.PrototypeIdentityID(), + toID: baseIDs.PrototypeIdentityID(), + canMintAsset: true, + canRenumerateAsset: true, + canBurnAsset: true, + canAddMaintainer: true, + CanRemoveMaintainer: true, + CanMutateMaintainer: true, + }, + setup: func() { + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "Deputize Failure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + toID: baseIDs.PrototypeIdentityID(), + canMintAsset: false, + canRenumerateAsset: true, + canBurnAsset: true, + canAddMaintainer: true, + CanRemoveMaintainer: true, + CanMutateMaintainer: true, + }, + setup: func() { + }, + want: nil, + wantErr: errorConstants.MockError, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - parameterManager: tt.fields.parameterManager, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - deputizeAuxiliary: tt.fields.deputizeAuxiliary, - } - if got := transactionKeeper.Initialize(tt.args.mapper, tt.args.parameterManager, tt.args.auxiliaries); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { - t.Errorf("Initialize() = %v, want %v", got, tt.want) + tt.setup() + + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), + NewMessage(tt.args.from, + tt.args.fromID, + tt.args.toID, + baseIDs.PrototypeClassificationID(), + baseLists.NewPropertyList(), + tt.args.canMintAsset, + tt.args.canRenumerateAsset, + tt.args.canBurnAsset, + tt.args.canAddMaintainer, + tt.args.CanRemoveMaintainer, + tt.args.CanMutateMaintainer).(helpers.Message)) + + if tt.wantErr != nil { + require.Error(t, err) + require.Equal(t, tt.wantErr, err) + } else { + require.NoError(t, err) + require.Equal(t, tt.want, got) } }) } } -func Test_transactionKeeper_Transact(t *testing.T) { - Context, keepers, Mapper, parameterManager := createTestInput(t) - immutableProperties := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData"))) - immutables := baseQualified.NewImmutables(immutableProperties) - mutableProperties := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())) - mutables := baseQualified.NewMutables(mutableProperties) - classificationID := baseIDs.NewClassificationID(immutables, mutables) - testAsset := base.NewAsset(classificationID, immutables, mutables) - fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c" - fromAccAddress, err := sdkTypes.AccAddressFromBech32(fromAddress) - require.Nil(t, err) - fromID := baseIDs.NewIdentityID(classificationID, immutables) - keepers.DeputizeKeeper.(transactionKeeper).mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(record.NewRecord(testAsset)) - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - deputizeAuxiliary helpers.Auxiliary - } - type args struct { - context context.Context - message helpers.Message - } +func Test_keeperPrototype(t *testing.T) { tests := []struct { - name string - fields fields - args args - want helpers.TransactionResponse - wantErr bool + name string + want helpers.TransactionKeeper }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, deputizeAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, fromID, classificationID, mutableProperties, true, true, true, true, true, true).(*Message)}, newTransactionResponse(), false}, + {"+ve", transactionKeeper{}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - parameterManager: tt.fields.parameterManager, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - deputizeAuxiliary: tt.fields.deputizeAuxiliary, - } - got, err := transactionKeeper.Transact(tt.args.context, tt.args.message) - if (err != nil) != tt.wantErr { - t.Errorf("Transact() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Transact() got = %v, want %v", got, tt.want) + if got := keeperPrototype(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("keeperPrototype() = %v, want %v", got, tt.want) } }) } diff --git a/x/assets/transactions/deputize/transaction_request.go b/x/assets/transactions/deputize/transaction_request.go index 8a6c6172f..f64f2e69f 100644 --- a/x/assets/transactions/deputize/transaction_request.go +++ b/x/assets/transactions/deputize/transaction_request.go @@ -12,7 +12,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -119,7 +119,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { transactionRequest.CanMutateMaintainer, ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/assets/transactions/deputize/transaction_request_test.go b/x/assets/transactions/deputize/transaction_request_test.go index a1187081d..2e48388c3 100644 --- a/x/assets/transactions/deputize/transaction_request_test.go +++ b/x/assets/transactions/deputize/transaction_request_test.go @@ -15,7 +15,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -303,14 +303,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { CanMutateMaintainer bool } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), classificationID.AsString(), fmt.Sprint(mutableMetaProperties), true, true, true, true, true, true}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), classificationID.AsString(), fmt.Sprint(mutableMetaProperties), true, true, true, true, true, true}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { From 8eed76c14a20478a9cf43c3829a338b5a5339d4e Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Mon, 29 Jul 2024 11:49:33 +0530 Subject: [PATCH 04/21] revoke tk test cases fix --- x/assets/transactions/mutate/message.go | 4 +- x/assets/transactions/mutate/message_test.go | 6 +- .../mutate/transaction_keeper_test.go | 286 +++++++++++----- .../mutate/transaction_request.go | 4 +- .../mutate/transaction_request_test.go | 6 +- x/assets/transactions/revoke/message.go | 4 +- x/assets/transactions/revoke/message_test.go | 6 +- .../revoke/transaction_keeper_test.go | 311 ++++++++++-------- .../revoke/transaction_request.go | 4 +- .../revoke/transaction_request_test.go | 6 +- .../send/transaction_keeper_test.go | 27 +- x/assets/transactions/unwrap/message.go | 4 +- .../unwrap/transaction_request.go | 4 +- 13 files changed, 426 insertions(+), 246 deletions(-) diff --git a/x/assets/transactions/mutate/message.go b/x/assets/transactions/mutate/message.go index 2e8319b91..85ffe12bd 100644 --- a/x/assets/transactions/mutate/message.go +++ b/x/assets/transactions/mutate/message.go @@ -9,7 +9,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists" baseLists "github.com/AssetMantle/schema/lists/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -51,7 +51,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/mutate/message_test.go b/x/assets/transactions/mutate/message_test.go index b0eae6851..32c490843 100644 --- a/x/assets/transactions/mutate/message_test.go +++ b/x/assets/transactions/mutate/message_test.go @@ -14,7 +14,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -105,14 +105,14 @@ func Test_message_GetSigners(t *testing.T) { func Test_message_RegisterCodec(t *testing.T) { type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress.String(), fromID, testAssetID, mutableMetaProperties, mutableProperties}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, testAssetID, mutableMetaProperties, mutableProperties}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/mutate/transaction_keeper_test.go b/x/assets/transactions/mutate/transaction_keeper_test.go index 3f62e4e61..134f69206 100644 --- a/x/assets/transactions/mutate/transaction_keeper_test.go +++ b/x/assets/transactions/mutate/transaction_keeper_test.go @@ -4,110 +4,244 @@ package mutate import ( - "fmt" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" - "reflect" - "testing" - + "context" + "github.com/AssetMantle/modules/helpers" + baseHelpers "github.com/AssetMantle/modules/helpers/base" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + dataHelper "github.com/AssetMantle/modules/simulation/schema/types/base" + "github.com/AssetMantle/modules/x/assets/constants" + "github.com/AssetMantle/modules/x/assets/mapper" + "github.com/AssetMantle/modules/x/classifications/auxiliaries/conform" + "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" + "github.com/AssetMantle/modules/x/maintainers/auxiliaries/maintain" + "github.com/AssetMantle/schema/ids" + baseIDs "github.com/AssetMantle/schema/ids/base" + "github.com/AssetMantle/schema/lists" + baseLists "github.com/AssetMantle/schema/lists/base" + baseQualified "github.com/AssetMantle/schema/qualified/base" tendermintDB "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "math/rand" + "testing" +) - "github.com/AssetMantle/modules/helpers" - baseHelpers "github.com/AssetMantle/modules/helpers/base" - "github.com/AssetMantle/modules/x/assets/mapper" - "github.com/AssetMantle/modules/x/assets/parameters" - "github.com/AssetMantle/modules/x/classifications/auxiliaries/conform" - "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" - "github.com/AssetMantle/modules/x/maintainers/auxiliaries/maintain" +type MockAuxiliary struct { + mock.Mock +} + +var _ helpers.Auxiliary = (*MockAuxiliary)(nil) + +func (mockAuxiliary *MockAuxiliary) GetName() string { panic(mockAuxiliary) } +func (mockAuxiliary *MockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper { + args := mockAuxiliary.Called() + return args.Get(0).(helpers.AuxiliaryKeeper) +} +func (mockAuxiliary *MockAuxiliary) Initialize(_ helpers.Mapper, _ helpers.ParameterManager, _ ...interface{}) helpers.Auxiliary { + panic(mockAuxiliary) +} + +type MockAuxiliaryKeeper struct { + mock.Mock +} + +var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) + +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, request) + return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) +} +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(m2, manager, i) + return args.Get(0).(helpers.Keeper) +} + +const ( + TestMinterModuleName = "testMinter" + Denom = "stake" + ChainID = "testChain" + GenesisSupply = 1000000000000 ) var ( - authenticateAuxiliary helpers.Auxiliary - maintainAuxiliary helpers.Auxiliary - conformAuxiliary helpers.Auxiliary -) + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) -type TestKeepers struct { - MutateKeeper helpers.TransactionKeeper -} + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - // var legacyAmino = codec.NewLegacyAmino() - // schemaCodec.RegisterLegacyAminoCodec(legacyAmino) - // std.RegisterLegacyAminoCodec(legacyAmino) - // legacyAmino.Seal() - codec := baseHelpers.CodecPrototype() - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - ParamsKeeper := paramsKeeper.NewKeeper( - codec.GetProtoCodec(), - codec.GetLegacyAmino(), - paramsStoreKey, - paramsTransientStoreKeys, - ) - parameterManager := parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) + maintainAuxiliaryKeeper = new(MockAuxiliaryKeeper) + maintainAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) + _ = maintainAuxiliaryKeeper.On("Help", mock.Anything, maintain.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), baseIDs.PrototypeIdentityID(), baseQualified.NewMutables(maintainAuxiliaryMutablesFailure))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + maintainAuxiliary = new(MockAuxiliary) + _ = maintainAuxiliary.On("GetKeeper").Return(maintainAuxiliaryKeeper) - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) + conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) + conformAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) + _ = conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(conformAuxiliaryMutablesFailure))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + conformAuxiliary = new(MockAuxiliary) + _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) + + codec = baseHelpers.TestCodec() + + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) + paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) + + authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) + moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) - context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) + bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) + blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) - maintainAuxiliary = maintain.Auxiliary.Initialize(Mapper, parameterManager) - conformAuxiliary = conform.Auxiliary.Initialize(Mapper, parameterManager) - authenticateAuxiliary = authenticate.Auxiliary.Initialize(Mapper, parameterManager) + Context = setContext() - keepers := TestKeepers{ - MutateKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.TransactionKeeper), + coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) + _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) + + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) + + TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), + authenticateAuxiliary, + maintainAuxiliary, + conformAuxiliary, } +) - return context, keepers, Mapper, parameterManager +func setContext() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(authStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(bankStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) } -func Test_transactionKeeper_Initialize(t *testing.T) { - _, _, Mapper, parameterManager := createTestInput(t) - type fields struct { - mapper helpers.Mapper - authenticateAuxiliary helpers.Auxiliary - maintainAuxiliary helpers.Auxiliary - conformAuxiliary helpers.Auxiliary - } +func TestTransactionKeeperTransact(t *testing.T) { type args struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - auxiliaries []interface{} + from sdkTypes.AccAddress + fromID ids.IdentityID + assetID ids.AssetID + mutableMetaProps lists.PropertyList + mutableProps lists.PropertyList } + tests := []struct { - name string - fields fields - args args - want helpers.Keeper + name string + args args + setup func() + want *TransactionResponse + wantErr helpers.Error }{ - {"+ve", fields{Mapper, authenticateAuxiliary, maintainAuxiliary, conformAuxiliary}, args{Mapper, parameterManager, []interface{}{}}, transactionKeeper{Mapper, authenticateAuxiliary, maintainAuxiliary, conformAuxiliary}}, + {"mutateValidAsset", + args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + func() { + }, + newTransactionResponse(), + nil, + }, + {"mutateNonExistentAsset", + args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + func() {}, + nil, + errorConstants.EntityNotFound, + }, + {"authenticateAuxiliaryFailure", + args{ + from: authenticateAuxiliaryFailureAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + func() {}, + nil, + errorConstants.MockError, + }, + {"maintainAuxiliaryFailure", + args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: maintainAuxiliaryMutablesFailure, + }, + func() { + maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + }, + nil, + errorConstants.MockError, + }, + {"conformAuxiliaryFailure", + args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: conformAuxiliaryMutablesFailure, + }, + func() { + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + }, + nil, + errorConstants.MockError, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - maintainAuxiliary: tt.fields.maintainAuxiliary, - conformAuxiliary: tt.fields.conformAuxiliary, - } - if got := transactionKeeper.Initialize(tt.args.mapper, tt.args.parameterManager, tt.args.auxiliaries); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { - t.Errorf("Initialize() = %v, want %v", got, tt.want) + tt.setup() + + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), + NewMessage(tt.args.from, + tt.args.fromID, + tt.args.assetID, + tt.args.mutableMetaProps.(lists.PropertyList), + tt.args.mutableProps.(lists.PropertyList)).(helpers.Message), + ) + + if tt.wantErr != nil { + require.Error(t, err) + require.Equal(t, tt.wantErr, err) + } else { + require.NoError(t, err) + require.Equal(t, tt.want, got) } }) } diff --git a/x/assets/transactions/mutate/transaction_request.go b/x/assets/transactions/mutate/transaction_request.go index 70b006af3..471bf5dd6 100644 --- a/x/assets/transactions/mutate/transaction_request.go +++ b/x/assets/transactions/mutate/transaction_request.go @@ -12,7 +12,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -102,7 +102,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { mutableProperties, ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/assets/transactions/mutate/transaction_request_test.go b/x/assets/transactions/mutate/transaction_request_test.go index 27c63f9f4..80870c86f 100644 --- a/x/assets/transactions/mutate/transaction_request_test.go +++ b/x/assets/transactions/mutate/transaction_request_test.go @@ -15,7 +15,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -239,14 +239,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { MutableProperties string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), testAssetID.AsString(), mutableMetaPropertiesString, mutablePropertiesString}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), testAssetID.AsString(), mutableMetaPropertiesString, mutablePropertiesString}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/revoke/message.go b/x/assets/transactions/revoke/message.go index 78c8daf85..96369741b 100644 --- a/x/assets/transactions/revoke/message.go +++ b/x/assets/transactions/revoke/message.go @@ -7,7 +7,7 @@ import ( codecUtilities "github.com/AssetMantle/schema/codec/utilities" "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -46,7 +46,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/revoke/message_test.go b/x/assets/transactions/revoke/message_test.go index 3143a184b..d415e8ed1 100644 --- a/x/assets/transactions/revoke/message_test.go +++ b/x/assets/transactions/revoke/message_test.go @@ -13,7 +13,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -98,14 +98,14 @@ func Test_message_GetSigners(t *testing.T) { func Test_message_RegisterCodec(t *testing.T) { type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress.String(), fromID, fromID, classificationID}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, fromID, classificationID}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/revoke/transaction_keeper_test.go b/x/assets/transactions/revoke/transaction_keeper_test.go index 041b5ddcb..4d12d7c57 100644 --- a/x/assets/transactions/revoke/transaction_keeper_test.go +++ b/x/assets/transactions/revoke/transaction_keeper_test.go @@ -5,179 +5,218 @@ package revoke import ( "context" - "fmt" - "github.com/AssetMantle/modules/helpers" - baseHelpers "github.com/AssetMantle/modules/helpers/base" - "github.com/AssetMantle/modules/x/assets/mapper" - "github.com/AssetMantle/modules/x/assets/parameters" - "github.com/AssetMantle/modules/x/assets/record" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/revoke" + "github.com/AssetMantle/schema/ids" + "github.com/AssetMantle/schema/parameters/base" + constantProperties "github.com/AssetMantle/schema/properties/constants" + "github.com/cometbft/cometbft/crypto/ed25519" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" + paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/mock" + "testing" + baseData "github.com/AssetMantle/schema/data/base" - "github.com/AssetMantle/schema/documents/base" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" - baseQualified "github.com/AssetMantle/schema/qualified/base" tendermintDB "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" - storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" - "reflect" - "testing" -) -var ( - authenticateAuxiliary helpers.Auxiliary - revokeAuxiliary helpers.Auxiliary + "github.com/AssetMantle/modules/helpers" + baseHelpers "github.com/AssetMantle/modules/helpers/base" + "github.com/AssetMantle/modules/x/assets/mapper" + "github.com/AssetMantle/modules/x/assets/parameters" + "github.com/AssetMantle/modules/x/classifications/auxiliaries/define" ) -type TestKeepers struct { - RevokeKeeper helpers.TransactionKeeper +type MockAuxiliary struct { + mock.Mock } -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() - - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - codec := baseHelpers.TestCodec() - ParamsKeeper := paramsKeeper.NewKeeper( - codec, - legacyAmino, - paramsStoreKey, - paramsTransientStoreKeys, - ) - parameterManager := parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) - - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) +var _ helpers.Auxiliary = (*MockAuxiliary)(nil) - Context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) +func (mockAuxiliary *MockAuxiliary) GetName() string { panic(mockAuxiliary) } +func (mockAuxiliary *MockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper { + args := mockAuxiliary.Called() + return args.Get(0).(helpers.AuxiliaryKeeper) +} +func (mockAuxiliary *MockAuxiliary) Initialize(_ helpers.Mapper, _ helpers.ParameterManager, _ ...interface{}) helpers.Auxiliary { + panic(mockAuxiliary) +} - revokeAuxiliary = revoke.Auxiliary.Initialize(Mapper, parameterManager) - authenticateAuxiliary = authenticate.Auxiliary.Initialize(Mapper, parameterManager) +type MockAuxiliaryKeeper struct { + mock.Mock +} - keepers := TestKeepers{ - RevokeKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.TransactionKeeper), - } +var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) - return Context, keepers, Mapper, parameterManager +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, request) + return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } - -func Test_keeperPrototype(t *testing.T) { - tests := []struct { - name string - want helpers.TransactionKeeper - }{ - {"+ve", transactionKeeper{}}, - } - 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) - } - }) - } +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(m2, manager, i) + return args.Get(0).(helpers.Keeper) } -func Test_transactionKeeper_Initialize(t *testing.T) { - _, _, Mapper, parameterManager := createTestInput(t) - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - revokeAuxiliary helpers.Auxiliary - } - type args struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - auxiliaries []interface{} - } - tests := []struct { - name string - fields fields - args args - want helpers.Keeper - }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, revokeAuxiliary}, args{Mapper, parameterManager, []interface{}{}}, transactionKeeper{Mapper, parameterManager, authenticateAuxiliary, revokeAuxiliary}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - parameterManager: tt.fields.parameterManager, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - revokeAuxiliary: tt.fields.revokeAuxiliary, - } - if got := transactionKeeper.Initialize(tt.args.mapper, tt.args.parameterManager, tt.args.auxiliaries); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { - t.Errorf("Initialize() = %v, want %v", got, tt.want) - } - }) +const ( + TestMinterModuleName = "testMinter" + Denom = "stake" + ChainID = "testChain" + GenesisSupply = 1000000000000 +) + +var ( + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) + + revokeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + revokeAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + revokeAuxiliaryKeeperFailureID = baseIDs.NewIdentityID(baseIDs.NewClassificationID(immutables, mutables), immutables) //baseIDs.PrototypeIdentityID() + _ = revokeAuxiliaryKeeper.On("Help", mock.Anything, revoke.NewAuxiliaryRequest(revokeAuxiliaryKeeperFailureID, baseIDs.PrototypeIdentityID(), baseIDs.PrototypeClassificationID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = revokeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(define.NewAuxiliaryResponse(baseIDs.PrototypeClassificationID()), nil) + revokeAuxiliary = new(MockAuxiliary) + _ = revokeAuxiliary.On("GetKeeper").Return(revokeAuxiliaryKeeper) + + codec = baseHelpers.TestCodec() + + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) + paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) + + authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) + moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) + blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + Context = setContext() + + coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) + _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) + + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) + + parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) + TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), + parameterManager, + authenticateAuxiliary, + revokeAuxiliary, } +) + +func setContext() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(authStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(bankStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) } -func Test_transactionKeeper_Transact(t *testing.T) { - Context, keepers, Mapper, parameterManager := createTestInput(t) - immutableProperties := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData"))) - immutables := baseQualified.NewImmutables(immutableProperties) - mutableProperties := baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())) - mutables := baseQualified.NewMutables(mutableProperties) - classificationID := baseIDs.NewClassificationID(immutables, mutables) - testAsset := base.NewAsset(classificationID, immutables, mutables) - fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c" - fromAccAddress, err := sdkTypes.AccAddressFromBech32(fromAddress) - require.Nil(t, err) - fromID := baseIDs.NewIdentityID(classificationID, immutables) - keepers.RevokeKeeper.(transactionKeeper).mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(record.NewRecord(testAsset)) - - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - revokeAuxiliary helpers.Auxiliary - } +func TestTransactionKeeperTransact(t *testing.T) { type args struct { - context context.Context - message helpers.Message + from sdkTypes.AccAddress + fromID ids.IdentityID + toID ids.IdentityID + classificationID ids.ClassificationID } + tests := []struct { name string - fields fields args args - want helpers.TransactionResponse - wantErr bool + setup func() + want *TransactionResponse + wantErr helpers.Error }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, revokeAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, fromID, classificationID).(*Message)}, newTransactionResponse(), false}, + { + name: "Positive Case", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + }, + setup: func() { + }, + want: newTransactionResponse(), + wantErr: nil, + }, + { + name: "Authentication Failure", + args: args{ + from: authenticateAuxiliaryFailureAddress, + fromID: baseIDs.PrototypeIdentityID(), + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + }, + setup: func() { + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "Revoke Auxiliary Failure", + args: args{ + from: revokeAuxiliaryFailureAddress, + fromID: revokeAuxiliaryKeeperFailureID, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + }, + setup: func() { + + }, + want: nil, + wantErr: errorConstants.MockError, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - parameterManager: tt.fields.parameterManager, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - revokeAuxiliary: tt.fields.revokeAuxiliary, - } - got, err := transactionKeeper.Transact(tt.args.context, tt.args.message) - if (err != nil) != tt.wantErr { - t.Errorf("Transact() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Transact() got = %v, want %v", got, tt.want) + tt.setup() + + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), + NewMessage(tt.args.from, + tt.args.fromID, + tt.args.toID, + tt.args.classificationID).(helpers.Message)) + + if tt.wantErr != nil { + require.Error(t, err) + require.Equal(t, tt.wantErr, err) + } else { + require.NoError(t, err) + require.Equal(t, tt.want, got) } }) } diff --git a/x/assets/transactions/revoke/transaction_request.go b/x/assets/transactions/revoke/transaction_request.go index 7c23b8645..b172c7ec4 100644 --- a/x/assets/transactions/revoke/transaction_request.go +++ b/x/assets/transactions/revoke/transaction_request.go @@ -11,7 +11,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -92,7 +92,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { classificationID.(ids.ClassificationID), ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/assets/transactions/revoke/transaction_request_test.go b/x/assets/transactions/revoke/transaction_request_test.go index 4acf2b848..3f57db540 100644 --- a/x/assets/transactions/revoke/transaction_request_test.go +++ b/x/assets/transactions/revoke/transaction_request_test.go @@ -11,7 +11,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -220,14 +220,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { ClassificationID string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), classificationID.AsString()}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), fromID.AsString(), classificationID.AsString()}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 962e5d454..97853a042 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -116,16 +116,21 @@ var ( supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) - supplementAuxiliaryFailureAsset = randomAssetGenerator(baseProperties.NewMetaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(0))).ScrubData(), nil) + supplementAuxiliaryFailureAsset = randomAssetGenerator( + baseProperties.NewMetaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(0))), + nil, + ) supplementAuxiliaryFailureAssetID = baseIDs.NewAssetID(supplementAuxiliaryFailureAsset.GetClassificationID(), supplementAuxiliaryFailureAsset.GetImmutables()).(*baseIDs.AssetID) - _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(supplementAuxiliaryFailureAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - mesaLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(1))), nil) - mesaLockAssetID = baseIDs.NewAssetID(mesaLockAsset.GetClassificationID(), mesaLockAsset.GetImmutables()).(*baseIDs.AssetID) - _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(mesaLockAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(1))))), nil) - unrevealedLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(2))), nil) - unrevealedLockAssetID = baseIDs.NewAssetID(unrevealedLockAsset.GetClassificationID(), unrevealedLockAsset.GetImmutables()).(*baseIDs.AssetID) - _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(unrevealedLockAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) - _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(supplementAuxiliaryFailureAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), errorConstants.MockError) + + mesaLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(1))), nil) + mesaLockAssetID = baseIDs.NewAssetID(mesaLockAsset.GetClassificationID(), mesaLockAsset.GetImmutables()).(*baseIDs.AssetID) + _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(mesaLockAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(1))))), nil) + + unrevealedLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(2))), nil) + unrevealedLockAssetID = baseIDs.NewAssetID(unrevealedLockAsset.GetClassificationID(), unrevealedLockAsset.GetImmutables()).(*baseIDs.AssetID) + _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(unrevealedLockAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) + _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) supplementAuxiliaryAuxiliary = new(MockAuxiliary) _ = supplementAuxiliaryAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) @@ -258,7 +263,6 @@ func TestTransactionKeeperTransact(t *testing.T) { "sendAssetWithUnrevealedLock", args{fromAddress, unrevealedLockAssetID, 1}, func() { - }, nil, errorConstants.MetaDataError, @@ -267,6 +271,9 @@ func TestTransactionKeeperTransact(t *testing.T) { "supplementAuxiliaryFailure", args{fromAddress, supplementAuxiliaryFailureAssetID, 1}, func() { + supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest( + supplementAuxiliaryFailureAsset.GetProperty(constantProperties.LockHeightProperty.GetID())), + ).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), errorConstants.MockError) }, nil, errorConstants.MockError, diff --git a/x/assets/transactions/unwrap/message.go b/x/assets/transactions/unwrap/message.go index ba5061f4d..9bdf1df5e 100644 --- a/x/assets/transactions/unwrap/message.go +++ b/x/assets/transactions/unwrap/message.go @@ -9,7 +9,7 @@ import ( codecUtilities "github.com/AssetMantle/schema/codec/utilities" "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -48,7 +48,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/unwrap/transaction_request.go b/x/assets/transactions/unwrap/transaction_request.go index 2219eb738..73b5377bc 100644 --- a/x/assets/transactions/unwrap/transaction_request.go +++ b/x/assets/transactions/unwrap/transaction_request.go @@ -11,7 +11,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -84,7 +84,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { coins, ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { From 334e59c6bb1fe7fc63d6fe805ccedf47cf6ab98f Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 30 Jul 2024 01:25:47 +0530 Subject: [PATCH 05/21] test cases fix --- .../mutate/transaction_keeper_test.go | 76 ++-- x/assets/transactions/renumerate/message.go | 4 +- .../transactions/renumerate/message_test.go | 6 +- .../renumerate/transaction_keeper.go | 2 + .../renumerate/transaction_keeper_test.go | 408 +++++++++++------- .../renumerate/transaction_request.go | 4 +- .../renumerate/transaction_request_test.go | 6 +- .../send/transaction_keeper_test.go | 8 +- .../unwrap/transaction_keeper_test.go | 11 + 9 files changed, 339 insertions(+), 186 deletions(-) diff --git a/x/assets/transactions/mutate/transaction_keeper_test.go b/x/assets/transactions/mutate/transaction_keeper_test.go index 134f69206..6c49f2c2a 100644 --- a/x/assets/transactions/mutate/transaction_keeper_test.go +++ b/x/assets/transactions/mutate/transaction_keeper_test.go @@ -11,9 +11,11 @@ import ( dataHelper "github.com/AssetMantle/modules/simulation/schema/types/base" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/assets/mapper" + recordassets "github.com/AssetMantle/modules/x/assets/record" "github.com/AssetMantle/modules/x/classifications/auxiliaries/conform" "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" "github.com/AssetMantle/modules/x/maintainers/auxiliaries/maintain" + baseDocuments "github.com/AssetMantle/schema/documents/base" "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/AssetMantle/schema/lists" @@ -34,8 +36,8 @@ import ( paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "math/rand" + "reflect" "testing" ) @@ -86,19 +88,25 @@ var ( authenticateAuxiliary = new(MockAuxiliary) _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - maintainAuxiliaryKeeper = new(MockAuxiliaryKeeper) + maintainAuxiliaryKeeper = new(MockAuxiliaryKeeper) + maintainFailureID = baseIDs.NewIdentityID(classificationID, immutables) + maintainAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) - _ = maintainAuxiliaryKeeper.On("Help", mock.Anything, maintain.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), baseIDs.PrototypeIdentityID(), baseQualified.NewMutables(maintainAuxiliaryMutablesFailure))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) maintainAuxiliary = new(MockAuxiliary) _ = maintainAuxiliary.On("GetKeeper").Return(maintainAuxiliaryKeeper) - conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) - conformAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) - _ = conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(conformAuxiliaryMutablesFailure))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - conformAuxiliary = new(MockAuxiliary) - _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) + conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) + //conformAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) + //_ = conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + //_ = conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + conformAuxiliary = new(MockAuxiliary) + _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) + + testNewAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, mutables), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList())) + testNewAssetID = baseIDs.NewAssetID(testNewAsset.GetClassificationID(), testNewAsset.GetImmutables()).(*baseIDs.AssetID) + maintainFailureClassificationID = testNewAsset.GetClassificationID() + conformNewAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, mutables), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList())) + conformNewAssetID = baseIDs.NewAssetID(conformNewAsset.GetClassificationID(), conformNewAsset.GetImmutables()).(*baseIDs.AssetID) codec = baseHelpers.TestCodec() @@ -157,15 +165,32 @@ func TestTransactionKeeperTransact(t *testing.T) { want *TransactionResponse wantErr helpers.Error }{ + {"mutateInvalidAsset - validatebasic", + args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: testNewAssetID, + mutableMetaProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + func() { + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, + newTransactionResponse(), + nil, + }, {"mutateValidAsset", args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), - assetID: baseIDs.PrototypeAssetID(), + assetID: testNewAssetID, mutableMetaProps: baseLists.NewPropertyList(), mutableProps: baseLists.NewPropertyList(), }, func() { + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() }, newTransactionResponse(), nil, @@ -197,13 +222,13 @@ func TestTransactionKeeperTransact(t *testing.T) { {"maintainAuxiliaryFailure", args{ from: genesisAddress, - fromID: baseIDs.PrototypeIdentityID(), - assetID: baseIDs.PrototypeAssetID(), + fromID: maintainFailureID, + assetID: testNewAssetID, mutableMetaProps: baseLists.NewPropertyList(), - mutableProps: maintainAuxiliaryMutablesFailure, + mutableProps: baseLists.NewPropertyList(), }, func() { - maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + maintainAuxiliaryKeeper.On("Help", mock.Anything, maintain.NewAuxiliaryRequest(maintainFailureClassificationID, maintainFailureID, baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) }, nil, errorConstants.MockError, @@ -212,12 +237,13 @@ func TestTransactionKeeperTransact(t *testing.T) { args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), - assetID: baseIDs.PrototypeAssetID(), + assetID: testNewAssetID, mutableMetaProps: baseLists.NewPropertyList(), - mutableProps: conformAuxiliaryMutablesFailure, + mutableProps: baseLists.NewPropertyList(), }, func() { - conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(testNewAsset.GetClassificationID(), testNewAsset.GetImmutables(), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) }, nil, errorConstants.MockError, @@ -228,6 +254,8 @@ func TestTransactionKeeperTransact(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tt.setup() + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(testNewAsset)) + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), NewMessage(tt.args.from, tt.args.fromID, @@ -236,12 +264,12 @@ func TestTransactionKeeperTransact(t *testing.T) { tt.args.mutableProps.(lists.PropertyList)).(helpers.Message), ) - if tt.wantErr != nil { - require.Error(t, err) - require.Equal(t, tt.wantErr, err) - } else { - require.NoError(t, err) - require.Equal(t, tt.want, got) + if (tt.wantErr != nil && !tt.wantErr.Is(err)) || (tt.wantErr == nil && err != nil) { + t.Errorf("unexpected error: %v", err) + } + + if !reflect.DeepEqual(got, tt.want) { + t.Error("unexpected response") } }) } diff --git a/x/assets/transactions/renumerate/message.go b/x/assets/transactions/renumerate/message.go index 3d93e648f..40b88772f 100644 --- a/x/assets/transactions/renumerate/message.go +++ b/x/assets/transactions/renumerate/message.go @@ -7,7 +7,7 @@ import ( codecUtilities "github.com/AssetMantle/schema/codec/utilities" "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -43,7 +43,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/renumerate/message_test.go b/x/assets/transactions/renumerate/message_test.go index a6912c4f3..c81cef8e0 100644 --- a/x/assets/transactions/renumerate/message_test.go +++ b/x/assets/transactions/renumerate/message_test.go @@ -13,7 +13,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -99,14 +99,14 @@ func Test_message_GetSigners(t *testing.T) { func Test_message_RegisterCodec(t *testing.T) { type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress.String(), fromID, testAssetID}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress.String(), fromID, testAssetID}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/renumerate/transaction_keeper.go b/x/assets/transactions/renumerate/transaction_keeper.go index e8a94e64f..e5fffff39 100644 --- a/x/assets/transactions/renumerate/transaction_keeper.go +++ b/x/assets/transactions/renumerate/transaction_keeper.go @@ -60,6 +60,7 @@ func (transactionKeeper transactionKeeper) Handle(context context.Context, messa supply := asset.GetSupply() + // TODO: Clarify why supply property can't be meta if supplyProperty := asset.GetProperty(propertyConstants.SupplyProperty.GetID()); supplyProperty != nil && !supplyProperty.IsMeta() { auxiliaryResponse, err := transactionKeeper.supplementAuxiliary.GetKeeper().Help(context, supplement.NewAuxiliaryRequest(supplyProperty)) if err != nil { @@ -67,6 +68,7 @@ func (transactionKeeper transactionKeeper) Handle(context context.Context, messa } if supplyProperty = supplement.GetMetaPropertiesFromResponse(auxiliaryResponse).GetProperty(propertyConstants.SupplyProperty.GetID()); supplyProperty != nil && supplyProperty.IsMeta() { + //TODO: This type casting will panic if the property is not a meta property supply = supplyProperty.Get().(properties.MetaProperty).GetData().Get().(data.NumberData).Get() } else { return nil, errorConstants.MetaDataError.Wrapf("supply property is not revealed") diff --git a/x/assets/transactions/renumerate/transaction_keeper_test.go b/x/assets/transactions/renumerate/transaction_keeper_test.go index 397f59d6c..352affa0a 100644 --- a/x/assets/transactions/renumerate/transaction_keeper_test.go +++ b/x/assets/transactions/renumerate/transaction_keeper_test.go @@ -5,16 +5,37 @@ package renumerate import ( "context" - "fmt" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + dataHelper "github.com/AssetMantle/modules/simulation/schema/types/base" + "github.com/AssetMantle/modules/x/assets/constants" + recordassets "github.com/AssetMantle/modules/x/assets/record" + "github.com/AssetMantle/modules/x/metas/auxiliaries/supplement" + baseDocuments "github.com/AssetMantle/schema/documents/base" + "github.com/AssetMantle/schema/ids" + "github.com/AssetMantle/schema/parameters/base" + constantProperties "github.com/AssetMantle/schema/properties/constants" + "github.com/cometbft/cometbft/crypto/ed25519" storeTypes "github.com/cosmos/cosmos-sdk/store/types" + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" + paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/mock" + "math/rand" "reflect" "testing" + "github.com/AssetMantle/modules/helpers" + baseHelpers "github.com/AssetMantle/modules/helpers/base" + "github.com/AssetMantle/modules/x/assets/mapper" + "github.com/AssetMantle/modules/x/assets/parameters" + "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" + "github.com/AssetMantle/modules/x/splits/auxiliaries/renumerate" baseData "github.com/AssetMantle/schema/data/base" - "github.com/AssetMantle/schema/documents/base" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" - "github.com/AssetMantle/schema/properties" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" tendermintDB "github.com/cometbft/cometbft-db" @@ -23,177 +44,270 @@ import ( "github.com/cosmos/cosmos-sdk/store" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - "github.com/stretchr/testify/require" - - "github.com/AssetMantle/modules/helpers" - baseHelpers "github.com/AssetMantle/modules/helpers/base" - "github.com/AssetMantle/modules/x/assets/mapper" - "github.com/AssetMantle/modules/x/assets/parameters" - "github.com/AssetMantle/modules/x/assets/record" - "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" - "github.com/AssetMantle/modules/x/maintainers/auxiliaries/authorize" - "github.com/AssetMantle/modules/x/metas/auxiliaries/supplement" - "github.com/AssetMantle/modules/x/splits/auxiliaries/renumerate" ) -var ( - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - renumerateAuxiliary helpers.Auxiliary - supplementAuxiliary helpers.Auxiliary -) +type MockAuxiliary struct { + mock.Mock +} -type TestKeepers struct { - RenumerateKeeper helpers.TransactionKeeper +var _ helpers.Auxiliary = (*MockAuxiliary)(nil) + +func (mockAuxiliary *MockAuxiliary) GetName() string { panic(mockAuxiliary) } +func (mockAuxiliary *MockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper { + args := mockAuxiliary.Called() + return args.Get(0).(helpers.AuxiliaryKeeper) +} +func (mockAuxiliary *MockAuxiliary) Initialize(_ helpers.Mapper, _ helpers.ParameterManager, _ ...interface{}) helpers.Auxiliary { + panic(mockAuxiliary) } -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() - - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - codec := baseHelpers.TestCodec() - ParamsKeeper := paramsKeeper.NewKeeper( - codec, - legacyAmino, - paramsStoreKey, - paramsTransientStoreKeys, +type MockAuxiliaryKeeper struct { + mock.Mock +} + +var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) + +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, request) + return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) +} +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(m2, manager, i) + return args.Get(0).(helpers.Keeper) +} + +const ( + TestMinterModuleName = "testMinter" + Denom = "stake" + ChainID = "testChain" + GenesisSupply = 1000000000000 +) + +var ( + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + + propList = baseQualified.NewMutables(mutableMetaProperties).GetMutablePropertyList().Add( + baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) - parameterManager := parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) + newMutables = baseQualified.NewMutables(propList) + testNewAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) + testNewAssetID = baseIDs.NewAssetID(testNewAsset.GetClassificationID(), testNewAsset.GetImmutables()).(*baseIDs.AssetID) - Context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - authenticateAuxiliary = authenticate.Auxiliary.Initialize(Mapper, parameterManager) - authorizeAuxiliary = authorize.Auxiliary.Initialize(Mapper, parameterManager) - renumerateAuxiliary = renumerate.Auxiliary.Initialize(Mapper, parameterManager) - supplementAuxiliary = supplement.Auxiliary.Initialize(Mapper, parameterManager) + authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authorizeAuxiliaryFailureClassificationID = baseIDs.NewIdentityID(testNewAsset.GetClassificationID(), immutables) + //_ = authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliary = new(MockAuxiliary) + _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) - keepers := TestKeepers{ - RenumerateKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.TransactionKeeper), - } + renumerateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + renumerateAuxiliaryAssetID = baseIDs.NewStringID("renumerateFailureAsset") + _ = renumerateAuxiliaryKeeper.On("Help", mock.Anything, renumerate.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseIDs.PrototypeAssetID(), sdkTypes.NewInt(1000))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + //_ = renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - return Context, keepers, Mapper, parameterManager -} + renumerateAuxiliary = new(MockAuxiliary) + _ = renumerateAuxiliary.On("GetKeeper").Return(renumerateAuxiliaryKeeper) -func Test_keeperPrototype(t *testing.T) { - tests := []struct { - name string - want helpers.TransactionKeeper - }{ - {"+ve", transactionKeeper{}}, - } - 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) - } - }) - } -} + supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) + supplementAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) + //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest()).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + supplementAuxiliary = new(MockAuxiliary) + _ = supplementAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) -func Test_transactionKeeper_Initialize(t *testing.T) { - _, _, Mapper, parameterManager := createTestInput(t) - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - renumerateAuxiliary helpers.Auxiliary - supplementAuxiliary helpers.Auxiliary - } - type args struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - auxiliaries []interface{} - } - tests := []struct { - name string - fields fields - args args - want helpers.Keeper - }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, renumerateAuxiliary, supplementAuxiliary}, args{Mapper, parameterManager, []interface{}{}}, transactionKeeper{Mapper, parameterManager, authenticateAuxiliary, renumerateAuxiliary, supplementAuxiliary, authenticateAuxiliary}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - renumerateAuxiliary: tt.fields.renumerateAuxiliary, - supplementAuxiliary: tt.fields.supplementAuxiliary, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - } - if got := transactionKeeper.Initialize(tt.args.mapper, tt.args.parameterManager, tt.args.auxiliaries); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) { - t.Errorf("Initialize() = %v, want %v", got, tt.want) - } - }) + codec = baseHelpers.TestCodec() + + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) + paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) + + authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) + moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) + blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + Context = setContext() + + coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) + _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) + + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) + + parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) + TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), + parameterManager, + authenticateAuxiliary, + authorizeAuxiliary, + renumerateAuxiliary, + supplementAuxiliary, } +) + +func setContext() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(authStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(bankStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) } -func Test_transactionKeeper_Transact(t *testing.T) { - Context, keepers, Mapper, parameterManager := createTestInput(t) - immutableProperties := baseLists.NewPropertyList([]properties.Property{baseProperties.NewMetaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData")), baseProperties.NewMetaProperty(baseIDs.NewStringID("supply"), baseData.NewDecData(sdkTypes.NewDec(1)))}...) - immutables := baseQualified.NewImmutables(immutableProperties) - mutableProperties := baseLists.NewPropertyList([]properties.Property{baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())}...) - mutables := baseQualified.NewMutables(mutableProperties) - classificationID := baseIDs.NewClassificationID(immutables, mutables) - testAsset := base.NewAsset(classificationID, immutables, mutables) - testAssetID := baseIDs.NewAssetID(classificationID, immutables) - fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c" - fromAccAddress, err := sdkTypes.AccAddressFromBech32(fromAddress) - require.Nil(t, err) - fromID := baseIDs.NewIdentityID(classificationID, immutables) - keepers.RenumerateKeeper.(transactionKeeper).mapper.NewCollection(Context.Context()).Add(record.NewRecord(testAsset)) - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - renumerateAuxiliary helpers.Auxiliary - supplementAuxiliary helpers.Auxiliary - } +func TestTransactionKeeperTransact(t *testing.T) { type args struct { - context context.Context - message helpers.Message + from sdkTypes.AccAddress + fromID ids.IdentityID + assetID ids.AssetID + denom string } + tests := []struct { name string - fields fields args args - want helpers.TransactionResponse - wantErr bool + setup func() + want *TransactionResponse + wantErr helpers.Error }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, renumerateAuxiliary, supplementAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, testAssetID).(*Message)}, newTransactionResponse(), false}, - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, renumerateAuxiliary, supplementAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, baseIDs.PrototypeAssetID()).(*Message)}, newTransactionResponse(), false}, + { + name: "Success Case", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: testNewAssetID, + denom: Denom, + }, + setup: func() { + renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList(constantProperties.SupplyProperty)), nil).Once() + }, + want: newTransactionResponse(), + wantErr: nil, + }, + { + name: "Renumerate Property Disabled", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: testNewAssetID, + denom: Denom, + }, + setup: func() { + //authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(false))))) + }, + want: nil, + wantErr: errorConstants.NotAuthorized, + }, + { + name: "Authentication Failure", + args: args{ + from: authenticateAuxiliaryFailureAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + denom: Denom, + }, + setup: func() { + parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))) + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "Entity Not Found Failure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + denom: Denom, + }, + setup: func() { + //authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, + want: nil, + wantErr: errorConstants.EntityNotFound, + }, + { + name: "Authorize Auxiliary Failure", + args: args{ + from: genesisAddress, + fromID: authorizeAuxiliaryFailureClassificationID, + assetID: testNewAssetID, + denom: Denom, + }, + setup: func() { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "Supplement Auxiliary Failure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: testNewAssetID, + }, + setup: func() { + //TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(testNewAsset)) + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "Renumerate Auxiliary Failure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: testNewAssetID, + }, + setup: func() { + renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList(constantProperties.SupplyProperty)), nil).Once() + }, + want: nil, + wantErr: errorConstants.MockError, + }, } + for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - parameterManager: tt.fields.parameterManager, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - authorizeAuxiliary: tt.fields.authorizeAuxiliary, - renumerateAuxiliary: tt.fields.renumerateAuxiliary, - supplementAuxiliary: tt.fields.supplementAuxiliary, - } - got, err := transactionKeeper.Transact(tt.args.context, tt.args.message) - if (err != nil) != tt.wantErr { - t.Errorf("Transact() error = %v, wantErr %v", err, tt.wantErr) - return + tt.setup() + + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(testNewAsset)) + + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), + NewMessage(tt.args.from, + tt.args.fromID, + tt.args.assetID).(helpers.Message)) + + if (err != nil) && !tt.wantErr.Is(err) { + t.Errorf("unexpected error: %v", err) } + if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Transact() got = %v, want %v", got, tt.want) + t.Error("unexpected response") } }) } diff --git a/x/assets/transactions/renumerate/transaction_request.go b/x/assets/transactions/renumerate/transaction_request.go index d2fe46442..8bc87d46f 100644 --- a/x/assets/transactions/renumerate/transaction_request.go +++ b/x/assets/transactions/renumerate/transaction_request.go @@ -11,7 +11,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -84,7 +84,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { assetID.(ids.AssetID), ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/assets/transactions/renumerate/transaction_request_test.go b/x/assets/transactions/renumerate/transaction_request_test.go index 21075e409..25526b06b 100644 --- a/x/assets/transactions/renumerate/transaction_request_test.go +++ b/x/assets/transactions/renumerate/transaction_request_test.go @@ -11,7 +11,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -209,14 +209,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { AssetID string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), testAssetID.AsString()}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), testAssetID.AsString()}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 97853a042..462cf3a5e 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -117,7 +117,7 @@ var ( supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) supplementAuxiliaryFailureAsset = randomAssetGenerator( - baseProperties.NewMetaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(0))), + baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(0))), nil, ) supplementAuxiliaryFailureAssetID = baseIDs.NewAssetID(supplementAuxiliaryFailureAsset.GetClassificationID(), supplementAuxiliaryFailureAsset.GetImmutables()).(*baseIDs.AssetID) @@ -269,11 +269,9 @@ func TestTransactionKeeperTransact(t *testing.T) { }, { "supplementAuxiliaryFailure", - args{fromAddress, supplementAuxiliaryFailureAssetID, 1}, + args{fromAddress, supplementAuxiliaryFailureAssetID, 0}, func() { - supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest( - supplementAuxiliaryFailureAsset.GetProperty(constantProperties.LockHeightProperty.GetID())), - ).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), errorConstants.MockError) + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) }, nil, errorConstants.MockError, diff --git a/x/assets/transactions/unwrap/transaction_keeper_test.go b/x/assets/transactions/unwrap/transaction_keeper_test.go index fb4dce300..f0487a3d6 100644 --- a/x/assets/transactions/unwrap/transaction_keeper_test.go +++ b/x/assets/transactions/unwrap/transaction_keeper_test.go @@ -92,6 +92,7 @@ var ( _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) burnAuxiliaryKeeper = new(MockAuxiliaryKeeper) + newCollectionFaliure = "notfound" burnAuxiliaryFailureDenom = "burn" _ = burnAuxiliaryKeeper.On("Help", mock.Anything, burn.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseDocuments.NewCoinAsset(burnAuxiliaryFailureDenom).GetCoinAssetID(), sdkTypes.OneInt())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) _ = burnAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) @@ -225,6 +226,16 @@ func TestTransactionKeeperTransact(t *testing.T) { nil, errorConstants.NotAuthorized, }, + { + "EntityNotFound", + args{genesisAddress, burnAuxiliaryFailureDenom, 1}, + func() { + TransactionKeeper.parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(burnAuxiliaryFailureDenom)))))) + parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(newCollectionFaliure), baseData.NewStringData(burnAuxiliaryFailureDenom)))))) + }, + nil, + errorConstants.EntityNotFound, + }, { "burnAuxiliaryFailure", args{genesisAddress, burnAuxiliaryFailureDenom, 1}, From ee763206bec2c1c49fcf8ad7182c197104e9549b Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 30 Jul 2024 12:22:54 +0530 Subject: [PATCH 06/21] send test cases fix --- x/assets/transactions/send/transaction_keeper_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 462cf3a5e..737f4bbe4 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -121,7 +121,7 @@ var ( nil, ) supplementAuxiliaryFailureAssetID = baseIDs.NewAssetID(supplementAuxiliaryFailureAsset.GetClassificationID(), supplementAuxiliaryFailureAsset.GetImmutables()).(*baseIDs.AssetID) - _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(supplementAuxiliaryFailureAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), errorConstants.MockError) + //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(supplementAuxiliaryFailureAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), errorConstants.MockError) mesaLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(1))), nil) mesaLockAssetID = baseIDs.NewAssetID(mesaLockAsset.GetClassificationID(), mesaLockAsset.GetImmutables()).(*baseIDs.AssetID) @@ -130,7 +130,7 @@ var ( unrevealedLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(2))), nil) unrevealedLockAssetID = baseIDs.NewAssetID(unrevealedLockAsset.GetClassificationID(), unrevealedLockAsset.GetImmutables()).(*baseIDs.AssetID) _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(unrevealedLockAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) - _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) + //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) supplementAuxiliaryAuxiliary = new(MockAuxiliary) _ = supplementAuxiliaryAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) @@ -271,7 +271,7 @@ func TestTransactionKeeperTransact(t *testing.T) { "supplementAuxiliaryFailure", args{fromAddress, supplementAuxiliaryFailureAssetID, 0}, func() { - supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() }, nil, errorConstants.MockError, From 7a6186e485b7c5a63536a54a9a044ae3d8af82b3 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 30 Jul 2024 21:04:56 +0530 Subject: [PATCH 07/21] burn test cases fix --- x/assets/transactions/burn/message.go | 4 +- x/assets/transactions/burn/message_test.go | 8 +- .../burn/transaction_keeper_test.go | 544 +++++++++++++----- .../transactions/burn/transaction_request.go | 4 +- .../burn/transaction_request_test.go | 6 +- .../send/transaction_keeper_test.go | 2 - 6 files changed, 409 insertions(+), 159 deletions(-) diff --git a/x/assets/transactions/burn/message.go b/x/assets/transactions/burn/message.go index 1e49cd3f0..3a0dabd86 100644 --- a/x/assets/transactions/burn/message.go +++ b/x/assets/transactions/burn/message.go @@ -7,7 +7,7 @@ import ( codecUtilities "github.com/AssetMantle/schema/codec/utilities" "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdkTypes "github.com/cosmos/cosmos-sdk/types" @@ -43,7 +43,7 @@ func (message *Message) GetSigners() []sdkTypes.AccAddress { } return []sdkTypes.AccAddress{from} } -func (*Message) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (*Message) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, Message{}) } func (message *Message) RegisterInterface(interfaceRegistry types.InterfaceRegistry) { diff --git a/x/assets/transactions/burn/message_test.go b/x/assets/transactions/burn/message_test.go index 7178d55b3..a2b686447 100644 --- a/x/assets/transactions/burn/message_test.go +++ b/x/assets/transactions/burn/message_test.go @@ -13,7 +13,7 @@ import ( baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -99,15 +99,15 @@ func Test_message_RegisterCodec(t *testing.T) { AssetID ids.AssetID } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{fromAccAddress, fromID, testAssetID}, args{codec.NewLegacyAmino()}}, - {"+ve", fields{}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{fromAccAddress, fromID, testAssetID}, args{sdkCodec.NewLegacyAmino()}}, + {"+ve", fields{}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/burn/transaction_keeper_test.go b/x/assets/transactions/burn/transaction_keeper_test.go index 9c6adaf8e..dd227224c 100644 --- a/x/assets/transactions/burn/transaction_keeper_test.go +++ b/x/assets/transactions/burn/transaction_keeper_test.go @@ -5,198 +5,450 @@ package burn import ( "context" - "fmt" - "github.com/AssetMantle/modules/x/assets/record" + errorConstants "github.com/AssetMantle/modules/helpers/constants" + "github.com/AssetMantle/modules/x/assets/constants" + recordassets "github.com/AssetMantle/modules/x/assets/record" + "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" + "github.com/AssetMantle/modules/x/metas/auxiliaries/supplement" + baseDocuments "github.com/AssetMantle/schema/documents/base" + "github.com/AssetMantle/schema/ids" + "github.com/AssetMantle/schema/parameters/base" + constantProperties "github.com/AssetMantle/schema/properties/constants" + baseQualified "github.com/AssetMantle/schema/qualified/base" + base2 "github.com/AssetMantle/schema/types/base" + "github.com/cometbft/cometbft/crypto/ed25519" storeTypes "github.com/cosmos/cosmos-sdk/store/types" + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" + paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/stretchr/testify/mock" "reflect" "testing" baseData "github.com/AssetMantle/schema/data/base" - "github.com/AssetMantle/schema/documents/base" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" baseProperties "github.com/AssetMantle/schema/properties/base" - baseQualified "github.com/AssetMantle/schema/qualified/base" tendermintDB "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" sdkTypes "github.com/cosmos/cosmos-sdk/types" paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - "github.com/stretchr/testify/require" "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" "github.com/AssetMantle/modules/x/assets/mapper" "github.com/AssetMantle/modules/x/assets/parameters" - "github.com/AssetMantle/modules/x/splits/auxiliaries/renumerate" ) -var ( - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - purgeAuxiliary helpers.Auxiliary - supplementAuxiliary helpers.Auxiliary - unbondAuxiliary helpers.Auxiliary -) +type MockAuxiliary struct { + mock.Mock +} + +var _ helpers.Auxiliary = (*MockAuxiliary)(nil) + +func (mockAuxiliary *MockAuxiliary) GetName() string { panic(mockAuxiliary) } +func (mockAuxiliary *MockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper { + args := mockAuxiliary.Called() + return args.Get(0).(helpers.AuxiliaryKeeper) +} +func (mockAuxiliary *MockAuxiliary) Initialize(_ helpers.Mapper, _ helpers.ParameterManager, _ ...interface{}) helpers.Auxiliary { + panic(mockAuxiliary) +} + +type MockAuxiliaryKeeper struct { + mock.Mock +} + +var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -type TestKeepers struct { - BurnKeeper helpers.TransactionKeeper +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, request) + return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) +} +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(m2, manager, i) + return args.Get(0).(helpers.Keeper) } -func createTestInput(t *testing.T) (sdkTypes.Context, TestKeepers, helpers.Mapper, helpers.ParameterManager) { - var legacyAmino = baseHelpers.CodecPrototype().GetLegacyAmino() - - storeKey := sdkTypes.NewKVStoreKey("test") - paramsStoreKey := sdkTypes.NewKVStoreKey("testParams") - paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient") - Mapper := mapper.Prototype().Initialize(storeKey) - codec := baseHelpers.TestCodec() - ParamsKeeper := paramsKeeper.NewKeeper( - codec, - legacyAmino, - paramsStoreKey, - paramsTransientStoreKeys, +const ( + TestMinterModuleName = "testMinter" + Denom = "stake" + ChainID = "testChain" + GenesisSupply = 1000000000000 +) + +var ( + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + immutableMesaProperties = baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList)) + supplymutableMesaPropertiesList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) + mutableMesaPropertiesList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) + mutableMetaPropertiesList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + propList = baseQualified.NewMutables(mutableMetaPropertiesList).GetMutablePropertyList().Add( + baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) - parameterManager := parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) - memDB := tendermintDB.NewMemDB() - commitMultiStore := store.NewCommitMultiStore(memDB) - commitMultiStore.MountStoreWithDB(storeKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) - commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) - err := commitMultiStore.LoadLatestVersion() - require.Nil(t, err) + propListburnHeightMetamutables = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + propListburnHeightMeta = baseQualified.NewMutables(propListburnHeightMetamutables).GetMutablePropertyList().Add( + baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMetaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(20))), + ) - Context := sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ - ChainID: "test", - }, false, log.NewNopLogger()) + propListsupplyMetamutables = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + propListsupplyMeta = baseQualified.NewMutables(propListsupplyMetamutables).GetMutablePropertyList().Add( + baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + ) - authenticateAuxiliary = renumerate.Auxiliary.Initialize(Mapper, parameterManager) - authorizeAuxiliary = renumerate.Auxiliary.Initialize(Mapper, parameterManager) - purgeAuxiliary = renumerate.Auxiliary.Initialize(Mapper, parameterManager) - supplementAuxiliary = renumerate.Auxiliary.Initialize(Mapper, parameterManager) - unbondAuxiliary = renumerate.Auxiliary.Initialize(Mapper, parameterManager) + supplyPropertyMesaProp = baseQualified.NewMutables(supplymutableMesaPropertiesList).GetMutablePropertyList().Add( + baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), + ) - keepers := TestKeepers{ - BurnKeeper: keeperPrototype().Initialize(Mapper, parameterManager, []interface{}{}).(helpers.TransactionKeeper), - } + burnHeightMesaProp = baseQualified.NewMutables(mutableMesaPropertiesList).GetMutablePropertyList().Add( + baseProperties.NewMesaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(13))), + baseProperties.NewMesaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), + ) + burnHeightMesaPropMutables = baseQualified.NewMutables(burnHeightMesaProp) + burnHeightMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutableMesaProperties, burnHeightMesaPropMutables), immutableMesaProperties, burnHeightMesaPropMutables) + burnHeightMesaAssetID = baseIDs.NewAssetID(burnHeightMesaAsset.GetClassificationID(), burnHeightMesaAsset.GetImmutables()).(*baseIDs.AssetID) - return Context, keepers, Mapper, parameterManager -} + supplyPropertyMesaPropMutables = baseQualified.NewMutables(supplyPropertyMesaProp) + supplyPropertyMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutableMesaProperties, supplyPropertyMesaPropMutables), immutableMesaProperties, supplyPropertyMesaPropMutables) + supplyPropertyMesaAssetID = baseIDs.NewAssetID(supplyPropertyMesaAsset.GetClassificationID(), supplyPropertyMesaAsset.GetImmutables()).(*baseIDs.AssetID) -func Test_keeperPrototype(t *testing.T) { - tests := []struct { - name string - want helpers.TransactionKeeper - }{ - {"+ve", transactionKeeper{}}, - } - 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) - } - }) - } -} + newMutables = baseQualified.NewMutables(propList) + asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) + assetID = baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()).(*baseIDs.AssetID) -func Test_transactionKeeper_Initialize(t *testing.T) { - _, _, Mapper, parameterManager := createTestInput(t) - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - purgeAuxiliary helpers.Auxiliary - supplementAuxiliary helpers.Auxiliary - unbondAuxiliary helpers.Auxiliary - } - type args struct { - mapper helpers.Mapper - in1 helpers.ParameterManager - auxiliaries []interface{} - } - tests := []struct { - name string - fields fields - args args - want helpers.Keeper - }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, purgeAuxiliary, supplementAuxiliary, unbondAuxiliary}, args{Mapper, parameterManager, []interface{}{}}, transactionKeeper{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, supplementAuxiliary, nil, nil}}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - tt.fields.mapper, - tt.fields.parameterManager, - tt.fields.authenticateAuxiliary, - tt.fields.authorizeAuxiliary, - tt.fields.purgeAuxiliary, - tt.fields.supplementAuxiliary, - tt.fields.unbondAuxiliary, - } - if got := transactionKeeper.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) - } - }) - } + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) + + authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authorizeAuxiliary = new(MockAuxiliary) + _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) + + purgeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + purgeAuxiliary = new(MockAuxiliary) + _ = purgeAuxiliary.On("GetKeeper").Return(purgeAuxiliaryKeeper) + + supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) + + supplementAuxiliary = new(MockAuxiliary) + _ = supplementAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) + + unbondAuxiliaryKeeper = new(MockAuxiliaryKeeper) + unbondAuxiliary = new(MockAuxiliary) + _ = unbondAuxiliary.On("GetKeeper").Return(unbondAuxiliaryKeeper) + + codec = baseHelpers.TestCodec() + + paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) + paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) + ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) + + authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) + moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} + AuthKeeper = authKeeper.NewAccountKeeper(codec, authStoreKey, authTypes.ProtoBaseAccount, moduleAccountPermissions, sdkTypes.GetConfig().GetBech32AccountAddrPrefix(), authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + bankStoreKey = sdkTypes.NewKVStoreKey(bankTypes.StoreKey) + blacklistedAddresses = map[string]bool{authTypes.NewModuleAddress(TestMinterModuleName).String(): false, authTypes.NewModuleAddress(constants.ModuleName).String(): false} + BankKeeper = bankKeeper.NewBaseKeeper(codec, bankStoreKey, AuthKeeper, blacklistedAddresses, authTypes.NewModuleAddress(govTypes.ModuleName).String()) + + coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) + _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) + + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) + + Context = setContext() + + parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) + + TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), parameterManager, authenticateAuxiliary, authorizeAuxiliary, purgeAuxiliary, supplementAuxiliary, unbondAuxiliary} +) + +func setContext() sdkTypes.Context { + memDB := tendermintDB.NewMemDB() + commitMultiStore := store.NewCommitMultiStore(memDB) + commitMultiStore.MountStoreWithDB(moduleStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(authStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(bankStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsStoreKey, storeTypes.StoreTypeIAVL, memDB) + commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, storeTypes.StoreTypeTransient, memDB) + _ = commitMultiStore.LoadLatestVersion() + return sdkTypes.NewContext(commitMultiStore, protoTendermintTypes.Header{ChainID: ChainID}, false, log.NewNopLogger()) } -func Test_transactionKeeper_Transact1(t *testing.T) { - Context, keepers, Mapper, parameterManager := createTestInput(t) - immutables := baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("ID1"), baseData.NewStringData("ImmutableData")))) - mutables := baseQualified.NewMutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData()))) - classificationID := baseIDs.NewClassificationID(immutables, mutables) - testAssetID := baseIDs.NewAssetID(classificationID, immutables) - testAsset := base.NewAsset(classificationID, immutables, mutables) - fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c" - fromAccAddress, err := sdkTypes.AccAddressFromBech32(fromAddress) - require.Nil(t, err) - fromID := baseIDs.NewIdentityID(classificationID, immutables) - keepers.BurnKeeper.(transactionKeeper).mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(record.NewRecord(testAsset)) - type fields struct { - mapper helpers.Mapper - parameterManager helpers.ParameterManager - authenticateAuxiliary helpers.Auxiliary - authorizeAuxiliary helpers.Auxiliary - purgeAuxiliary helpers.Auxiliary - supplementAuxiliary helpers.Auxiliary - unbondAuxiliary helpers.Auxiliary - } +func TestTransactionKeeperTransact(t *testing.T) { type args struct { - context context.Context - message helpers.Message + from sdkTypes.AccAddress + fromID ids.IdentityID + assetID ids.AssetID + value int } tests := []struct { name string - fields fields args args - want helpers.TransactionResponse - wantErr bool + setup func() + want *TransactionResponse + wantErr helpers.Error }{ - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, purgeAuxiliary, supplementAuxiliary, unbondAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, testAssetID).(*Message)}, newTransactionResponse(), false}, - {"+ve", fields{Mapper, parameterManager, authenticateAuxiliary, authorizeAuxiliary, purgeAuxiliary, supplementAuxiliary, unbondAuxiliary}, args{Context.Context(), NewMessage(fromAccAddress, fromID, baseIDs.PrototypeAssetID()).(*Message)}, newTransactionResponse(), false}, + { + name: "burnDisabledSuccess", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: assetID, + }, + setup: func() { + parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(false))))) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, + want: nil, + wantErr: errorConstants.NotAuthorized, + }, + { + name: "burnAssetSuccess", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: assetID, + }, + setup: func() { + parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))) + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(asset)) + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + purgeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + unbondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, + want: newTransactionResponse(), + wantErr: nil, + }, + { + name: "burnAssetNotAuthenticated", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: assetID, + }, + setup: func() { + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "burnAssetNotAuthorized", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: assetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(asset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(genesisAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.NotAuthorized).Once() + }, + want: nil, + wantErr: errorConstants.NotAuthorized, + }, + { + name: "burnAssetEntityNotFound", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: baseIDs.PrototypeAssetID(), + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(asset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(genesisAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, + want: nil, + wantErr: errorConstants.EntityNotFound, + }, + { + name: "bondAmountSupplementAuxiliaryFailure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: burnHeightMesaAssetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(burnHeightMesaAsset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "bondHeightMetaDataAuxiliaryResponse", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: burnHeightMesaAssetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(burnHeightMesaAsset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(propListburnHeightMeta), nil).Once() + + }, + want: nil, + wantErr: errorConstants.NotAuthorized, + }, + { + name: "burnAmountSupplementMetaDataError", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: burnHeightMesaAssetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(burnHeightMesaAsset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(mutableMetaPropertiesList), nil).Once() + + }, + want: nil, + wantErr: errorConstants.MetaDataError, + }, + { + name: "SupplementAuxiliaryFailure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: supplyPropertyMesaAssetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyPropertyMesaAsset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + + }, + want: nil, + wantErr: errorConstants.MockError, + }, + { + name: "supplyMetaDataSuccess", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: supplyPropertyMesaAssetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyPropertyMesaAsset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(propListsupplyMeta), nil).Once() + purgeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + + }, + want: nil, + wantErr: errorConstants.MetaDataError, + }, + { + name: "supplyMetaDataError", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: supplyPropertyMesaAssetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyPropertyMesaAsset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(mutableMetaPropertiesList), nil).Once() + + }, + want: nil, + wantErr: errorConstants.MetaDataError, + }, + { + name: "PurgeAuxiliaryFailure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: assetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(asset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + purgeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + }, + want: nil, + wantErr: errorConstants.MockError, + }, + //{ + // name: "noRevealedBondAmountFailure", + // args: args{ + // from: genesisAddress, + // fromID: baseIDs.PrototypeIdentityID(), + // assetID: burnHeightMesaAssetID, + // }, + // setup: func() { + // TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(burnHeightMesaAsset)) + // authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(genesisAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), nil).Once() + // purgeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + // supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + // authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + // }, + // want: nil, + // wantErr: errorConstants.MetaDataError, + //}, + { + name: "unbondAuxiliaryFailure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: assetID, + }, + setup: func() { + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(asset)) + authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(genesisAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), nil).Once() + purgeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + unbondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + }, + want: nil, + wantErr: errorConstants.MockError, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - transactionKeeper := transactionKeeper{ - mapper: tt.fields.mapper, - parameterManager: tt.fields.parameterManager, - authenticateAuxiliary: tt.fields.authenticateAuxiliary, - authorizeAuxiliary: tt.fields.authorizeAuxiliary, - purgeAuxiliary: tt.fields.purgeAuxiliary, - supplementAuxiliary: tt.fields.supplementAuxiliary, - unbondAuxiliary: tt.fields.unbondAuxiliary, - } - got, err := transactionKeeper.Transact(tt.args.context, tt.args.message) - if (err != nil) != tt.wantErr { - t.Errorf("Transact() error = %v, wantErr %v", err, tt.wantErr) - return + tt.setup() + + got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), + NewMessage(tt.args.from, + tt.args.fromID, + tt.args.assetID).(helpers.Message)) + + if (err != nil) && !tt.wantErr.Is(err) { + t.Errorf("unexpected error: %v", err) } + if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Transact() got = %v, want %v", got, tt.want) + t.Error("unexpected response") } }) } } + +//sdkTypes.NewInt(10) diff --git a/x/assets/transactions/burn/transaction_request.go b/x/assets/transactions/burn/transaction_request.go index 15084779b..597919d36 100644 --- a/x/assets/transactions/burn/transaction_request.go +++ b/x/assets/transactions/burn/transaction_request.go @@ -11,7 +11,7 @@ import ( "github.com/AssetMantle/schema/ids" baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/AssetMantle/modules/helpers" @@ -84,7 +84,7 @@ func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) { assetID.(ids.AssetID), ), nil } -func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *codec.LegacyAmino) { +func (transactionRequest) RegisterLegacyAminoCodec(legacyAmino *sdkCodec.LegacyAmino) { codecUtilities.RegisterModuleConcrete(legacyAmino, transactionRequest{}) } func requestPrototype() helpers.TransactionRequest { diff --git a/x/assets/transactions/burn/transaction_request_test.go b/x/assets/transactions/burn/transaction_request_test.go index 440a2f03a..a990f39c6 100644 --- a/x/assets/transactions/burn/transaction_request_test.go +++ b/x/assets/transactions/burn/transaction_request_test.go @@ -12,7 +12,7 @@ import ( baseIDs "github.com/AssetMantle/schema/ids/base" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" + sdkCodec "github.com/cosmos/cosmos-sdk/codec" sdkTypes "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/viper" @@ -210,14 +210,14 @@ func Test_transactionRequest_RegisterCodec(t *testing.T) { AssetID string } type args struct { - legacyAmino *codec.LegacyAmino + legacyAmino *sdkCodec.LegacyAmino } tests := []struct { name string fields fields args args }{ - {"+ve", fields{testBaseRequest, fromID.AsString(), testAssetID.AsString()}, args{codec.NewLegacyAmino()}}, + {"+ve", fields{testBaseRequest, fromID.AsString(), testAssetID.AsString()}, args{sdkCodec.NewLegacyAmino()}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 737f4bbe4..87e8a9f03 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -121,7 +121,6 @@ var ( nil, ) supplementAuxiliaryFailureAssetID = baseIDs.NewAssetID(supplementAuxiliaryFailureAsset.GetClassificationID(), supplementAuxiliaryFailureAsset.GetImmutables()).(*baseIDs.AssetID) - //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(supplementAuxiliaryFailureAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), errorConstants.MockError) mesaLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(1))), nil) mesaLockAssetID = baseIDs.NewAssetID(mesaLockAsset.GetClassificationID(), mesaLockAsset.GetImmutables()).(*baseIDs.AssetID) @@ -130,7 +129,6 @@ var ( unrevealedLockAsset = randomAssetGenerator(baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(2))), nil) unrevealedLockAssetID = baseIDs.NewAssetID(unrevealedLockAsset.GetClassificationID(), unrevealedLockAsset.GetImmutables()).(*baseIDs.AssetID) _ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest(unrevealedLockAsset.GetProperty(constantProperties.LockHeightProperty.GetID()))).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) - //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList()), nil) supplementAuxiliaryAuxiliary = new(MockAuxiliary) _ = supplementAuxiliaryAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) From 15471480d3bc9e8adb186fbb7faece981269b7e0 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 30 Jul 2024 23:00:51 +0530 Subject: [PATCH 08/21] mint, renumerate test cases fix --- .../mint/transaction_keeper_test.go | 131 ++++++++++++------ .../renumerate/transaction_keeper.go | 3 +- .../renumerate/transaction_keeper_test.go | 31 ++++- 3 files changed, 117 insertions(+), 48 deletions(-) diff --git a/x/assets/transactions/mint/transaction_keeper_test.go b/x/assets/transactions/mint/transaction_keeper_test.go index 0bdfb3cfc..21e454ad8 100644 --- a/x/assets/transactions/mint/transaction_keeper_test.go +++ b/x/assets/transactions/mint/transaction_keeper_test.go @@ -12,12 +12,8 @@ import ( "github.com/AssetMantle/modules/x/assets/key" "github.com/AssetMantle/modules/x/assets/mapper" "github.com/AssetMantle/modules/x/assets/parameters" - "github.com/AssetMantle/modules/x/classifications/auxiliaries/bond" - "github.com/AssetMantle/modules/x/classifications/auxiliaries/conform" "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" - "github.com/AssetMantle/modules/x/maintainers/auxiliaries/authorize" "github.com/AssetMantle/modules/x/orders/record" - "github.com/AssetMantle/modules/x/splits/auxiliaries/mint" baseData "github.com/AssetMantle/schema/data/base" baseDocuments "github.com/AssetMantle/schema/documents/base" "github.com/AssetMantle/schema/ids" @@ -88,37 +84,31 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) - authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - authenticateAuxiliary = new(MockAuxiliary) - _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) - authorizeAuxiliaryFailureClassificationID = baseIDs.NewClassificationID(baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList())) - _ = authorizeAuxiliaryKeeper.On("Help", mock.Anything, authorize.NewAuxiliaryRequest(authorizeAuxiliaryFailureClassificationID, baseIDs.PrototypeIdentityID(), baseIDs.NewStringID(""))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - authorizeAuxiliary = new(MockAuxiliary) - _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) - mintAuxiliaryKeeper = new(MockAuxiliaryKeeper) - mintAuxiliaryFailureID = baseIDs.NewIdentityID(baseIDs.NewClassificationID(baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(1)))))), baseQualified.NewImmutables(baseLists.NewPropertyList())) - _ = mintAuxiliaryKeeper.On("Help", mock.Anything, mint.NewAuxiliaryRequest(mintAuxiliaryFailureID, baseDocuments.NewCoinAsset(Denom).GetCoinAssetID(), sdkTypes.OneInt())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = mintAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - mintAuxiliary = new(MockAuxiliary) - _ = mintAuxiliary.On("GetKeeper").Return(mintAuxiliaryKeeper) - bondAuxiliaryKeeper = new(MockAuxiliaryKeeper) - bondAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - _ = bondAuxiliaryKeeper.On("Help", mock.Anything, bond.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), bondAuxiliaryFailureAddress, sdkTypes.OneInt())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = bondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - _ = bondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - bondAuxiliary = new(MockAuxiliary) - _ = bondAuxiliary.On("GetKeeper").Return(bondAuxiliaryKeeper) - conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) - conformAuxiliaryFailureID = baseIDs.PrototypeClassificationID() - _ = conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(conformAuxiliaryFailureID, baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - conformAuxiliary = new(MockAuxiliary) - _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) + newMutables = baseQualified.NewMutables(baseLists.NewPropertyList()) + + asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) + assetID = baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()).(*baseIDs.AssetID) + + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) + authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authorizeAuxiliary = new(MockAuxiliary) + _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) + mintAuxiliaryKeeper = new(MockAuxiliaryKeeper) + mintAuxiliaryFailureID = baseIDs.NewIdentityID(baseIDs.NewClassificationID(baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(1)))))), baseQualified.NewImmutables(baseLists.NewPropertyList())) + mintAuxiliary = new(MockAuxiliary) + _ = mintAuxiliary.On("GetKeeper").Return(mintAuxiliaryKeeper) + bondAuxiliaryKeeper = new(MockAuxiliaryKeeper) + bondAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + bondAuxiliary = new(MockAuxiliary) + _ = bondAuxiliary.On("GetKeeper").Return(bondAuxiliaryKeeper) + conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) + conformAuxiliary = new(MockAuxiliary) + _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) codec = baseHelpers.TestCodec() paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) @@ -193,6 +183,24 @@ func TestTransactionKeeperTransact(t *testing.T) { want *TransactionResponse wantErr helpers.Error }{ + { + name: "success", + args: args{ + from: bondAuxiliaryFailureAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: asset.GetClassificationID(), + immutableProps: asset.GetImmutables().GetImmutablePropertyList(), + mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(1)))), + }, + setup: func(t *testing.T) { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + mintAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + bondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, + want: newTransactionResponse(assetID), + wantErr: nil, + }, { name: "minting not enabled", args: args{ @@ -212,12 +220,13 @@ func TestTransactionKeeperTransact(t *testing.T) { args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), - classificationID: authorizeAuxiliaryFailureClassificationID, + classificationID: baseIDs.PrototypeClassificationID(), immutableProps: baseLists.NewPropertyList(), mutableProps: baseLists.NewPropertyList(), }, setup: func(t *testing.T) { parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))) + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() }, wantErr: errorConstants.MockError, }, @@ -230,7 +239,9 @@ func TestTransactionKeeperTransact(t *testing.T) { immutableProps: baseLists.NewPropertyList(), mutableProps: baseLists.NewPropertyList(), }, - setup: func(t *testing.T) {}, + setup: func(t *testing.T) { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, wantErr: errorConstants.MockError, }, { @@ -249,6 +260,8 @@ func TestTransactionKeeperTransact(t *testing.T) { baseDocuments.NewOrder(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewStringData("val1")))), baseQualified.NewMutables(baseLists.NewPropertyList())))) + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, wantErr: errorConstants.EntityAlreadyExists, }, @@ -257,11 +270,15 @@ func TestTransactionKeeperTransact(t *testing.T) { args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), - classificationID: conformAuxiliaryFailureID, + classificationID: baseIDs.PrototypeClassificationID(), immutableProps: baseLists.NewPropertyList(), mutableProps: baseLists.NewPropertyList(), }, - setup: func(t *testing.T) {}, + setup: func(t *testing.T) { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + + }, wantErr: errorConstants.MockError, }, { @@ -273,9 +290,30 @@ func TestTransactionKeeperTransact(t *testing.T) { immutableProps: baseLists.NewPropertyList(), mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(-1)))), }, - setup: func(t *testing.T) {}, + setup: func(t *testing.T) { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + + }, wantErr: errorConstants.IncorrectFormat, }, + { + name: "mint auxiliary failure", + args: args{ + from: genesisAddress, + toID: baseIDs.PrototypeIdentityID(), + classificationID: baseIDs.PrototypeClassificationID(), + immutableProps: baseLists.NewPropertyList(), + mutableProps: baseLists.NewPropertyList(), + }, + setup: func(t *testing.T) { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + mintAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + + }, + wantErr: errorConstants.MockError, + }, { name: "bond auxiliary failure", args: args{ @@ -286,7 +324,12 @@ func TestTransactionKeeperTransact(t *testing.T) { mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(1)))), }, setup: func(t *testing.T) { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + mintAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + bondAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() }, + want: nil, wantErr: errorConstants.MockError, }, { @@ -298,7 +341,11 @@ func TestTransactionKeeperTransact(t *testing.T) { immutableProps: baseLists.NewPropertyList(), mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewNumberData(sdkTypes.NewInt(1)))), }, - setup: func(t *testing.T) {}, + setup: func(t *testing.T) { + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + mintAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + }, wantErr: errorConstants.MetaDataError, }, } @@ -313,10 +360,10 @@ func TestTransactionKeeperTransact(t *testing.T) { baseIDs.PrototypeIdentityID(), tt.args.toID, tt.args.classificationID, - baseLists.NewPropertyList(), tt.args.immutableProps, baseLists.NewPropertyList(), tt.args.mutableProps, + baseLists.NewPropertyList(), ).(helpers.Message)) if (err != nil) && !tt.wantErr.Is(err) { diff --git a/x/assets/transactions/renumerate/transaction_keeper.go b/x/assets/transactions/renumerate/transaction_keeper.go index e5fffff39..0de6b57f7 100644 --- a/x/assets/transactions/renumerate/transaction_keeper.go +++ b/x/assets/transactions/renumerate/transaction_keeper.go @@ -60,7 +60,8 @@ func (transactionKeeper transactionKeeper) Handle(context context.Context, messa supply := asset.GetSupply() - // TODO: Clarify why supply property can't be meta + // TODO: Clarify why supply property can't be meta, + // The first if statement is to check if the supply property is not meta and the second if statement is to check if the supply property is meta if supplyProperty := asset.GetProperty(propertyConstants.SupplyProperty.GetID()); supplyProperty != nil && !supplyProperty.IsMeta() { auxiliaryResponse, err := transactionKeeper.supplementAuxiliary.GetKeeper().Help(context, supplement.NewAuxiliaryRequest(supplyProperty)) if err != nil { diff --git a/x/assets/transactions/renumerate/transaction_keeper_test.go b/x/assets/transactions/renumerate/transaction_keeper_test.go index 352affa0a..a2e2b609a 100644 --- a/x/assets/transactions/renumerate/transaction_keeper_test.go +++ b/x/assets/transactions/renumerate/transaction_keeper_test.go @@ -86,6 +86,12 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + propListsupplyMetamutables = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + propListsupplyMeta = baseQualified.NewMutables(propListsupplyMetamutables).GetMutablePropertyList().Add( + //baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + ) + propList = baseQualified.NewMutables(mutableMetaProperties).GetMutablePropertyList().Add( baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) @@ -145,11 +151,11 @@ var ( _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). + Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), parameterManager, authenticateAuxiliary, @@ -274,6 +280,21 @@ func TestTransactionKeeperTransact(t *testing.T) { want: nil, wantErr: errorConstants.MockError, }, + //{ + // name: "Supplement Auxiliary Metadata Failure", + // args: args{ + // from: genesisAddress, + // fromID: baseIDs.PrototypeIdentityID(), + // assetID: testNewAssetID, + // }, + // setup: func() { + // renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + // authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + // supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(propListsupplyMeta)).Once() + // }, + // want: nil, + // wantErr: errorConstants.MetaDataError, + //}, { name: "Renumerate Auxiliary Failure", args: args{ From b9bd3f62e0f70a9ab6d424df25fc458d647a046a Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 10:18:02 +0530 Subject: [PATCH 09/21] burn tk refactored --- .../burn/transaction_keeper_test.go | 112 +++++++++--------- 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/x/assets/transactions/burn/transaction_keeper_test.go b/x/assets/transactions/burn/transaction_keeper_test.go index dd227224c..341662508 100644 --- a/x/assets/transactions/burn/transaction_keeper_test.go +++ b/x/assets/transactions/burn/transaction_keeper_test.go @@ -83,47 +83,52 @@ const ( ) var ( - moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - immutableMesaProperties = baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList)) - supplymutableMesaPropertiesList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) - mutableMesaPropertiesList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) - mutableMetaPropertiesList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) - propList = baseQualified.NewMutables(mutableMetaPropertiesList).GetMutablePropertyList().Add( - baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), - baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + + //Mesa Property List variables + immutablesMesaMock = baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList)) + + //Burn Height Asset - Mesa + burnHeightMesaPropList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) + burnHeightMesaMutables = baseQualified.NewMutables(burnHeightMesaPropList).GetMutablePropertyList().Add( + baseProperties.NewMesaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(13))), + baseProperties.NewMesaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), ) + burnHeightAssetMesaMutables = baseQualified.NewMutables(burnHeightMesaMutables) + burnHeightMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutablesMesaMock, burnHeightAssetMesaMutables), immutablesMesaMock, burnHeightAssetMesaMutables) + burnHeightMesaAssetID = baseIDs.NewAssetID(burnHeightMesaAsset.GetClassificationID(), burnHeightMesaAsset.GetImmutables()).(*baseIDs.AssetID) - propListburnHeightMetamutables = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) - propListburnHeightMeta = baseQualified.NewMutables(propListburnHeightMetamutables).GetMutablePropertyList().Add( + //Supply Asset - Mesa + supplyMesaPropList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) + supplyMesaMutables = baseQualified.NewMutables(supplyMesaPropList).GetMutablePropertyList().Add( + baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), + ) + supplyAssetMesaMutables = baseQualified.NewMutables(supplyMesaMutables) + supplyMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutablesMesaMock, supplyAssetMesaMutables), immutablesMesaMock, supplyAssetMesaMutables) + supplyMesaAssetID = baseIDs.NewAssetID(supplyMesaAsset.GetClassificationID(), supplyMesaAsset.GetImmutables()).(*baseIDs.AssetID) + + //Meta Property List variables + burnHeightMetaPropList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + burnHeightMetaMutables = baseQualified.NewMutables(burnHeightMetaPropList).GetMutablePropertyList().Add( baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), baseProperties.NewMetaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(20))), ) - propListsupplyMetamutables = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) - propListsupplyMeta = baseQualified.NewMutables(propListsupplyMetamutables).GetMutablePropertyList().Add( + supplyMetaPropList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + supplyMetaMutables = baseQualified.NewMutables(supplyMetaPropList).GetMutablePropertyList().Add( baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) - supplyPropertyMesaProp = baseQualified.NewMutables(supplymutableMesaPropertiesList).GetMutablePropertyList().Add( - baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), - ) - - burnHeightMesaProp = baseQualified.NewMutables(mutableMesaPropertiesList).GetMutablePropertyList().Add( - baseProperties.NewMesaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(13))), - baseProperties.NewMesaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), + //Burn Enabled Asset - Meta + mutableMetaMock = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + BurnEnableMetaMutables = baseQualified.NewMutables(mutableMetaMock).GetMutablePropertyList().Add( + baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) - burnHeightMesaPropMutables = baseQualified.NewMutables(burnHeightMesaProp) - burnHeightMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutableMesaProperties, burnHeightMesaPropMutables), immutableMesaProperties, burnHeightMesaPropMutables) - burnHeightMesaAssetID = baseIDs.NewAssetID(burnHeightMesaAsset.GetClassificationID(), burnHeightMesaAsset.GetImmutables()).(*baseIDs.AssetID) - - supplyPropertyMesaPropMutables = baseQualified.NewMutables(supplyPropertyMesaProp) - supplyPropertyMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutableMesaProperties, supplyPropertyMesaPropMutables), immutableMesaProperties, supplyPropertyMesaPropMutables) - supplyPropertyMesaAssetID = baseIDs.NewAssetID(supplyPropertyMesaAsset.GetClassificationID(), supplyPropertyMesaAsset.GetImmutables()).(*baseIDs.AssetID) - - newMutables = baseQualified.NewMutables(propList) - asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) - assetID = baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()).(*baseIDs.AssetID) + BurnEnabledAssetMetaMutable = baseQualified.NewMutables(BurnEnableMetaMutables) + asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, BurnEnabledAssetMetaMutable), immutables, BurnEnabledAssetMetaMutable) + assetID = baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()).(*baseIDs.AssetID) authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) authenticateAuxiliary = new(MockAuxiliary) @@ -138,9 +143,8 @@ var ( _ = purgeAuxiliary.On("GetKeeper").Return(purgeAuxiliaryKeeper) supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) - - supplementAuxiliary = new(MockAuxiliary) - _ = supplementAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) + supplementAuxiliary = new(MockAuxiliary) + _ = supplementAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) unbondAuxiliaryKeeper = new(MockAuxiliaryKeeper) unbondAuxiliary = new(MockAuxiliary) @@ -205,7 +209,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr helpers.Error }{ { - name: "burnDisabledSuccess", + name: "BurnPropertyDisabled", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -219,7 +223,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.NotAuthorized, }, { - name: "burnAssetSuccess", + name: "BurnTransactionKeeperSuccess", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -236,7 +240,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: nil, }, { - name: "burnAssetNotAuthenticated", + name: "AuthenticationFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -249,7 +253,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "burnAssetNotAuthorized", + name: "AuthorizationFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -264,7 +268,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.NotAuthorized, }, { - name: "burnAssetEntityNotFound", + name: "BurnAssetEntityNotFound", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -278,7 +282,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.EntityNotFound, }, { - name: "bondAmountSupplementAuxiliaryFailure", + name: "BurnHeightSupplementAuxiliaryFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -295,7 +299,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "bondHeightMetaDataAuxiliaryResponse", + name: "BurnHeightMetaDataError", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -305,14 +309,14 @@ func TestTransactionKeeperTransact(t *testing.T) { TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(burnHeightMesaAsset)) authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(propListburnHeightMeta), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(burnHeightMetaMutables), nil).Once() }, want: nil, wantErr: errorConstants.NotAuthorized, }, { - name: "burnAmountSupplementMetaDataError", + name: "BurnHeightPropertyNotRevealed", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -322,21 +326,21 @@ func TestTransactionKeeperTransact(t *testing.T) { TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(burnHeightMesaAsset)) authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(mutableMetaPropertiesList), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(mutableMetaMock), nil).Once() }, want: nil, wantErr: errorConstants.MetaDataError, }, { - name: "SupplementAuxiliaryFailure", + name: "SupplyPropertySupplementAuxiliaryFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), - assetID: supplyPropertyMesaAssetID, + assetID: supplyMesaAssetID, }, setup: func() { - TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyPropertyMesaAsset)) + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyMesaAsset)) authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() @@ -346,17 +350,17 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "supplyMetaDataSuccess", + name: "SupplyMetaPropertyAuxiliaryResponseSuccess", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), - assetID: supplyPropertyMesaAssetID, + assetID: supplyMesaAssetID, }, setup: func() { - TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyPropertyMesaAsset)) + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyMesaAsset)) authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(propListsupplyMeta), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(supplyMetaMutables), nil).Once() purgeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() }, @@ -364,17 +368,17 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MetaDataError, }, { - name: "supplyMetaDataError", + name: "AssetsWithoutSupplyCannotBeBurnedMetaError", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), - assetID: supplyPropertyMesaAssetID, + assetID: supplyMesaAssetID, }, setup: func() { - TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyPropertyMesaAsset)) + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(supplyMesaAsset)) authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(mutableMetaPropertiesList), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(mutableMetaMock), nil).Once() }, want: nil, From 16bb2773d56d1b543dcdfd9b336736f8e0ae3148 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 10:22:32 +0530 Subject: [PATCH 10/21] define tk refactored --- .../define/transaction_keeper_test.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/x/assets/transactions/define/transaction_keeper_test.go b/x/assets/transactions/define/transaction_keeper_test.go index 0de840e37..cc192af02 100644 --- a/x/assets/transactions/define/transaction_keeper_test.go +++ b/x/assets/transactions/define/transaction_keeper_test.go @@ -11,8 +11,6 @@ import ( "github.com/AssetMantle/modules/x/maintainers/auxiliaries/super" "github.com/AssetMantle/schema/ids" "github.com/AssetMantle/schema/lists" - "github.com/AssetMantle/schema/parameters/base" - constantProperties "github.com/AssetMantle/schema/properties/constants" baseQualified "github.com/AssetMantle/schema/qualified/base" "github.com/cometbft/cometbft/crypto/ed25519" storeTypes "github.com/cosmos/cosmos-sdk/store/types" @@ -26,10 +24,8 @@ import ( "math/rand" "testing" - baseData "github.com/AssetMantle/schema/data/base" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" - baseProperties "github.com/AssetMantle/schema/properties/base" tendermintDB "github.com/cometbft/cometbft-db" "github.com/cometbft/cometbft/libs/log" protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" @@ -42,7 +38,6 @@ import ( baseHelpers "github.com/AssetMantle/modules/helpers/base" dataHelper "github.com/AssetMantle/modules/simulation/schema/types/base" "github.com/AssetMantle/modules/x/assets/mapper" - "github.com/AssetMantle/modules/x/assets/parameters" permissionHelper "github.com/AssetMantle/modules/x/assets/utilities" "github.com/AssetMantle/modules/x/classifications/auxiliaries/define" ) @@ -130,12 +125,6 @@ var ( genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) - parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.MintEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). - Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.UnwrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))) TransactionKeeper = transactionKeeper{mapper.Prototype().Initialize(moduleStoreKey), defineAuxiliary, superAuxiliary, @@ -173,7 +162,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr helpers.Error }{ { - name: "Positive Case", + name: "DefineTransactionKeeperSuccess", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -188,7 +177,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: nil, }, { - name: "Authentication Failure", + name: "AuthenticationFailure", args: args{ from: authenticateAuxiliaryFailureAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -203,7 +192,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "Define Auxiliary Failure", + name: "DefineAuxiliaryFailure", args: args{ from: defineAuxiliaryKeeperFailureAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -219,7 +208,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "Super Auxiliary Failure", + name: "SuperAuxiliaryFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), From d14e90bbd03b0e5093ff4abd4f909fd08c88e347 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 10:31:50 +0530 Subject: [PATCH 11/21] deputize tk refactored --- .../deputize/transaction_keeper_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/x/assets/transactions/deputize/transaction_keeper_test.go b/x/assets/transactions/deputize/transaction_keeper_test.go index 68bb612b6..c1ab1cd40 100644 --- a/x/assets/transactions/deputize/transaction_keeper_test.go +++ b/x/assets/transactions/deputize/transaction_keeper_test.go @@ -89,12 +89,11 @@ var ( authenticateAuxiliary = new(MockAuxiliary) _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - deputizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) - deputizeAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - _ = deputizeAuxiliaryKeeper.On("Help", mock.Anything, deputize.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseIDs.PrototypeIdentityID(), baseIDs.PrototypeClassificationID(), baseLists.NewPropertyList(), true, true, true, permissionHelper.SetModulePermissions(false, true, true)...)).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - _ = deputizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - deputizeAuxiliary = new(MockAuxiliary) - _ = deputizeAuxiliary.On("GetKeeper").Return(deputizeAuxiliaryKeeper) + deputizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + _ = deputizeAuxiliaryKeeper.On("Help", mock.Anything, deputize.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseIDs.PrototypeIdentityID(), baseIDs.PrototypeClassificationID(), baseLists.NewPropertyList(), true, true, true, permissionHelper.SetModulePermissions(false, true, true)...)).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + _ = deputizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + deputizeAuxiliary = new(MockAuxiliary) + _ = deputizeAuxiliary.On("GetKeeper").Return(deputizeAuxiliaryKeeper) codec = baseHelpers.TestCodec() @@ -161,7 +160,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr helpers.Error }{ { - name: "Successful Transaction", + name: "DeputizeTransactionKeeperSuccess", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -179,7 +178,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: nil, }, { - name: "Authentication Failure", + name: "AuthenticationFailure", args: args{ from: authenticateAuxiliaryFailureAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -197,7 +196,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "Deputize Failure", + name: "DeputizeAuxiliaryFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), From e28f2d890e340fee171464352763060addf54c3c Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 10:46:16 +0530 Subject: [PATCH 12/21] mint tk refactored --- .../mint/transaction_keeper_test.go | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/x/assets/transactions/mint/transaction_keeper_test.go b/x/assets/transactions/mint/transaction_keeper_test.go index 21e454ad8..90c967be6 100644 --- a/x/assets/transactions/mint/transaction_keeper_test.go +++ b/x/assets/transactions/mint/transaction_keeper_test.go @@ -84,10 +84,10 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + //Asset - Meta newMutables = baseQualified.NewMutables(baseLists.NewPropertyList()) - - asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) - assetID = baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()).(*baseIDs.AssetID) + asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) + assetID = baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()).(*baseIDs.AssetID) authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) @@ -95,20 +95,23 @@ var ( _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) authenticateAuxiliary = new(MockAuxiliary) _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) - authorizeAuxiliary = new(MockAuxiliary) - _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) - mintAuxiliaryKeeper = new(MockAuxiliaryKeeper) - mintAuxiliaryFailureID = baseIDs.NewIdentityID(baseIDs.NewClassificationID(baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(1)))))), baseQualified.NewImmutables(baseLists.NewPropertyList())) - mintAuxiliary = new(MockAuxiliary) - _ = mintAuxiliary.On("GetKeeper").Return(mintAuxiliaryKeeper) - bondAuxiliaryKeeper = new(MockAuxiliaryKeeper) - bondAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - bondAuxiliary = new(MockAuxiliary) - _ = bondAuxiliary.On("GetKeeper").Return(bondAuxiliaryKeeper) - conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) - conformAuxiliary = new(MockAuxiliary) - _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) + + authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) + authorizeAuxiliary = new(MockAuxiliary) + _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) + + mintAuxiliaryKeeper = new(MockAuxiliaryKeeper) + mintAuxiliary = new(MockAuxiliary) + _ = mintAuxiliary.On("GetKeeper").Return(mintAuxiliaryKeeper) + + bondAuxiliaryKeeper = new(MockAuxiliaryKeeper) + bondAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + bondAuxiliary = new(MockAuxiliary) + _ = bondAuxiliary.On("GetKeeper").Return(bondAuxiliaryKeeper) + + conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) + conformAuxiliary = new(MockAuxiliary) + _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) codec = baseHelpers.TestCodec() paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) @@ -133,9 +136,8 @@ var ( coinSupply = sdkTypes.NewCoins(sdkTypes.NewCoin(Denom, sdkTypes.NewInt(GenesisSupply))) _ = BankKeeper.MintCoins(Context, TestMinterModuleName, coinSupply) - genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) - //parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace("test")) + genesisAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + _ = BankKeeper.SendCoinsFromModuleToAccount(Context, TestMinterModuleName, genesisAddress, coinSupply) parameterManager = parameters.Prototype().Initialize(ParamsKeeper.Subspace(constants.ModuleName).WithKeyTable(parameters.Prototype().GetKeyTable())). Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.WrapAllowedCoinsProperty.GetKey(), baseData.NewListData(baseData.NewStringData(Denom)))))). Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewBooleanData(true))))). @@ -184,7 +186,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr helpers.Error }{ { - name: "success", + name: "MintTransactionKeeperSuccess", args: args{ from: bondAuxiliaryFailureAddress, toID: baseIDs.PrototypeIdentityID(), @@ -202,7 +204,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: nil, }, { - name: "minting not enabled", + name: "MintPropertyNotEnabled", args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), @@ -216,7 +218,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.NotAuthorized, }, { - name: "authorization failure", + name: "AuthorizationFailure", args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), @@ -231,7 +233,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "authentication failure", + name: "AuthenticationFailure", args: args{ from: authenticateAuxiliaryFailureAddress, toID: baseIDs.PrototypeIdentityID(), @@ -245,7 +247,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "asset already exists", + name: "EntityAlreadyExistsError", args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), @@ -266,7 +268,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.EntityAlreadyExists, }, { - name: "conform auxiliary failure", + name: "ConformAuxiliaryFailure", args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), @@ -282,7 +284,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "asset supply negative", + name: "AssetSupplyNegativeIncorrectFormatError", args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), @@ -298,7 +300,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.IncorrectFormat, }, { - name: "mint auxiliary failure", + name: "MintAuxiliaryFailure", args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), @@ -315,7 +317,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "bond auxiliary failure", + name: "BondAuxiliaryFailure", args: args{ from: bondAuxiliaryFailureAddress, toID: baseIDs.PrototypeIdentityID(), @@ -333,7 +335,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "no bond amount property", + name: "BondAmountPropertyMetaDataError", args: args{ from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), From 5d80d5222450db678d3e4d55255f43c70f265c6a Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 10:57:06 +0530 Subject: [PATCH 13/21] mutate tk refactored --- .../mutate/transaction_keeper_test.go | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/x/assets/transactions/mutate/transaction_keeper_test.go b/x/assets/transactions/mutate/transaction_keeper_test.go index 6c49f2c2a..d78d5952e 100644 --- a/x/assets/transactions/mutate/transaction_keeper_test.go +++ b/x/assets/transactions/mutate/transaction_keeper_test.go @@ -8,7 +8,6 @@ import ( "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" errorConstants "github.com/AssetMantle/modules/helpers/constants" - dataHelper "github.com/AssetMantle/modules/simulation/schema/types/base" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/assets/mapper" recordassets "github.com/AssetMantle/modules/x/assets/record" @@ -33,10 +32,8 @@ import ( bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" - paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/mock" - "math/rand" "reflect" "testing" ) @@ -88,31 +85,23 @@ var ( authenticateAuxiliary = new(MockAuxiliary) _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - maintainAuxiliaryKeeper = new(MockAuxiliaryKeeper) - maintainFailureID = baseIDs.NewIdentityID(classificationID, immutables) - - maintainAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) - maintainAuxiliary = new(MockAuxiliary) - _ = maintainAuxiliary.On("GetKeeper").Return(maintainAuxiliaryKeeper) + maintainFailureClassificationID = testAsset.GetClassificationID() + maintainAuxiliaryKeeper = new(MockAuxiliaryKeeper) + maintainFailureID = baseIDs.NewIdentityID(classificationID, immutables) + maintainAuxiliary = new(MockAuxiliary) + _ = maintainAuxiliary.On("GetKeeper").Return(maintainAuxiliaryKeeper) conformAuxiliaryKeeper = new(MockAuxiliaryKeeper) - //conformAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) - //_ = conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - //_ = conformAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - conformAuxiliary = new(MockAuxiliary) - _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) + conformAuxiliary = new(MockAuxiliary) + _ = conformAuxiliary.On("GetKeeper").Return(conformAuxiliaryKeeper) - testNewAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, mutables), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList())) - testNewAssetID = baseIDs.NewAssetID(testNewAsset.GetClassificationID(), testNewAsset.GetImmutables()).(*baseIDs.AssetID) - maintainFailureClassificationID = testNewAsset.GetClassificationID() - conformNewAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, mutables), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList())) - conformNewAssetID = baseIDs.NewAssetID(conformNewAsset.GetClassificationID(), conformNewAsset.GetImmutables()).(*baseIDs.AssetID) + testAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, mutables), baseQualified.NewImmutables(baseLists.NewPropertyList()), baseQualified.NewMutables(baseLists.NewPropertyList())) + testNewAssetID = baseIDs.NewAssetID(testAsset.GetClassificationID(), testAsset.GetImmutables()).(*baseIDs.AssetID) codec = baseHelpers.TestCodec() paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) - ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} @@ -165,7 +154,8 @@ func TestTransactionKeeperTransact(t *testing.T) { want *TransactionResponse wantErr helpers.Error }{ - {"mutateInvalidAsset - validatebasic", + { + "MutateTransactionKeeeperSuccess", args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -180,7 +170,8 @@ func TestTransactionKeeperTransact(t *testing.T) { newTransactionResponse(), nil, }, - {"mutateValidAsset", + { + "MutateValidAsset", args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -195,7 +186,8 @@ func TestTransactionKeeperTransact(t *testing.T) { newTransactionResponse(), nil, }, - {"mutateNonExistentAsset", + { + "EntityNotFoundError", args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -207,7 +199,8 @@ func TestTransactionKeeperTransact(t *testing.T) { nil, errorConstants.EntityNotFound, }, - {"authenticateAuxiliaryFailure", + { + "AuthenticateAuxiliaryFailure", args{ from: authenticateAuxiliaryFailureAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -219,7 +212,8 @@ func TestTransactionKeeperTransact(t *testing.T) { nil, errorConstants.MockError, }, - {"maintainAuxiliaryFailure", + { + "MaintainAuxiliaryFailure", args{ from: genesisAddress, fromID: maintainFailureID, @@ -233,7 +227,8 @@ func TestTransactionKeeperTransact(t *testing.T) { nil, errorConstants.MockError, }, - {"conformAuxiliaryFailure", + { + "ConformAuxiliaryFailure", args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -243,7 +238,7 @@ func TestTransactionKeeperTransact(t *testing.T) { }, func() { maintainAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(testNewAsset.GetClassificationID(), testNewAsset.GetImmutables(), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) + conformAuxiliaryKeeper.On("Help", mock.Anything, conform.NewAuxiliaryRequest(testAsset.GetClassificationID(), testAsset.GetImmutables(), baseQualified.NewMutables(baseLists.NewPropertyList()))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) }, nil, errorConstants.MockError, @@ -254,7 +249,7 @@ func TestTransactionKeeperTransact(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tt.setup() - TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(testNewAsset)) + TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(testAsset)) got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), NewMessage(tt.args.from, From 60f28d743e9153dd268476427c14ab53c04e0569 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 11:03:00 +0530 Subject: [PATCH 14/21] renumerate tk refactored --- .../renumerate/transaction_keeper_test.go | 65 +++++-------------- 1 file changed, 15 insertions(+), 50 deletions(-) diff --git a/x/assets/transactions/renumerate/transaction_keeper_test.go b/x/assets/transactions/renumerate/transaction_keeper_test.go index a2e2b609a..323bcb09b 100644 --- a/x/assets/transactions/renumerate/transaction_keeper_test.go +++ b/x/assets/transactions/renumerate/transaction_keeper_test.go @@ -6,7 +6,6 @@ package renumerate import ( "context" errorConstants "github.com/AssetMantle/modules/helpers/constants" - dataHelper "github.com/AssetMantle/modules/simulation/schema/types/base" "github.com/AssetMantle/modules/x/assets/constants" recordassets "github.com/AssetMantle/modules/x/assets/record" "github.com/AssetMantle/modules/x/metas/auxiliaries/supplement" @@ -23,7 +22,6 @@ import ( govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/mock" - "math/rand" "reflect" "testing" @@ -32,7 +30,6 @@ import ( "github.com/AssetMantle/modules/x/assets/mapper" "github.com/AssetMantle/modules/x/assets/parameters" "github.com/AssetMantle/modules/x/identities/auxiliaries/authenticate" - "github.com/AssetMantle/modules/x/splits/auxiliaries/renumerate" baseData "github.com/AssetMantle/schema/data/base" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" @@ -86,16 +83,9 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - propListsupplyMetamutables = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) - propListsupplyMeta = baseQualified.NewMutables(propListsupplyMetamutables).GetMutablePropertyList().Add( - //baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), - baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), - ) - propList = baseQualified.NewMutables(mutableMetaProperties).GetMutablePropertyList().Add( baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) - newMutables = baseQualified.NewMutables(propList) testNewAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) testNewAssetID = baseIDs.NewAssetID(testNewAsset.GetClassificationID(), testNewAsset.GetImmutables()).(*baseIDs.AssetID) @@ -109,24 +99,16 @@ var ( authorizeAuxiliaryKeeper = new(MockAuxiliaryKeeper) authorizeAuxiliaryFailureClassificationID = baseIDs.NewIdentityID(testNewAsset.GetClassificationID(), immutables) - //_ = authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - authorizeAuxiliary = new(MockAuxiliary) - _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) - - renumerateAuxiliaryKeeper = new(MockAuxiliaryKeeper) - renumerateAuxiliaryAssetID = baseIDs.NewStringID("renumerateFailureAsset") - _ = renumerateAuxiliaryKeeper.On("Help", mock.Anything, renumerate.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseIDs.PrototypeAssetID(), sdkTypes.NewInt(1000))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - //_ = renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authorizeAuxiliary = new(MockAuxiliary) + _ = authorizeAuxiliary.On("GetKeeper").Return(authorizeAuxiliaryKeeper) - renumerateAuxiliary = new(MockAuxiliary) - _ = renumerateAuxiliary.On("GetKeeper").Return(renumerateAuxiliaryKeeper) + renumerateAuxiliaryKeeper = new(MockAuxiliaryKeeper) + renumerateAuxiliary = new(MockAuxiliary) + _ = renumerateAuxiliary.On("GetKeeper").Return(renumerateAuxiliaryKeeper) - supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) - supplementAuxiliaryMutablesFailure = dataHelper.GenerateRandomMetaPropertyListWithoutData(rand.New(rand.NewSource(99))) - //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, supplement.NewAuxiliaryRequest()).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) - //_ = supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - supplementAuxiliary = new(MockAuxiliary) - _ = supplementAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) + supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) + supplementAuxiliary = new(MockAuxiliary) + _ = supplementAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) codec = baseHelpers.TestCodec() @@ -193,7 +175,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr helpers.Error }{ { - name: "Success Case", + name: "RenumerateTransactionKeeperSuccess", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -209,7 +191,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: nil, }, { - name: "Renumerate Property Disabled", + name: "RenumeratePropertyDisabled", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -217,14 +199,13 @@ func TestTransactionKeeperTransact(t *testing.T) { denom: Denom, }, setup: func() { - //authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() parameterManager.Set(sdkTypes.WrapSDKContext(Context), baseLists.NewParameterList(base.NewParameter(baseProperties.NewMetaProperty(constantProperties.RenumerateEnabledProperty.GetKey(), baseData.NewBooleanData(false))))) }, want: nil, wantErr: errorConstants.NotAuthorized, }, { - name: "Authentication Failure", + name: "AuthenticationFailure", args: args{ from: authenticateAuxiliaryFailureAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -238,7 +219,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "Entity Not Found Failure", + name: "EntityNotFoundFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -252,7 +233,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.EntityNotFound, }, { - name: "Authorize Auxiliary Failure", + name: "AuthorizeAuxiliaryFailure", args: args{ from: genesisAddress, fromID: authorizeAuxiliaryFailureClassificationID, @@ -266,37 +247,21 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "Supplement Auxiliary Failure", + name: "SupplementAuxiliaryFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), assetID: testNewAssetID, }, setup: func() { - //TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(testNewAsset)) authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() }, want: nil, wantErr: errorConstants.MockError, }, - //{ - // name: "Supplement Auxiliary Metadata Failure", - // args: args{ - // from: genesisAddress, - // fromID: baseIDs.PrototypeIdentityID(), - // assetID: testNewAssetID, - // }, - // setup: func() { - // renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() - // authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - // supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(propListsupplyMeta)).Once() - // }, - // want: nil, - // wantErr: errorConstants.MetaDataError, - //}, { - name: "Renumerate Auxiliary Failure", + name: "RenumerateAuxiliaryFailure", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), From d2eaf1dcff7e0922d96282bb95efc84bb4e14fbc Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 11:04:10 +0530 Subject: [PATCH 15/21] revoke tk refactored --- x/assets/transactions/revoke/transaction_keeper_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/assets/transactions/revoke/transaction_keeper_test.go b/x/assets/transactions/revoke/transaction_keeper_test.go index 4d12d7c57..e0d10ee58 100644 --- a/x/assets/transactions/revoke/transaction_keeper_test.go +++ b/x/assets/transactions/revoke/transaction_keeper_test.go @@ -160,7 +160,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr helpers.Error }{ { - name: "Positive Case", + name: "RevokeTransactionKeeperSuccess", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -173,7 +173,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: nil, }, { - name: "Authentication Failure", + name: "AuthenticationFailure", args: args{ from: authenticateAuxiliaryFailureAddress, fromID: baseIDs.PrototypeIdentityID(), @@ -186,7 +186,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "Revoke Auxiliary Failure", + name: "RevokeAuxiliaryFailure", args: args{ from: revokeAuxiliaryFailureAddress, fromID: revokeAuxiliaryKeeperFailureID, From 8be90f36e086b242a9fa88bf8f32750216db4f86 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 11:08:48 +0530 Subject: [PATCH 16/21] send tk refactored --- .../send/transaction_keeper_test.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index 87e8a9f03..f7a06e70b 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -83,7 +83,6 @@ var ( randomMetaPropertyGenerator = func() properties.MetaProperty { return baseProperties.NewMetaProperty(baseIDs.NewStringID(random.GenerateUniqueIdentifier()), baseData.NewStringData(random.GenerateUniqueIdentifier())) } - randomAssetGenerator = func(withImmutable, withMutable properties.Property) documents.Asset { immutables := baseQualified.NewImmutables(baseLists.NewPropertyList(withImmutable, randomMetaPropertyGenerator(), randomMetaPropertyGenerator(), randomMetaPropertyGenerator())) mutables := baseQualified.NewMutables(baseLists.NewPropertyList(withMutable, randomMetaPropertyGenerator(), randomMetaPropertyGenerator(), randomMetaPropertyGenerator())) @@ -110,12 +109,10 @@ var ( authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - authenticateAuxiliary = new(MockAuxiliary) - _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - - supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) - + supplementAuxiliaryKeeper = new(MockAuxiliaryKeeper) supplementAuxiliaryFailureAsset = randomAssetGenerator( baseProperties.NewMesaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(0))), nil, @@ -133,15 +130,13 @@ var ( supplementAuxiliaryAuxiliary = new(MockAuxiliary) _ = supplementAuxiliaryAuxiliary.On("GetKeeper").Return(supplementAuxiliaryKeeper) - transferAuxiliaryKeeper = new(MockAuxiliaryKeeper) - + transferAuxiliaryKeeper = new(MockAuxiliaryKeeper) transferAuxiliaryFailureAsset = randomAssetGenerator(baseProperties.NewMetaProperty(constantProperties.LockHeightProperty.GetKey(), baseData.NewHeightData(baseTypes.NewHeight(0))), nil) transferAuxiliaryFailureAssetID = baseIDs.NewAssetID(transferAuxiliaryFailureAsset.GetClassificationID(), transferAuxiliaryFailureAsset.GetImmutables()).(*baseIDs.AssetID) _ = transferAuxiliaryKeeper.On("Help", mock.Anything, transfer.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseIDs.PrototypeIdentityID(), transferAuxiliaryFailureAssetID, sdkTypes.NewInt(1))).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) _ = transferAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - - transferAuxiliaryAuxiliary = new(MockAuxiliary) - _ = transferAuxiliaryAuxiliary.On("GetKeeper").Return(transferAuxiliaryKeeper) + transferAuxiliaryAuxiliary = new(MockAuxiliary) + _ = transferAuxiliaryAuxiliary.On("GetKeeper").Return(transferAuxiliaryKeeper) codec = baseHelpers.TestCodec() From d4615cc04b033b8a1ddb6670d86e597f2ba008d3 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 11:11:27 +0530 Subject: [PATCH 17/21] unwrap tk refactored --- .../unwrap/transaction_keeper_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/x/assets/transactions/unwrap/transaction_keeper_test.go b/x/assets/transactions/unwrap/transaction_keeper_test.go index f0487a3d6..f414ddc38 100644 --- a/x/assets/transactions/unwrap/transaction_keeper_test.go +++ b/x/assets/transactions/unwrap/transaction_keeper_test.go @@ -86,22 +86,21 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + newCollectionFaliure = "notfound" + authenticateAuxiliaryKeeper = new(MockAuxiliaryKeeper) authenticateAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(authenticateAuxiliaryFailureAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) _ = authenticateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) + authenticateAuxiliary = new(MockAuxiliary) + _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - burnAuxiliaryKeeper = new(MockAuxiliaryKeeper) - newCollectionFaliure = "notfound" burnAuxiliaryFailureDenom = "burn" + burnAuxiliaryKeeper = new(MockAuxiliaryKeeper) _ = burnAuxiliaryKeeper.On("Help", mock.Anything, burn.NewAuxiliaryRequest(baseIDs.PrototypeIdentityID(), baseDocuments.NewCoinAsset(burnAuxiliaryFailureDenom).GetCoinAssetID(), sdkTypes.OneInt())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) _ = burnAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil) - - authenticateAuxiliary = new(MockAuxiliary) - _ = authenticateAuxiliary.On("GetKeeper").Return(authenticateAuxiliaryKeeper) - - burnAuxiliary = new(MockAuxiliary) - _ = burnAuxiliary.On("GetKeeper").Return(burnAuxiliaryKeeper) + burnAuxiliary = new(MockAuxiliary) + _ = burnAuxiliary.On("GetKeeper").Return(burnAuxiliaryKeeper) codec = baseHelpers.TestCodec() From 3382354435f774ab84efa083b23fd32cd555800c Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Wed, 31 Jul 2024 11:33:19 +0530 Subject: [PATCH 18/21] renumerate tk.go refactored --- x/assets/transactions/renumerate/transaction_keeper.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/x/assets/transactions/renumerate/transaction_keeper.go b/x/assets/transactions/renumerate/transaction_keeper.go index 0de6b57f7..e8a94e64f 100644 --- a/x/assets/transactions/renumerate/transaction_keeper.go +++ b/x/assets/transactions/renumerate/transaction_keeper.go @@ -60,8 +60,6 @@ func (transactionKeeper transactionKeeper) Handle(context context.Context, messa supply := asset.GetSupply() - // TODO: Clarify why supply property can't be meta, - // The first if statement is to check if the supply property is not meta and the second if statement is to check if the supply property is meta if supplyProperty := asset.GetProperty(propertyConstants.SupplyProperty.GetID()); supplyProperty != nil && !supplyProperty.IsMeta() { auxiliaryResponse, err := transactionKeeper.supplementAuxiliary.GetKeeper().Help(context, supplement.NewAuxiliaryRequest(supplyProperty)) if err != nil { @@ -69,7 +67,6 @@ func (transactionKeeper transactionKeeper) Handle(context context.Context, messa } if supplyProperty = supplement.GetMetaPropertiesFromResponse(auxiliaryResponse).GetProperty(propertyConstants.SupplyProperty.GetID()); supplyProperty != nil && supplyProperty.IsMeta() { - //TODO: This type casting will panic if the property is not a meta property supply = supplyProperty.Get().(properties.MetaProperty).GetData().Get().(data.NumberData).Get() } else { return nil, errorConstants.MetaDataError.Wrapf("supply property is not revealed") From f610c29e70c35fff4f95558be8f31cadf34dffec Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 6 Aug 2024 12:59:38 +0530 Subject: [PATCH 19/21] burn comments removed --- .../burn/transaction_keeper_test.go | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/x/assets/transactions/burn/transaction_keeper_test.go b/x/assets/transactions/burn/transaction_keeper_test.go index 341662508..c6219cd53 100644 --- a/x/assets/transactions/burn/transaction_keeper_test.go +++ b/x/assets/transactions/burn/transaction_keeper_test.go @@ -85,10 +85,8 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - //Mesa Property List variables immutablesMesaMock = baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList)) - //Burn Height Asset - Mesa burnHeightMesaPropList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) burnHeightMesaMutables = baseQualified.NewMutables(burnHeightMesaPropList).GetMutablePropertyList().Add( baseProperties.NewMesaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(13))), @@ -98,7 +96,6 @@ var ( burnHeightMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutablesMesaMock, burnHeightAssetMesaMutables), immutablesMesaMock, burnHeightAssetMesaMutables) burnHeightMesaAssetID = baseIDs.NewAssetID(burnHeightMesaAsset.GetClassificationID(), burnHeightMesaAsset.GetImmutables()).(*baseIDs.AssetID) - //Supply Asset - Mesa supplyMesaPropList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) supplyMesaMutables = baseQualified.NewMutables(supplyMesaPropList).GetMutablePropertyList().Add( baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), @@ -107,7 +104,6 @@ var ( supplyMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutablesMesaMock, supplyAssetMesaMutables), immutablesMesaMock, supplyAssetMesaMutables) supplyMesaAssetID = baseIDs.NewAssetID(supplyMesaAsset.GetClassificationID(), supplyMesaAsset.GetImmutables()).(*baseIDs.AssetID) - //Meta Property List variables burnHeightMetaPropList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) burnHeightMetaMutables = baseQualified.NewMutables(burnHeightMetaPropList).GetMutablePropertyList().Add( baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), @@ -120,7 +116,6 @@ var ( baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) - //Burn Enabled Asset - Meta mutableMetaMock = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) BurnEnableMetaMutables = baseQualified.NewMutables(mutableMetaMock).GetMutablePropertyList().Add( baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), @@ -400,23 +395,6 @@ func TestTransactionKeeperTransact(t *testing.T) { want: nil, wantErr: errorConstants.MockError, }, - //{ - // name: "noRevealedBondAmountFailure", - // args: args{ - // from: genesisAddress, - // fromID: baseIDs.PrototypeIdentityID(), - // assetID: burnHeightMesaAssetID, - // }, - // setup: func() { - // TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Add(recordassets.NewRecord(burnHeightMesaAsset)) - // authenticateAuxiliaryKeeper.On("Help", mock.Anything, authenticate.NewAuxiliaryRequest(genesisAddress, baseIDs.PrototypeIdentityID())).Return(new(helpers.AuxiliaryResponse), nil).Once() - // purgeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - // supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - // authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() - // }, - // want: nil, - // wantErr: errorConstants.MetaDataError, - //}, { name: "unbondAuxiliaryFailure", args: args{ @@ -454,5 +432,3 @@ func TestTransactionKeeperTransact(t *testing.T) { }) } } - -//sdkTypes.NewInt(10) From 8aeff8f7beb6afd4587061b8a33b16025533e55b Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 6 Aug 2024 13:39:28 +0530 Subject: [PATCH 20/21] renumerate negative supply fix --- .../define/transaction_keeper_test.go | 2 -- .../mint/transaction_keeper_test.go | 3 -- .../renumerate/transaction_keeper_test.go | 35 ++++++++++++++++++- .../revoke/transaction_keeper_test.go | 2 +- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/x/assets/transactions/define/transaction_keeper_test.go b/x/assets/transactions/define/transaction_keeper_test.go index cc192af02..47a811df4 100644 --- a/x/assets/transactions/define/transaction_keeper_test.go +++ b/x/assets/transactions/define/transaction_keeper_test.go @@ -31,7 +31,6 @@ import ( protoTendermintTypes "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/store" sdkTypes "github.com/cosmos/cosmos-sdk/types" - paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" "github.com/stretchr/testify/require" "github.com/AssetMantle/modules/helpers" @@ -107,7 +106,6 @@ var ( paramsStoreKey = sdkTypes.NewKVStoreKey(paramsTypes.StoreKey) paramsTransientStoreKeys = sdkTypes.NewTransientStoreKey(paramsTypes.TStoreKey) - ParamsKeeper = paramsKeeper.NewKeeper(codec, codec.GetLegacyAmino(), paramsStoreKey, paramsTransientStoreKeys) authStoreKey = sdkTypes.NewKVStoreKey(authTypes.StoreKey) moduleAccountPermissions = map[string][]string{TestMinterModuleName: {authTypes.Minter}, constants.ModuleName: nil} diff --git a/x/assets/transactions/mint/transaction_keeper_test.go b/x/assets/transactions/mint/transaction_keeper_test.go index 90c967be6..16d511245 100644 --- a/x/assets/transactions/mint/transaction_keeper_test.go +++ b/x/assets/transactions/mint/transaction_keeper_test.go @@ -43,7 +43,6 @@ import ( "testing" ) -// start type MockAuxiliary struct { mock.Mock } @@ -84,7 +83,6 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - //Asset - Meta newMutables = baseQualified.NewMutables(baseLists.NewPropertyList()) asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) assetID = baseIDs.NewAssetID(asset.GetClassificationID(), asset.GetImmutables()).(*baseIDs.AssetID) @@ -356,7 +354,6 @@ func TestTransactionKeeperTransact(t *testing.T) { t.Run(tt.name, func(t *testing.T) { tt.setup(t) - //fmt.Print(tt.args.classificationID) got, err := TransactionKeeper.Transact(sdkTypes.WrapSDKContext(Context), NewMessage( tt.args.from, baseIDs.PrototypeIdentityID(), diff --git a/x/assets/transactions/renumerate/transaction_keeper_test.go b/x/assets/transactions/renumerate/transaction_keeper_test.go index 323bcb09b..a56bbc064 100644 --- a/x/assets/transactions/renumerate/transaction_keeper_test.go +++ b/x/assets/transactions/renumerate/transaction_keeper_test.go @@ -33,6 +33,7 @@ import ( baseData "github.com/AssetMantle/schema/data/base" baseIDs "github.com/AssetMantle/schema/ids/base" baseLists "github.com/AssetMantle/schema/lists/base" + baseMetaProp "github.com/AssetMantle/schema/properties/base" baseProperties "github.com/AssetMantle/schema/properties/base" baseQualified "github.com/AssetMantle/schema/qualified/base" tendermintDB "github.com/cometbft/cometbft-db" @@ -83,6 +84,9 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + SupplyNotRevealedProperty = baseMetaProp.NewMetaProperty(baseIDs.NewStringID("supply"), baseData.NewBooleanData(false)) + NegativeSupplyProperty = baseMetaProp.NewMetaProperty(constantProperties.SupplyProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(-1))) + propList = baseQualified.NewMutables(mutableMetaProperties).GetMutablePropertyList().Add( baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), ) @@ -227,7 +231,6 @@ func TestTransactionKeeperTransact(t *testing.T) { denom: Denom, }, setup: func() { - //authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() }, want: nil, wantErr: errorConstants.EntityNotFound, @@ -260,6 +263,36 @@ func TestTransactionKeeperTransact(t *testing.T) { want: nil, wantErr: errorConstants.MockError, }, + { + name: "SuupplyNotRevealedError", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: testNewAssetID, + }, + setup: func() { + renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList(SupplyNotRevealedProperty)), nil).Once() + }, + want: nil, + wantErr: errorConstants.MetaDataError, + }, + { + name: "NegativeSupplyFailure", + args: args{ + from: genesisAddress, + fromID: baseIDs.PrototypeIdentityID(), + assetID: testNewAssetID, + }, + setup: func() { + renumerateAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError).Once() + authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() + supplementAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(supplement.NewAuxiliaryResponse(baseLists.NewPropertyList(NegativeSupplyProperty)), nil).Once() + }, + want: nil, + wantErr: errorConstants.MetaDataError, + }, { name: "RenumerateAuxiliaryFailure", args: args{ diff --git a/x/assets/transactions/revoke/transaction_keeper_test.go b/x/assets/transactions/revoke/transaction_keeper_test.go index e0d10ee58..5bea52de0 100644 --- a/x/assets/transactions/revoke/transaction_keeper_test.go +++ b/x/assets/transactions/revoke/transaction_keeper_test.go @@ -91,7 +91,7 @@ var ( revokeAuxiliaryKeeper = new(MockAuxiliaryKeeper) revokeAuxiliaryFailureAddress = sdkTypes.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - revokeAuxiliaryKeeperFailureID = baseIDs.NewIdentityID(baseIDs.NewClassificationID(immutables, mutables), immutables) //baseIDs.PrototypeIdentityID() + revokeAuxiliaryKeeperFailureID = baseIDs.NewIdentityID(baseIDs.NewClassificationID(immutables, mutables), immutables) _ = revokeAuxiliaryKeeper.On("Help", mock.Anything, revoke.NewAuxiliaryRequest(revokeAuxiliaryKeeperFailureID, baseIDs.PrototypeIdentityID(), baseIDs.PrototypeClassificationID())).Return(new(helpers.AuxiliaryResponse), errorConstants.MockError) _ = revokeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(define.NewAuxiliaryResponse(baseIDs.PrototypeClassificationID()), nil) revokeAuxiliary = new(MockAuxiliary) From 7118017f2d12667f7cc9974cac8b26a1a6de37b6 Mon Sep 17 00:00:00 2001 From: Sid-AssetMantle Date: Tue, 6 Aug 2024 16:05:03 +0530 Subject: [PATCH 21/21] refactored test cases --- .../burn/transaction_keeper_test.go | 45 ++++++++++--------- .../define/transaction_keeper_test.go | 8 ++-- .../deputize/transaction_keeper_test.go | 8 ++-- .../mint/transaction_keeper_test.go | 24 ++++++---- .../mutate/transaction_keeper_test.go | 8 ++-- .../renumerate/transaction_keeper_test.go | 19 ++++---- .../revoke/transaction_keeper_test.go | 8 ++-- .../send/transaction_keeper_test.go | 8 ++-- .../unwrap/transaction_keeper_test.go | 8 ++-- .../wrap/transaction_keeper_test.go | 8 ++-- 10 files changed, 79 insertions(+), 65 deletions(-) diff --git a/x/assets/transactions/burn/transaction_keeper_test.go b/x/assets/transactions/burn/transaction_keeper_test.go index c6219cd53..e235f9e49 100644 --- a/x/assets/transactions/burn/transaction_keeper_test.go +++ b/x/assets/transactions/burn/transaction_keeper_test.go @@ -15,7 +15,7 @@ import ( "github.com/AssetMantle/schema/parameters/base" constantProperties "github.com/AssetMantle/schema/properties/constants" baseQualified "github.com/AssetMantle/schema/qualified/base" - base2 "github.com/AssetMantle/schema/types/base" + baseType "github.com/AssetMantle/schema/types/base" "github.com/cometbft/cometbft/crypto/ed25519" storeTypes "github.com/cosmos/cosmos-sdk/store/types" authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -25,6 +25,7 @@ import ( govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/mock" + "math/rand" "reflect" "testing" @@ -41,6 +42,7 @@ import ( "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" + baseProp "github.com/AssetMantle/modules/simulation/schema/types/base" "github.com/AssetMantle/modules/x/assets/mapper" "github.com/AssetMantle/modules/x/assets/parameters" ) @@ -66,12 +68,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } @@ -85,41 +87,44 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - immutablesMesaMock = baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList)) + randomInteger int64 = 100 + randomSeed int64 = 99 - burnHeightMesaPropList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) + immutablesMesaMock = baseQualified.NewImmutables(baseProp.GenerateRandomPropertyList(rand.New(rand.NewSource(randomSeed)))) + + burnHeightMesaPropList = baseProp.GenerateRandomPropertyList(rand.New(rand.NewSource(randomSeed))) burnHeightMesaMutables = baseQualified.NewMutables(burnHeightMesaPropList).GetMutablePropertyList().Add( - baseProperties.NewMesaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(13))), - baseProperties.NewMesaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), + baseProperties.NewMesaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(baseType.NewHeight(randomInteger))), + baseProperties.NewMesaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), ) burnHeightAssetMesaMutables = baseQualified.NewMutables(burnHeightMesaMutables) burnHeightMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutablesMesaMock, burnHeightAssetMesaMutables), immutablesMesaMock, burnHeightAssetMesaMutables) burnHeightMesaAssetID = baseIDs.NewAssetID(burnHeightMesaAsset.GetClassificationID(), burnHeightMesaAsset.GetImmutables()).(*baseIDs.AssetID) - supplyMesaPropList = baseLists.NewPropertyList(baseProperties.NewMesaProperty(baseIDs.NewStringID("mockMesaProp"), baseData.NewListData())).(*baseLists.PropertyList) + supplyMesaPropList = baseProp.GenerateRandomPropertyList(rand.New(rand.NewSource(randomSeed))) supplyMesaMutables = baseQualified.NewMutables(supplyMesaPropList).GetMutablePropertyList().Add( - baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(34))), + baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), ) supplyAssetMesaMutables = baseQualified.NewMutables(supplyMesaMutables) supplyMesaAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutablesMesaMock, supplyAssetMesaMutables), immutablesMesaMock, supplyAssetMesaMutables) supplyMesaAssetID = baseIDs.NewAssetID(supplyMesaAsset.GetClassificationID(), supplyMesaAsset.GetImmutables()).(*baseIDs.AssetID) - burnHeightMetaPropList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + burnHeightMetaPropList = baseProp.GenerateRandomPropertyList(rand.New(rand.NewSource(randomSeed))) burnHeightMetaMutables = baseQualified.NewMutables(burnHeightMetaPropList).GetMutablePropertyList().Add( - baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), - baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), - baseProperties.NewMetaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(base2.NewHeight(20))), + baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), + baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), + baseProperties.NewMetaProperty(constantProperties.BurnHeightProperty.GetKey(), baseData.NewHeightData(baseType.NewHeight(randomInteger))), ) - supplyMetaPropList = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + supplyMetaPropList = baseProp.GenerateRandomPropertyList(rand.New(rand.NewSource(randomSeed))) supplyMetaMutables = baseQualified.NewMutables(supplyMetaPropList).GetMutablePropertyList().Add( - baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMetaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), ) - mutableMetaMock = baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("authentication"), baseData.NewListData())).(*baseLists.PropertyList) + mutableMetaMock = baseProp.GenerateRandomPropertyList(rand.New(rand.NewSource(randomSeed))) BurnEnableMetaMutables = baseQualified.NewMutables(mutableMetaMock).GetMutablePropertyList().Add( - baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), - baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMetaProperty(constantProperties.BurnEnabledProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), + baseProperties.NewMetaProperty(constantProperties.BondAmountProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), ) BurnEnabledAssetMetaMutable = baseQualified.NewMutables(BurnEnableMetaMutables) asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, BurnEnabledAssetMetaMutable), immutables, BurnEnabledAssetMetaMutable) diff --git a/x/assets/transactions/define/transaction_keeper_test.go b/x/assets/transactions/define/transaction_keeper_test.go index 47a811df4..6073bf89d 100644 --- a/x/assets/transactions/define/transaction_keeper_test.go +++ b/x/assets/transactions/define/transaction_keeper_test.go @@ -62,12 +62,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } diff --git a/x/assets/transactions/deputize/transaction_keeper_test.go b/x/assets/transactions/deputize/transaction_keeper_test.go index c1ab1cd40..5e36069ae 100644 --- a/x/assets/transactions/deputize/transaction_keeper_test.go +++ b/x/assets/transactions/deputize/transaction_keeper_test.go @@ -63,12 +63,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } diff --git a/x/assets/transactions/mint/transaction_keeper_test.go b/x/assets/transactions/mint/transaction_keeper_test.go index 16d511245..798424b9a 100644 --- a/x/assets/transactions/mint/transaction_keeper_test.go +++ b/x/assets/transactions/mint/transaction_keeper_test.go @@ -8,6 +8,7 @@ import ( "github.com/AssetMantle/modules/helpers" baseHelpers "github.com/AssetMantle/modules/helpers/base" errorConstants "github.com/AssetMantle/modules/helpers/constants" + baseProp "github.com/AssetMantle/modules/simulation/schema/types/base" "github.com/AssetMantle/modules/x/assets/constants" "github.com/AssetMantle/modules/x/assets/key" "github.com/AssetMantle/modules/x/assets/mapper" @@ -39,6 +40,7 @@ import ( paramsKeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramsTypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/mock" + "math/rand" "reflect" "testing" ) @@ -64,12 +66,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } @@ -81,7 +83,11 @@ const ( ) var ( - moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) + randomSeed int64 = 99 + randomInt int64 = 1 + randomMetaProperty = baseProp.GenerateRandomMetaProperty(rand.New(rand.NewSource(randomSeed))) + randomBondMetaProperty = baseProperties.NewMetaProperty(baseIDs.NewStringID(""), baseData.NewNumberData(sdkTypes.NewInt(randomInt))) newMutables = baseQualified.NewMutables(baseLists.NewPropertyList()) asset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) @@ -250,15 +256,15 @@ func TestTransactionKeeperTransact(t *testing.T) { from: genesisAddress, toID: baseIDs.PrototypeIdentityID(), classificationID: baseIDs.PrototypeClassificationID(), - immutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewStringData("val1"))), + immutableProps: baseLists.NewPropertyList(randomMetaProperty), mutableProps: baseLists.NewPropertyList(), }, setup: func(t *testing.T) { - assetID := baseIDs.NewAssetID(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewStringData("val1"))))) + assetID := baseIDs.NewAssetID(baseIDs.PrototypeClassificationID(), baseQualified.NewImmutables(baseLists.NewPropertyList(randomMetaProperty))) assets := TransactionKeeper.mapper.NewCollection(sdkTypes.WrapSDKContext(Context)).Fetch(key.NewKey(assetID)) assets.Add(record.NewRecord( baseDocuments.NewOrder(baseIDs.PrototypeClassificationID(), - baseQualified.NewImmutables(baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewStringData("val1")))), + baseQualified.NewImmutables(baseLists.NewPropertyList(randomMetaProperty)), baseQualified.NewMutables(baseLists.NewPropertyList())))) authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() @@ -339,7 +345,7 @@ func TestTransactionKeeperTransact(t *testing.T) { toID: baseIDs.PrototypeIdentityID(), classificationID: baseIDs.PrototypeClassificationID(), immutableProps: baseLists.NewPropertyList(), - mutableProps: baseLists.NewPropertyList(baseProperties.NewMetaProperty(baseIDs.NewStringID("prop1"), baseData.NewNumberData(sdkTypes.NewInt(1)))), + mutableProps: baseLists.NewPropertyList(randomBondMetaProperty), }, setup: func(t *testing.T) { authorizeAuxiliaryKeeper.On("Help", mock.Anything, mock.Anything).Return(new(helpers.AuxiliaryResponse), nil).Once() diff --git a/x/assets/transactions/mutate/transaction_keeper_test.go b/x/assets/transactions/mutate/transaction_keeper_test.go index d78d5952e..ed6a6de20 100644 --- a/x/assets/transactions/mutate/transaction_keeper_test.go +++ b/x/assets/transactions/mutate/transaction_keeper_test.go @@ -59,12 +59,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } diff --git a/x/assets/transactions/renumerate/transaction_keeper_test.go b/x/assets/transactions/renumerate/transaction_keeper_test.go index a56bbc064..839f45b05 100644 --- a/x/assets/transactions/renumerate/transaction_keeper_test.go +++ b/x/assets/transactions/renumerate/transaction_keeper_test.go @@ -65,12 +65,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } @@ -84,11 +84,14 @@ const ( var ( moduleStoreKey = sdkTypes.NewKVStoreKey(constants.ModuleName) - SupplyNotRevealedProperty = baseMetaProp.NewMetaProperty(baseIDs.NewStringID("supply"), baseData.NewBooleanData(false)) - NegativeSupplyProperty = baseMetaProp.NewMetaProperty(constantProperties.SupplyProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(-1))) + randomInteger int64 = 100 + randomNegativeInteger int64 = -1 + + SupplyNotRevealedProperty = baseMetaProp.NewMesaProperty(constantProperties.SupplyProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomNegativeInteger))) + NegativeSupplyProperty = baseMetaProp.NewMetaProperty(constantProperties.SupplyProperty.GetID().GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomNegativeInteger))) propList = baseQualified.NewMutables(mutableMetaProperties).GetMutablePropertyList().Add( - baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(100))), + baseProperties.NewMesaProperty(constantProperties.SupplyProperty.GetKey(), baseData.NewNumberData(sdkTypes.NewInt(randomInteger))), ) newMutables = baseQualified.NewMutables(propList) testNewAsset = baseDocuments.NewAsset(baseIDs.NewClassificationID(immutables, newMutables), immutables, newMutables) @@ -264,7 +267,7 @@ func TestTransactionKeeperTransact(t *testing.T) { wantErr: errorConstants.MockError, }, { - name: "SuupplyNotRevealedError", + name: "SupplyNotRevealedError", args: args{ from: genesisAddress, fromID: baseIDs.PrototypeIdentityID(), diff --git a/x/assets/transactions/revoke/transaction_keeper_test.go b/x/assets/transactions/revoke/transaction_keeper_test.go index 5bea52de0..e52cd096a 100644 --- a/x/assets/transactions/revoke/transaction_keeper_test.go +++ b/x/assets/transactions/revoke/transaction_keeper_test.go @@ -63,12 +63,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } diff --git a/x/assets/transactions/send/transaction_keeper_test.go b/x/assets/transactions/send/transaction_keeper_test.go index f7a06e70b..418d8335d 100644 --- a/x/assets/transactions/send/transaction_keeper_test.go +++ b/x/assets/transactions/send/transaction_keeper_test.go @@ -64,12 +64,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } diff --git a/x/assets/transactions/unwrap/transaction_keeper_test.go b/x/assets/transactions/unwrap/transaction_keeper_test.go index f414ddc38..8fc6063b2 100644 --- a/x/assets/transactions/unwrap/transaction_keeper_test.go +++ b/x/assets/transactions/unwrap/transaction_keeper_test.go @@ -67,12 +67,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) } diff --git a/x/assets/transactions/wrap/transaction_keeper_test.go b/x/assets/transactions/wrap/transaction_keeper_test.go index 7299ff76f..05ce634ce 100644 --- a/x/assets/transactions/wrap/transaction_keeper_test.go +++ b/x/assets/transactions/wrap/transaction_keeper_test.go @@ -65,12 +65,12 @@ type MockAuxiliaryKeeper struct { var _ helpers.AuxiliaryKeeper = (*MockAuxiliaryKeeper)(nil) -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, request helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { - args := mockAuxiliaryKeeper.Called(context, request) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Help(context context.Context, auxiliaryRequest helpers.AuxiliaryRequest) (helpers.AuxiliaryResponse, error) { + args := mockAuxiliaryKeeper.Called(context, auxiliaryRequest) return args.Get(0).(helpers.AuxiliaryResponse), args.Error(1) } -func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(m2 helpers.Mapper, manager helpers.ParameterManager, i []interface{}) helpers.Keeper { - args := mockAuxiliaryKeeper.Called(m2, manager, i) +func (mockAuxiliaryKeeper *MockAuxiliaryKeeper) Initialize(mapper helpers.Mapper, parameterManager helpers.ParameterManager, i []interface{}) helpers.Keeper { + args := mockAuxiliaryKeeper.Called(mapper, parameterManager, i) return args.Get(0).(helpers.Keeper) }