Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JekaMas committed Dec 17, 2021
1 parent 3406b7f commit f460dd2
Show file tree
Hide file tree
Showing 289 changed files with 2,359 additions and 2,168 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ test: test-unit
test-all: test-unit test-ledger-mock test-race test-cover

test-ledger-mock:
@go test -mod=readonly -shuffle=on `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger test_ledger_mock'
@go test -mod=readonly `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger test_ledger_mock'

test-ledger: test-ledger-mock
@go test -mod=readonly -v -shuffle=on `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger'
@go test -mod=readonly -v `go list github.com/cosmos/cosmos-sdk/crypto` -tags='cgo ledger'

test-unit:
@VERSION=$(VERSION) go test -mod=readonly -shuffle=on $(PACKAGES_NOSIMULATION) -tags='ledger test_ledger_mock'
@VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_NOSIMULATION) -tags='ledger test_ledger_mock'

test-race:
@VERSION=$(VERSION) go test -mod=readonly -race -shuffle=on $(PACKAGES_NOSIMULATION)
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)

.PHONY: test test-all test-ledger-mock test-ledger test-unit test-race

Expand Down
4 changes: 2 additions & 2 deletions modules/assets/internal/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func CreateTestInput(t *testing.T) sdkTypes.Context {
commitMultiStore.MountStoreWithDB(storeKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsStoreKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, sdkTypes.StoreTypeTransient, memDB)
Error := commitMultiStore.LoadLatestVersion()
require.Nil(t, Error)
err := commitMultiStore.LoadLatestVersion()
require.Nil(t, err)

context := sdkTypes.NewContext(commitMultiStore, abciTypes.Header{
ChainID: "test",
Expand Down
2 changes: 1 addition & 1 deletion modules/assets/internal/key/assetID_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Test_AssetID_Methods(t *testing.T) {
immutableProperties := base.NewProperties(base.NewProperty(base.NewID("ID1"), base.NewFact(base.NewStringData("ImmutableData"))))

testAssetID := NewAssetID(classificationID, immutableProperties).(assetID)

require.NotPanics(t, func() {
require.Equal(t, assetID{ClassificationID: classificationID, HashID: baseTraits.HasImmutables{Properties: immutableProperties}.GenerateHashID()}, testAssetID)
require.Equal(t, strings.Join([]string{classificationID.String(), baseTraits.HasImmutables{Properties: immutableProperties}.GenerateHashID().String()}, constants.FirstOrderCompositeIDSeparator), testAssetID.String())
Expand All @@ -35,5 +36,4 @@ func Test_AssetID_Methods(t *testing.T) {
require.Equal(t, assetID{ClassificationID: base.NewID(""), HashID: base.NewID("")}, FromID(base.NewID("")))
require.Equal(t, testAssetID, readAssetID(testAssetID.String()))
})

}
4 changes: 2 additions & 2 deletions modules/assets/internal/key/utilities_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package key

import (
"testing"

"github.com/persistenceOne/persistenceSDK/constants"
"github.com/persistenceOne/persistenceSDK/schema/types/base"
"github.com/stretchr/testify/require"
"testing"
)

func TestFromID(t *testing.T) {
Expand All @@ -31,5 +32,4 @@ func TestReadClassificationID(t *testing.T) {
assetID := NewAssetID(classificationID, immutableProperties)

require.Equal(t, assetIDFromInterface(assetID).ClassificationID, ReadClassificationID(assetID))

}
2 changes: 1 addition & 1 deletion modules/assets/internal/mappable/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Test_Asset_Methods(t *testing.T) {
require.Equal(t, classificationID, testAsset.GetClassificationID())
require.Equal(t, immutableProperties, testAsset.GetImmutableProperties())
require.Equal(t, mutableProperties, testAsset.GetMutableProperties())

data, _ := base.ReadHeightData("-1")
require.Equal(t, testAsset.GetBurn(), base.NewProperty(base.NewID(properties.Burn), base.NewFact(data)))
require.Equal(t, base.NewProperty(base.NewID(properties.Burn), base.NewFact(base.NewStringData("BurnImmutableData"))), asset{ID: assetID, HasImmutables: baseTraits.HasImmutables{Properties: base.NewProperties(base.NewProperty(base.NewID(properties.Burn), base.NewFact(base.NewStringData("BurnImmutableData"))))}, HasMutables: baseTraits.HasMutables{Properties: mutableProperties}}.GetBurn())
Expand All @@ -36,5 +37,4 @@ func Test_Asset_Methods(t *testing.T) {
require.Equal(t, base.NewProperty(base.NewID(properties.Lock), base.NewFact(base.NewStringData("LockImmutableData"))), asset{ID: assetID, HasImmutables: baseTraits.HasImmutables{Properties: base.NewProperties(base.NewProperty(base.NewID(properties.Lock), base.NewFact(base.NewStringData("LockImmutableData"))))}, HasMutables: baseTraits.HasMutables{Properties: mutableProperties}}.GetLock())
require.Equal(t, base.NewProperty(base.NewID(properties.Lock), base.NewFact(base.NewStringData("LockMutableData"))), asset{ID: assetID, HasImmutables: baseTraits.HasImmutables{Properties: immutableProperties}, HasMutables: baseTraits.HasMutables{Properties: base.NewProperties(base.NewProperty(base.NewID(properties.Lock), base.NewFact(base.NewStringData("LockMutableData"))))}}.GetLock())
require.Equal(t, assetID, testAsset.GetKey())

}
8 changes: 4 additions & 4 deletions modules/assets/internal/parameters/dummy/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
func validator(i interface{}) error {
switch value := i.(type) {
case types.Parameter:
data, Error := value.GetData().AsDec()
if Error != nil || value.GetID().Compare(ID) != 0 || data.IsNegative() {
data, err := value.GetData().AsDec()
if err != nil || value.GetID().Compare(ID) != 0 || data.IsNegative() {
return errors.InvalidParameter
}

return nil
case types.Data:
data, Error := value.AsDec()
if Error != nil || data.IsNegative() {
data, err := value.AsDec()
if err != nil || data.IsNegative() {
return errors.InvalidParameter
}

Expand Down
21 changes: 14 additions & 7 deletions modules/assets/internal/queries/asset/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/persistenceOne/persistenceSDK/schema"
"github.com/persistenceOne/persistenceSDK/schema/helpers"
baseHelpers "github.com/persistenceOne/persistenceSDK/schema/helpers/base"
"github.com/persistenceOne/persistenceSDK/schema/types"
"github.com/persistenceOne/persistenceSDK/schema/types/base"
"github.com/stretchr/testify/require"
abciTypes "github.com/tendermint/tendermint/abci/types"
Expand All @@ -28,12 +29,14 @@ import (

func CreateTestInput2(t *testing.T) (sdkTypes.Context, helpers.Keeper) {
var Codec = codec.New()

schema.RegisterCodec(Codec)
sdkTypes.RegisterCodec(Codec)
codec.RegisterCrypto(Codec)
codec.RegisterEvidences(Codec)
vesting.RegisterCodec(Codec)
Codec.Seal()

storeKey := sdkTypes.NewKVStoreKey("test")
paramsStoreKey := sdkTypes.NewKVStoreKey("testParams")
paramsTransientStoreKeys := sdkTypes.NewTransientStoreKey("testParamsTransient")
Expand All @@ -43,8 +46,9 @@ func CreateTestInput2(t *testing.T) (sdkTypes.Context, helpers.Keeper) {
commitMultiStore.MountStoreWithDB(storeKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsStoreKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, sdkTypes.StoreTypeTransient, memDB)
Error := commitMultiStore.LoadLatestVersion()
require.Nil(t, Error)

err := commitMultiStore.LoadLatestVersion()
require.Nil(t, err)

context := sdkTypes.NewContext(commitMultiStore, abciTypes.Header{
ChainID: "test",
Expand All @@ -66,15 +70,18 @@ func CreateTestInput2(t *testing.T) (sdkTypes.Context, helpers.Keeper) {
func Test_Query_Keeper_Asset(t *testing.T) {

context, keepers := CreateTestInput2(t)
immutableProperties, Error := base.ReadProperties("defaultImmutable1:S|defaultImmutable1")
require.Equal(t, nil, Error)
mutableProperties, Error2 := base.ReadProperties("burn:S|100")
require.Equal(t, nil, Error2)

immutableProperties, err := base.ReadProperties("defaultImmutable1:S|defaultImmutable1")
require.Equal(t, nil, err)

var mutableProperties types.Properties
mutableProperties, err = base.ReadProperties("burn:S|100")
require.Equal(t, nil, err)

classificationID := base.NewID("ClassificationID")
assetID := key.NewAssetID(classificationID, immutableProperties)
keepers.(queryKeeper).mapper.NewCollection(context).Add(mappable.NewAsset(assetID, immutableProperties, mutableProperties))

testQueryRequest := newQueryRequest(assetID)
require.Equal(t, queryResponse{Success: true, Error: nil, List: keepers.(queryKeeper).mapper.NewCollection(context).Fetch(key.FromID(assetID)).GetList()}, keepers.(queryKeeper).Enquire(context, testQueryRequest))

}
8 changes: 4 additions & 4 deletions modules/assets/internal/queries/asset/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ var _ helpers.QueryRequest = (*queryRequest)(nil)
// @Failure default {object} queryResponse "Message for an unexpected error."
// @Router /assets/assets/{assetID} [get]
func (queryRequest queryRequest) Validate() error {
_, Error := govalidator.ValidateStruct(queryRequest)
return Error
_, err := govalidator.ValidateStruct(queryRequest)
return err
}
func (queryRequest queryRequest) FromCLI(cliCommand helpers.CLICommand, _ context.CLIContext) helpers.QueryRequest {
return newQueryRequest(base.NewID(cliCommand.ReadString(flags.AssetID)))
Expand All @@ -46,8 +46,8 @@ func (queryRequest queryRequest) Encode() ([]byte, error) {
}

func (queryRequest queryRequest) Decode(bytes []byte) (helpers.QueryRequest, error) {
if Error := common.Codec.UnmarshalJSON(bytes, &queryRequest); Error != nil {
return nil, Error
if err := common.Codec.UnmarshalJSON(bytes, &queryRequest); err != nil {
return nil, err
}

return queryRequest, nil
Expand Down
20 changes: 14 additions & 6 deletions modules/assets/internal/queries/asset/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import (
func Test_Asset_Request(t *testing.T) {

var Codec = codec.New()

schema.RegisterCodec(Codec)
sdkTypes.RegisterCodec(Codec)
codec.RegisterCrypto(Codec)
codec.RegisterEvidences(Codec)
vesting.RegisterCodec(Codec)
Codec.Seal()

classificationID := base.NewID("classificationID")
immutableProperties := base.NewProperties(base.NewProperty(base.NewID("ID1"), base.NewFact(base.NewStringData("ImmutableData"))))

Expand All @@ -47,16 +49,22 @@ func Test_Asset_Request(t *testing.T) {
vars["assets"] = "randomString"
require.Equal(t, newQueryRequest(base.NewID("randomString")), queryRequest{}.FromMap(vars))

encodedRequest, Error := testQueryRequest.Encode()
encodedResult, _ := common.Codec.MarshalJSON(testQueryRequest)
encodedRequest, err := testQueryRequest.Encode()
require.Nil(t, err)

var encodedResult []byte
encodedResult, err = common.Codec.MarshalJSON(testQueryRequest)
require.Nil(t, err)
require.Equal(t, encodedResult, encodedRequest)
require.Nil(t, Error)

decodedRequest, Error := queryRequest{}.Decode(encodedRequest)
var decodedRequest helpers.QueryRequest
decodedRequest, err = queryRequest{}.Decode(encodedRequest)
require.Equal(t, nil, err)
require.Equal(t, testQueryRequest, decodedRequest)
require.Equal(t, nil, Error)

randomDecode, _ := queryRequest{}.Decode(base.NewID("").Bytes())
var randomDecode helpers.QueryRequest
randomDecode, err = queryRequest{}.Decode(base.NewID("").Bytes())
require.Equal(t, nil, err)
require.Equal(t, nil, randomDecode)
require.Equal(t, testQueryRequest, queryRequestFromInterface(testQueryRequest))
require.Equal(t, queryRequest{}, queryRequestFromInterface(nil))
Expand Down
4 changes: 2 additions & 2 deletions modules/assets/internal/queries/asset/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (queryResponse queryResponse) Encode() ([]byte, error) {
return common.Codec.MarshalJSON(queryResponse)
}
func (queryResponse queryResponse) Decode(bytes []byte) (helpers.QueryResponse, error) {
if Error := common.Codec.UnmarshalJSON(bytes, &queryResponse); Error != nil {
return nil, Error
if err := common.Codec.UnmarshalJSON(bytes, &queryResponse); err != nil {
return nil, err
}

return queryResponse, nil
Expand Down
9 changes: 6 additions & 3 deletions modules/assets/internal/queries/asset/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package asset

import (
"testing"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdkTypes "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -19,11 +21,11 @@ import (
abciTypes "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tendermintDB "github.com/tendermint/tm-db"
"testing"
)

func CreateTestInput(t *testing.T) sdkTypes.Context {
var Codec = codec.New()

schema.RegisterCodec(Codec)
sdkTypes.RegisterCodec(Codec)
codec.RegisterCrypto(Codec)
Expand All @@ -40,8 +42,9 @@ func CreateTestInput(t *testing.T) sdkTypes.Context {
commitMultiStore.MountStoreWithDB(storeKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsStoreKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, sdkTypes.StoreTypeTransient, memDB)
Error := commitMultiStore.LoadLatestVersion()
require.Nil(t, Error)

err := commitMultiStore.LoadLatestVersion()
require.Nil(t, err)

context := sdkTypes.NewContext(commitMultiStore, abciTypes.Header{
ChainID: "test",
Expand Down
6 changes: 3 additions & 3 deletions modules/assets/internal/simulator/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func (simulator) ParamChangeList(_ *rand.Rand) []simulation.ParamChange {
simulation.NewSimParamChange(module.Name,
dummy.ID.String(),
func(r *rand.Rand) string {
bytes, Error := common.Codec.MarshalJSON(dummy.Parameter.Mutate(base.NewDecData(sdk.NewDecWithPrec(int64(r.Intn(99)), 2))).GetData())
if Error != nil {
panic(Error)
bytes, err := common.Codec.MarshalJSON(dummy.Parameter.Mutate(base.NewDecData(sdk.NewDecWithPrec(int64(r.Intn(99)), 2))).GetData())
if err != nil {
panic(err)
}
return string(bytes)
}),
Expand Down
12 changes: 6 additions & 6 deletions modules/assets/internal/transactions/burn/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ func (transactionKeeper transactionKeeper) Transact(context sdkTypes.Context, ms
return newTransactionResponse(errors.EntityNotFound)
}

metaProperties, Error := supplement.GetMetaPropertiesFromResponse(transactionKeeper.supplementAuxiliary.GetKeeper().Help(context, supplement.NewAuxiliaryRequest(asset.(mappables.InterNFT).GetBurn())))
if Error != nil {
return newTransactionResponse(Error)
metaProperties, err := supplement.GetMetaPropertiesFromResponse(transactionKeeper.supplementAuxiliary.GetKeeper().Help(context, supplement.NewAuxiliaryRequest(asset.(mappables.InterNFT).GetBurn())))
if err != nil {
return newTransactionResponse(err)
}

burnHeightMetaFact := metaProperties.Get(base.NewID(properties.Burn))
if burnHeightMetaFact == nil {
return newTransactionResponse(errors.EntityNotFound)
}

burnHeight, Error := burnHeightMetaFact.GetMetaFact().GetData().AsHeight()
if Error != nil {
return newTransactionResponse(Error)
burnHeight, err := burnHeightMetaFact.GetMetaFact().GetData().AsHeight()
if err != nil {
return newTransactionResponse(err)
}

if burnHeight.Compare(base.NewHeight(context.BlockHeight())) > 0 {
Expand Down
16 changes: 8 additions & 8 deletions modules/assets/internal/transactions/burn/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func CreateTestInput(t *testing.T) (sdkTypes.Context, TestKeepers) {
commitMultiStore.MountStoreWithDB(storeKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsStoreKey, sdkTypes.StoreTypeIAVL, memDB)
commitMultiStore.MountStoreWithDB(paramsTransientStoreKeys, sdkTypes.StoreTypeTransient, memDB)
Error := commitMultiStore.LoadLatestVersion()
require.Nil(t, Error)
err := commitMultiStore.LoadLatestVersion()
require.Nil(t, err)

context := sdkTypes.NewContext(commitMultiStore, abciTypes.Header{
ChainID: "test",
Expand All @@ -85,12 +85,12 @@ func Test_transactionKeeper_Transact(t *testing.T) {

ctx, keepers := CreateTestInput(t)
ctx = ctx.WithBlockHeight(2)
immutableProperties, Error := base.ReadProperties("defaultImmutable1:S|defaultImmutable1")
require.Equal(t, nil, Error)
mutableProperties, Error := base.ReadProperties("burn:H|100")
require.Equal(t, nil, Error)
supplementError, Error := base.ReadMetaProperties("supplementError:S|mockError")
require.Equal(t, nil, Error)
immutableProperties, err := base.ReadProperties("defaultImmutable1:S|defaultImmutable1")
require.Equal(t, nil, err)
mutableProperties, err := base.ReadProperties("burn:H|100")
require.Equal(t, nil, err)
supplementError, err := base.ReadMetaProperties("supplementError:S|mockError")
require.Equal(t, nil, err)
defaultAddr := sdkTypes.AccAddress("addr")
verifyMockErrorAddress := sdkTypes.AccAddress("verifyError")
defaultIdentityID := base.NewID("fromIdentityID")
Expand Down
7 changes: 4 additions & 3 deletions modules/assets/internal/transactions/burn/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
package burn

import (
"testing"

sdkTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/persistenceOne/persistenceSDK/modules/assets/internal/module"
"github.com/persistenceOne/persistenceSDK/schema/types/base"
"github.com/persistenceOne/persistenceSDK/utilities/transaction"
"github.com/stretchr/testify/require"
"testing"
)

func Test_Burn_Message(t *testing.T) {
Expand All @@ -20,8 +21,8 @@ func Test_Burn_Message(t *testing.T) {
testFromID := base.NewID("fromID")

fromAddress := "cosmos1pkkayn066msg6kn33wnl5srhdt3tnu2vzasz9c"
fromAccAddress, Error := sdkTypes.AccAddressFromBech32(fromAddress)
require.Nil(t, Error)
fromAccAddress, err := sdkTypes.AccAddressFromBech32(fromAddress)
require.Nil(t, err)

testMessage := newMessage(fromAccAddress, testFromID, testAssetID)
require.Equal(t, message{From: fromAccAddress, FromID: testFromID, AssetID: testAssetID}, testMessage)
Expand Down
14 changes: 7 additions & 7 deletions modules/assets/internal/transactions/burn/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ var _ helpers.TransactionRequest = (*transactionRequest)(nil)
// @Failure default {object} transactionResponse "Message for an unexpected error in the transaction."
// @Router /assets/burn [post]
func (transactionRequest transactionRequest) Validate() error {
_, Error := govalidator.ValidateStruct(transactionRequest)
return Error
_, err := govalidator.ValidateStruct(transactionRequest)
return err
}
func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLICommand, cliContext context.CLIContext) (helpers.TransactionRequest, error) {
return newTransactionRequest(
Expand All @@ -50,8 +50,8 @@ func (transactionRequest transactionRequest) FromCLI(cliCommand helpers.CLIComma
), nil
}
func (transactionRequest transactionRequest) FromJSON(rawMessage json.RawMessage) (helpers.TransactionRequest, error) {
if Error := json.Unmarshal(rawMessage, &transactionRequest); Error != nil {
return nil, Error
if err := json.Unmarshal(rawMessage, &transactionRequest); err != nil {
return nil, err
}

return transactionRequest, nil
Expand All @@ -60,9 +60,9 @@ func (transactionRequest transactionRequest) GetBaseReq() rest.BaseReq {
return transactionRequest.BaseReq
}
func (transactionRequest transactionRequest) MakeMsg() (sdkTypes.Msg, error) {
from, Error := sdkTypes.AccAddressFromBech32(transactionRequest.GetBaseReq().From)
if Error != nil {
return nil, Error
from, err := sdkTypes.AccAddressFromBech32(transactionRequest.GetBaseReq().From)
if err != nil {
return nil, err
}

return newMessage(
Expand Down
Loading

0 comments on commit f460dd2

Please sign in to comment.