Skip to content

Commit

Permalink
Merge pull request #160 from AssetMantle/0xankit/toDosTests
Browse files Browse the repository at this point in the history
0xankit/to dos tests
  • Loading branch information
deepanshutr authored Dec 13, 2022
2 parents b1b0ad7 + fc96647 commit 604a771
Show file tree
Hide file tree
Showing 132 changed files with 955 additions and 1,330 deletions.
10 changes: 6 additions & 4 deletions modules/assets/internal/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package block

import (
"fmt"
"reflect"
"testing"

Expand Down Expand Up @@ -109,7 +110,9 @@ func Test_block_End(t *testing.T) {
}

func Test_block_Initialize(t *testing.T) {
// testBlock := block{mapper.Prototype(), parameters.Prototype()}
testMapper := mapper.Prototype()
testParameter := parameters.Prototype()
testBlock := block{testMapper, testParameter}
type fields struct {
mapper helpers.Mapper
parameters helpers.Parameters
Expand All @@ -125,16 +128,15 @@ func Test_block_Initialize(t *testing.T) {
args args
want helpers.Block
}{
// TODO: Add test cases.
// {"+ve", fields{mapper.Prototype(), parameters.Prototype()}, args{mapper.Prototype(), parameters.Prototype(), []helpers.Auxiliary{}}, Prototype()},
{"+ve", fields{testMapper, testParameter}, args{testMapper, testParameter, []interface{}{}}, testBlock},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
block := block{
mapper: tt.fields.mapper,
parameters: tt.fields.parameters,
}
if got := block.Initialize(tt.args.mapper, tt.args.parameters, tt.args.in2...); !reflect.DeepEqual(got, tt.want) {
if got := block.Initialize(tt.args.mapper, tt.args.parameters, tt.args.in2...); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
t.Errorf("Initialize() = %v, want %v", got, tt.want)
}
})
Expand Down
1 change: 0 additions & 1 deletion modules/assets/internal/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (key) RegisterCodec(codec *codec.Codec) {
codecUtilities.RegisterModuleConcrete(codec, key{})
}
func (key key) IsPartial() bool {
// TODO test nil AssetID case
return len(key.AssetID.Bytes()) == 0
}
func (key key) Equals(compareKey helpers.Key) bool {
Expand Down
44 changes: 16 additions & 28 deletions modules/assets/internal/mapper/prototype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,28 @@
package mapper

import (
"github.com/AssetMantle/modules/schema/helpers"
"reflect"
"testing"

"github.com/stretchr/testify/require"

"github.com/AssetMantle/modules/modules/assets/internal/key"
"github.com/AssetMantle/modules/modules/assets/internal/mappable"
baseHelpers "github.com/AssetMantle/modules/schema/helpers/base"
)

// func TestPrototype(t *testing.T) {
// storeKey := sdkTypes.NewKVStoreKey("test")
// newMapper := baseHelpers.NewMapper(key.Prototype, mappable.Prototype).Initialize(storeKey)
//
// tests := []struct {
// name string
// want helpers.Mapper
// }{
// // TODO: Add test cases.
// {"Default Tests", newMapper},
// //{"dummy tests", baseHelpers.NewMapper(key.Prototype, mappable.Prototype)},
// //{"Dt1", Prototype()},
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// if got := Prototype().Initialize(storeKey); !reflect.DeepEqual(got, tt.want) {
// t.Errorf("Prototype() = %v, want %v", got, tt.want)
// }
// })
// }
// }

func TestPrototype(t *testing.T) {
// storeKey := sdkTypes.NewKVStoreKey("test")
require.Panics(t, func() {
require.Equal(t, Prototype(), baseHelpers.NewMapper(key.Prototype, mappable.Prototype))
})
tests := []struct {
name string
want helpers.Mapper
}{
// TODO: it should pass, but possibly due to a bug in the code, it fails
{"+ve", baseHelpers.NewMapper(key.Prototype, mappable.Prototype)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Prototype(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Prototype() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion modules/assets/internal/parameters/dummy/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Test_validator(t *testing.T) {
{"-ve with different type of Data", args{baseData.NewStringData("stringData")}, errorConstants.IncorrectFormat},
{"-ve InvalidParameter", args{baseTypes.NewParameter(baseIDs.NewStringID(""), baseData.NewStringData(""), validator)}, errorConstants.InvalidParameter},
{"-ve with -ve decData", args{baseTypes.NewParameter(baseIDs.NewStringID("ID"), baseData.NewDecData(sdkTypes.NewDec(-1)), validator)}, errorConstants.InvalidParameter},
{"+ve with +ve decData", args{baseTypes.NewParameter(baseIDs.NewStringID("dummy"), baseData.NewDecData(sdkTypes.NewDec(1)), validator)}, nil}, // TODO: Check whether input provided is right
{"+ve with +ve decData", args{baseTypes.NewParameter(baseIDs.NewStringID("dummy"), baseData.NewDecData(sdkTypes.NewDec(1)), validator)}, nil},
{"-ve nil", args{}, errorConstants.IncorrectFormat},
}
for _, tt := range tests {
Expand Down
11 changes: 5 additions & 6 deletions modules/assets/internal/parameters/prototype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package parameters

import (
"github.com/AssetMantle/modules/schema/helpers"
"reflect"
"testing"

Expand All @@ -13,17 +14,15 @@ import (

func TestPrototype(t *testing.T) {
tests := []struct {
name string
// want helpers.Parameters
want string
name string
want helpers.Parameters
wantError error
}{
// TODO: Update test case.
{"+ve", baseHelpers.NewParameters(dummy.Parameter).String(), nil},
{"+ve", baseHelpers.NewParameters(dummy.Parameter), nil},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Prototype(); tt.wantError != got.Validate() && !reflect.DeepEqual(got.String(), tt.want) {
if got := Prototype(); tt.wantError != got.Validate() && !reflect.DeepEqual(got.String(), tt.want.String()) {
t.Errorf("Prototype() = %v, want %v", got, tt.want)
}
})
Expand Down
9 changes: 8 additions & 1 deletion modules/assets/internal/queries/asset/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"github.com/AssetMantle/modules/modules/assets/internal/common"
baseData "github.com/AssetMantle/modules/schema/data/base"
"github.com/AssetMantle/modules/schema/helpers"
"github.com/AssetMantle/modules/schema/helpers/base"
"github.com/AssetMantle/modules/schema/helpers/constants"
"github.com/AssetMantle/modules/schema/ids"
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
baseLists "github.com/AssetMantle/modules/schema/lists/base"
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
baseQualified "github.com/AssetMantle/modules/schema/qualified/base"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
"reflect"
"testing"
Expand Down Expand Up @@ -139,6 +142,8 @@ func Test_queryRequest_Encode(t *testing.T) {
}

func Test_queryRequest_FromCLI(t *testing.T) {
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID})
viper.Set(constants.AssetID.GetName(), testAssetID.String())
type fields struct {
AssetID ids.AssetID
}
Expand All @@ -152,7 +157,9 @@ func Test_queryRequest_FromCLI(t *testing.T) {
args args
want helpers.QueryRequest
wantErr bool
}{}
}{
{"+ve", fields{testAssetID}, args{cliCommand, context.NewCLIContext()}, newQueryRequest(testAssetID), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
qu := queryRequest{
Expand Down
16 changes: 10 additions & 6 deletions modules/assets/internal/transactions/burn/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ package burn

import (
"encoding/json"
"fmt"
"github.com/AssetMantle/modules/schema/helpers"
"github.com/AssetMantle/modules/schema/helpers/base"
"github.com/AssetMantle/modules/schema/helpers/constants"
"github.com/AssetMantle/modules/utilities/transaction"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/spf13/viper"
"reflect"
"testing"
)
Expand Down Expand Up @@ -58,9 +62,10 @@ func Test_requestPrototype(t *testing.T) {
}

func Test_transactionRequest_FromCLI(t *testing.T) {
//cliCommand := baseHelpers.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID, constants.FromID})
//cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
//cliContext.WithInput(os.Stdin)
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID, constants.FromID})
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
viper.Set(constants.AssetID.GetName(), testAssetID.String())
viper.Set(constants.FromID.GetName(), fromID.String())
type fields struct {
BaseReq rest.BaseReq
FromID string
Expand All @@ -77,8 +82,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
want helpers.TransactionRequest
wantErr bool
}{
// TODO: Add test cases.
//{"+ve", fields{BaseReq: testBaseRequest, FromID: fromID.String(), AssetID: testAssetID.String()}, args{cliCommand, cliContext}, newTransactionRequest(testBaseRequest, fromID.String(), testAssetID.String()), false},
{"+ve", fields{BaseReq: testBaseRequest, FromID: fromID.String(), AssetID: testAssetID.String()}, args{cliCommand, cliContext}, newTransactionRequest(testBaseRequest, fromID.String(), testAssetID.String()), false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -92,7 +96,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
}
})
Expand Down
15 changes: 13 additions & 2 deletions modules/assets/internal/transactions/define/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ package define

import (
"encoding/json"
"fmt"
baseData "github.com/AssetMantle/modules/schema/data/base"
"github.com/AssetMantle/modules/schema/helpers"
"github.com/AssetMantle/modules/schema/helpers/base"
"github.com/AssetMantle/modules/schema/helpers/constants"
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
baseLists "github.com/AssetMantle/modules/schema/lists/base"
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
Expand All @@ -15,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/spf13/viper"
"reflect"
"testing"
)
Expand Down Expand Up @@ -73,6 +77,13 @@ func Test_requestPrototype(t *testing.T) {
}

func Test_transactionRequest_FromCLI(t *testing.T) {
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.FromID, constants.ImmutableMetaProperties, constants.ImmutableProperties, constants.MutableMetaProperties, constants.MutableProperties})
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
viper.Set(constants.ImmutableMetaProperties.GetName(), immutableMetaPropertiesString)
viper.Set(constants.ImmutableProperties.GetName(), immutablePropertiesString)
viper.Set(constants.MutableMetaProperties.GetName(), mutableMetaPropertiesString)
viper.Set(constants.MutableProperties.GetName(), mutablePropertiesString)
viper.Set(constants.FromID.GetName(), fromID.String())
type fields struct {
BaseReq rest.BaseReq
FromID string
Expand All @@ -92,7 +103,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
want helpers.TransactionRequest
wantErr bool
}{
// TODO: Add test cases.
{"+ve", fields{testBaseRequest, fromID.String(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -109,7 +120,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
}
})
Expand Down
19 changes: 17 additions & 2 deletions modules/assets/internal/transactions/deputize/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
baseData "github.com/AssetMantle/modules/schema/data/base"
"github.com/AssetMantle/modules/schema/helpers"
"github.com/AssetMantle/modules/schema/helpers/base"
"github.com/AssetMantle/modules/schema/helpers/constants"
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
baseLists "github.com/AssetMantle/modules/schema/lists/base"
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
Expand All @@ -16,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/spf13/viper"
"reflect"
"testing"
)
Expand Down Expand Up @@ -73,6 +76,18 @@ func Test_requestPrototype(t *testing.T) {
}

func Test_transactionRequest_FromCLI(t *testing.T) {
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.ToID, constants.FromID, constants.ClassificationID, constants.MaintainedProperties, constants.CanMintAsset, constants.CanBurnAsset, constants.CanRenumerateAsset, constants.CanAddMaintainer, constants.CanRemoveMaintainer, constants.CanMutateMaintainer})
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
viper.Set(constants.ToID.GetName(), fromID.String())
viper.Set(constants.FromID.GetName(), fromID.String())
viper.Set(constants.ClassificationID.GetName(), classificationID.String())
viper.Set(constants.MaintainedProperties.GetName(), mutableMetaPropertiesString)
viper.Set(constants.CanMintAsset.GetName(), true)
viper.Set(constants.CanBurnAsset.GetName(), true)
viper.Set(constants.CanRenumerateAsset.GetName(), true)
viper.Set(constants.CanAddMaintainer.GetName(), true)
viper.Set(constants.CanRemoveMaintainer.GetName(), true)
viper.Set(constants.CanMutateMaintainer.GetName(), true)
type fields struct {
BaseReq rest.BaseReq
FromID string
Expand All @@ -97,7 +112,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
want helpers.TransactionRequest
wantErr bool
}{
// TODO: Add test cases.
{"+ve", fields{}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), fromID.String(), classificationID.String(), mutableMetaPropertiesString, true, true, true, true, true, true}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -119,7 +134,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
}
})
Expand Down
17 changes: 15 additions & 2 deletions modules/assets/internal/transactions/mint/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ package mint

import (
"encoding/json"
"fmt"
baseData "github.com/AssetMantle/modules/schema/data/base"
"github.com/AssetMantle/modules/schema/helpers"
"github.com/AssetMantle/modules/schema/helpers/base"
"github.com/AssetMantle/modules/schema/helpers/constants"
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
baseLists "github.com/AssetMantle/modules/schema/lists/base"
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
Expand All @@ -15,6 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/spf13/viper"
"reflect"
"testing"
)
Expand Down Expand Up @@ -75,6 +79,15 @@ func Test_requestPrototype(t *testing.T) {
}

func Test_transactionRequest_FromCLI(t *testing.T) {
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID, constants.FromID, constants.ToID, constants.ClassificationID, constants.ImmutableMetaProperties, constants.ImmutableProperties, constants.MutableMetaProperties, constants.MutableProperties})
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
viper.Set(constants.FromID.GetName(), fromID.String())
viper.Set(constants.ToID.GetName(), fromID.String())
viper.Set(constants.ClassificationID.GetName(), classificationID.String())
viper.Set(constants.ImmutableMetaProperties.GetName(), immutableMetaPropertiesString)
viper.Set(constants.ImmutableProperties.GetName(), immutablePropertiesString)
viper.Set(constants.MutableMetaProperties.GetName(), mutableMetaPropertiesString)
viper.Set(constants.MutableProperties.GetName(), mutablePropertiesString)
type fields struct {
BaseReq rest.BaseReq
FromID string
Expand All @@ -96,7 +109,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
want helpers.TransactionRequest
wantErr bool
}{
// TODO: Add test cases.
{"+ve", fields{}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), fromID.String(), classificationID.String(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -115,7 +128,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
}
})
Expand Down
Loading

0 comments on commit 604a771

Please sign in to comment.