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/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/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) { 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) { 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/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..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,10 +271,14 @@ 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, - }, { + }, + { "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/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 { 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) } }) }