Skip to content

Commit 604a771

Browse files
authored
Merge pull request #160 from AssetMantle/0xankit/toDosTests
0xankit/to dos tests
2 parents b1b0ad7 + fc96647 commit 604a771

File tree

132 files changed

+955
-1330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+955
-1330
lines changed

modules/assets/internal/block/block_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package block
55

66
import (
7+
"fmt"
78
"reflect"
89
"testing"
910

@@ -109,7 +110,9 @@ func Test_block_End(t *testing.T) {
109110
}
110111

111112
func Test_block_Initialize(t *testing.T) {
112-
// testBlock := block{mapper.Prototype(), parameters.Prototype()}
113+
testMapper := mapper.Prototype()
114+
testParameter := parameters.Prototype()
115+
testBlock := block{testMapper, testParameter}
113116
type fields struct {
114117
mapper helpers.Mapper
115118
parameters helpers.Parameters
@@ -125,16 +128,15 @@ func Test_block_Initialize(t *testing.T) {
125128
args args
126129
want helpers.Block
127130
}{
128-
// TODO: Add test cases.
129-
// {"+ve", fields{mapper.Prototype(), parameters.Prototype()}, args{mapper.Prototype(), parameters.Prototype(), []helpers.Auxiliary{}}, Prototype()},
131+
{"+ve", fields{testMapper, testParameter}, args{testMapper, testParameter, []interface{}{}}, testBlock},
130132
}
131133
for _, tt := range tests {
132134
t.Run(tt.name, func(t *testing.T) {
133135
block := block{
134136
mapper: tt.fields.mapper,
135137
parameters: tt.fields.parameters,
136138
}
137-
if got := block.Initialize(tt.args.mapper, tt.args.parameters, tt.args.in2...); !reflect.DeepEqual(got, tt.want) {
139+
if got := block.Initialize(tt.args.mapper, tt.args.parameters, tt.args.in2...); !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
138140
t.Errorf("Initialize() = %v, want %v", got, tt.want)
139141
}
140142
})

modules/assets/internal/key/key.go

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func (key) RegisterCodec(codec *codec.Codec) {
2626
codecUtilities.RegisterModuleConcrete(codec, key{})
2727
}
2828
func (key key) IsPartial() bool {
29-
// TODO test nil AssetID case
3029
return len(key.AssetID.Bytes()) == 0
3130
}
3231
func (key key) Equals(compareKey helpers.Key) bool {

modules/assets/internal/mapper/prototype_test.go

+16-28
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,28 @@
44
package mapper
55

66
import (
7+
"github.com/AssetMantle/modules/schema/helpers"
8+
"reflect"
79
"testing"
810

9-
"github.com/stretchr/testify/require"
10-
1111
"github.com/AssetMantle/modules/modules/assets/internal/key"
1212
"github.com/AssetMantle/modules/modules/assets/internal/mappable"
1313
baseHelpers "github.com/AssetMantle/modules/schema/helpers/base"
1414
)
1515

16-
// func TestPrototype(t *testing.T) {
17-
// storeKey := sdkTypes.NewKVStoreKey("test")
18-
// newMapper := baseHelpers.NewMapper(key.Prototype, mappable.Prototype).Initialize(storeKey)
19-
//
20-
// tests := []struct {
21-
// name string
22-
// want helpers.Mapper
23-
// }{
24-
// // TODO: Add test cases.
25-
// {"Default Tests", newMapper},
26-
// //{"dummy tests", baseHelpers.NewMapper(key.Prototype, mappable.Prototype)},
27-
// //{"Dt1", Prototype()},
28-
// }
29-
// for _, tt := range tests {
30-
// t.Run(tt.name, func(t *testing.T) {
31-
// if got := Prototype().Initialize(storeKey); !reflect.DeepEqual(got, tt.want) {
32-
// t.Errorf("Prototype() = %v, want %v", got, tt.want)
33-
// }
34-
// })
35-
// }
36-
// }
37-
3816
func TestPrototype(t *testing.T) {
39-
// storeKey := sdkTypes.NewKVStoreKey("test")
40-
require.Panics(t, func() {
41-
require.Equal(t, Prototype(), baseHelpers.NewMapper(key.Prototype, mappable.Prototype))
42-
})
17+
tests := []struct {
18+
name string
19+
want helpers.Mapper
20+
}{
21+
// TODO: it should pass, but possibly due to a bug in the code, it fails
22+
{"+ve", baseHelpers.NewMapper(key.Prototype, mappable.Prototype)},
23+
}
24+
for _, tt := range tests {
25+
t.Run(tt.name, func(t *testing.T) {
26+
if got := Prototype(); !reflect.DeepEqual(got, tt.want) {
27+
t.Errorf("Prototype() = %v, want %v", got, tt.want)
28+
}
29+
})
30+
}
4331
}

modules/assets/internal/parameters/dummy/validator_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Test_validator(t *testing.T) {
3232
{"-ve with different type of Data", args{baseData.NewStringData("stringData")}, errorConstants.IncorrectFormat},
3333
{"-ve InvalidParameter", args{baseTypes.NewParameter(baseIDs.NewStringID(""), baseData.NewStringData(""), validator)}, errorConstants.InvalidParameter},
3434
{"-ve with -ve decData", args{baseTypes.NewParameter(baseIDs.NewStringID("ID"), baseData.NewDecData(sdkTypes.NewDec(-1)), validator)}, errorConstants.InvalidParameter},
35-
{"+ve with +ve decData", args{baseTypes.NewParameter(baseIDs.NewStringID("dummy"), baseData.NewDecData(sdkTypes.NewDec(1)), validator)}, nil}, // TODO: Check whether input provided is right
35+
{"+ve with +ve decData", args{baseTypes.NewParameter(baseIDs.NewStringID("dummy"), baseData.NewDecData(sdkTypes.NewDec(1)), validator)}, nil},
3636
{"-ve nil", args{}, errorConstants.IncorrectFormat},
3737
}
3838
for _, tt := range tests {

modules/assets/internal/parameters/prototype_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package parameters
55

66
import (
7+
"github.com/AssetMantle/modules/schema/helpers"
78
"reflect"
89
"testing"
910

@@ -13,17 +14,15 @@ import (
1314

1415
func TestPrototype(t *testing.T) {
1516
tests := []struct {
16-
name string
17-
// want helpers.Parameters
18-
want string
17+
name string
18+
want helpers.Parameters
1919
wantError error
2020
}{
21-
// TODO: Update test case.
22-
{"+ve", baseHelpers.NewParameters(dummy.Parameter).String(), nil},
21+
{"+ve", baseHelpers.NewParameters(dummy.Parameter), nil},
2322
}
2423
for _, tt := range tests {
2524
t.Run(tt.name, func(t *testing.T) {
26-
if got := Prototype(); tt.wantError != got.Validate() && !reflect.DeepEqual(got.String(), tt.want) {
25+
if got := Prototype(); tt.wantError != got.Validate() && !reflect.DeepEqual(got.String(), tt.want.String()) {
2726
t.Errorf("Prototype() = %v, want %v", got, tt.want)
2827
}
2928
})

modules/assets/internal/queries/asset/request_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import (
77
"github.com/AssetMantle/modules/modules/assets/internal/common"
88
baseData "github.com/AssetMantle/modules/schema/data/base"
99
"github.com/AssetMantle/modules/schema/helpers"
10+
"github.com/AssetMantle/modules/schema/helpers/base"
11+
"github.com/AssetMantle/modules/schema/helpers/constants"
1012
"github.com/AssetMantle/modules/schema/ids"
1113
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
1214
baseLists "github.com/AssetMantle/modules/schema/lists/base"
1315
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
1416
baseQualified "github.com/AssetMantle/modules/schema/qualified/base"
1517
"github.com/cosmos/cosmos-sdk/client/context"
18+
"github.com/spf13/viper"
1619
"github.com/stretchr/testify/require"
1720
"reflect"
1821
"testing"
@@ -139,6 +142,8 @@ func Test_queryRequest_Encode(t *testing.T) {
139142
}
140143

141144
func Test_queryRequest_FromCLI(t *testing.T) {
145+
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID})
146+
viper.Set(constants.AssetID.GetName(), testAssetID.String())
142147
type fields struct {
143148
AssetID ids.AssetID
144149
}
@@ -152,7 +157,9 @@ func Test_queryRequest_FromCLI(t *testing.T) {
152157
args args
153158
want helpers.QueryRequest
154159
wantErr bool
155-
}{}
160+
}{
161+
{"+ve", fields{testAssetID}, args{cliCommand, context.NewCLIContext()}, newQueryRequest(testAssetID), false},
162+
}
156163
for _, tt := range tests {
157164
t.Run(tt.name, func(t *testing.T) {
158165
qu := queryRequest{

modules/assets/internal/transactions/burn/request_test.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ package burn
55

66
import (
77
"encoding/json"
8+
"fmt"
89
"github.com/AssetMantle/modules/schema/helpers"
10+
"github.com/AssetMantle/modules/schema/helpers/base"
11+
"github.com/AssetMantle/modules/schema/helpers/constants"
912
"github.com/AssetMantle/modules/utilities/transaction"
1013
"github.com/cosmos/cosmos-sdk/client/context"
1114
"github.com/cosmos/cosmos-sdk/codec"
1215
"github.com/cosmos/cosmos-sdk/types"
1316
"github.com/cosmos/cosmos-sdk/types/rest"
17+
"github.com/spf13/viper"
1418
"reflect"
1519
"testing"
1620
)
@@ -58,9 +62,10 @@ func Test_requestPrototype(t *testing.T) {
5862
}
5963

6064
func Test_transactionRequest_FromCLI(t *testing.T) {
61-
//cliCommand := baseHelpers.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID, constants.FromID})
62-
//cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
63-
//cliContext.WithInput(os.Stdin)
65+
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID, constants.FromID})
66+
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
67+
viper.Set(constants.AssetID.GetName(), testAssetID.String())
68+
viper.Set(constants.FromID.GetName(), fromID.String())
6469
type fields struct {
6570
BaseReq rest.BaseReq
6671
FromID string
@@ -77,8 +82,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
7782
want helpers.TransactionRequest
7883
wantErr bool
7984
}{
80-
// TODO: Add test cases.
81-
//{"+ve", fields{BaseReq: testBaseRequest, FromID: fromID.String(), AssetID: testAssetID.String()}, args{cliCommand, cliContext}, newTransactionRequest(testBaseRequest, fromID.String(), testAssetID.String()), false},
85+
{"+ve", fields{BaseReq: testBaseRequest, FromID: fromID.String(), AssetID: testAssetID.String()}, args{cliCommand, cliContext}, newTransactionRequest(testBaseRequest, fromID.String(), testAssetID.String()), false},
8286
}
8387
for _, tt := range tests {
8488
t.Run(tt.name, func(t *testing.T) {
@@ -92,7 +96,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
9296
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
9397
return
9498
}
95-
if !reflect.DeepEqual(got, tt.want) {
99+
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
96100
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
97101
}
98102
})

modules/assets/internal/transactions/define/request_test.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ package define
55

66
import (
77
"encoding/json"
8+
"fmt"
89
baseData "github.com/AssetMantle/modules/schema/data/base"
910
"github.com/AssetMantle/modules/schema/helpers"
11+
"github.com/AssetMantle/modules/schema/helpers/base"
12+
"github.com/AssetMantle/modules/schema/helpers/constants"
1013
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
1114
baseLists "github.com/AssetMantle/modules/schema/lists/base"
1215
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
@@ -15,6 +18,7 @@ import (
1518
"github.com/cosmos/cosmos-sdk/codec"
1619
"github.com/cosmos/cosmos-sdk/types"
1720
"github.com/cosmos/cosmos-sdk/types/rest"
21+
"github.com/spf13/viper"
1822
"reflect"
1923
"testing"
2024
)
@@ -73,6 +77,13 @@ func Test_requestPrototype(t *testing.T) {
7377
}
7478

7579
func Test_transactionRequest_FromCLI(t *testing.T) {
80+
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.FromID, constants.ImmutableMetaProperties, constants.ImmutableProperties, constants.MutableMetaProperties, constants.MutableProperties})
81+
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
82+
viper.Set(constants.ImmutableMetaProperties.GetName(), immutableMetaPropertiesString)
83+
viper.Set(constants.ImmutableProperties.GetName(), immutablePropertiesString)
84+
viper.Set(constants.MutableMetaProperties.GetName(), mutableMetaPropertiesString)
85+
viper.Set(constants.MutableProperties.GetName(), mutablePropertiesString)
86+
viper.Set(constants.FromID.GetName(), fromID.String())
7687
type fields struct {
7788
BaseReq rest.BaseReq
7889
FromID string
@@ -92,7 +103,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
92103
want helpers.TransactionRequest
93104
wantErr bool
94105
}{
95-
// TODO: Add test cases.
106+
{"+ve", fields{testBaseRequest, fromID.String(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, false},
96107
}
97108
for _, tt := range tests {
98109
t.Run(tt.name, func(t *testing.T) {
@@ -109,7 +120,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
109120
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
110121
return
111122
}
112-
if !reflect.DeepEqual(got, tt.want) {
123+
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
113124
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
114125
}
115126
})

modules/assets/internal/transactions/deputize/request_test.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"fmt"
99
baseData "github.com/AssetMantle/modules/schema/data/base"
1010
"github.com/AssetMantle/modules/schema/helpers"
11+
"github.com/AssetMantle/modules/schema/helpers/base"
12+
"github.com/AssetMantle/modules/schema/helpers/constants"
1113
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
1214
baseLists "github.com/AssetMantle/modules/schema/lists/base"
1315
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
@@ -16,6 +18,7 @@ import (
1618
"github.com/cosmos/cosmos-sdk/codec"
1719
"github.com/cosmos/cosmos-sdk/types"
1820
"github.com/cosmos/cosmos-sdk/types/rest"
21+
"github.com/spf13/viper"
1922
"reflect"
2023
"testing"
2124
)
@@ -73,6 +76,18 @@ func Test_requestPrototype(t *testing.T) {
7376
}
7477

7578
func Test_transactionRequest_FromCLI(t *testing.T) {
79+
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})
80+
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
81+
viper.Set(constants.ToID.GetName(), fromID.String())
82+
viper.Set(constants.FromID.GetName(), fromID.String())
83+
viper.Set(constants.ClassificationID.GetName(), classificationID.String())
84+
viper.Set(constants.MaintainedProperties.GetName(), mutableMetaPropertiesString)
85+
viper.Set(constants.CanMintAsset.GetName(), true)
86+
viper.Set(constants.CanBurnAsset.GetName(), true)
87+
viper.Set(constants.CanRenumerateAsset.GetName(), true)
88+
viper.Set(constants.CanAddMaintainer.GetName(), true)
89+
viper.Set(constants.CanRemoveMaintainer.GetName(), true)
90+
viper.Set(constants.CanMutateMaintainer.GetName(), true)
7691
type fields struct {
7792
BaseReq rest.BaseReq
7893
FromID string
@@ -97,7 +112,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
97112
want helpers.TransactionRequest
98113
wantErr bool
99114
}{
100-
// TODO: Add test cases.
115+
{"+ve", fields{}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), fromID.String(), classificationID.String(), mutableMetaPropertiesString, true, true, true, true, true, true}, false},
101116
}
102117
for _, tt := range tests {
103118
t.Run(tt.name, func(t *testing.T) {
@@ -119,7 +134,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
119134
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
120135
return
121136
}
122-
if !reflect.DeepEqual(got, tt.want) {
137+
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
123138
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
124139
}
125140
})

modules/assets/internal/transactions/mint/request_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ package mint
55

66
import (
77
"encoding/json"
8+
"fmt"
89
baseData "github.com/AssetMantle/modules/schema/data/base"
910
"github.com/AssetMantle/modules/schema/helpers"
11+
"github.com/AssetMantle/modules/schema/helpers/base"
12+
"github.com/AssetMantle/modules/schema/helpers/constants"
1013
baseIDs "github.com/AssetMantle/modules/schema/ids/base"
1114
baseLists "github.com/AssetMantle/modules/schema/lists/base"
1215
baseProperties "github.com/AssetMantle/modules/schema/properties/base"
@@ -15,6 +18,7 @@ import (
1518
"github.com/cosmos/cosmos-sdk/codec"
1619
"github.com/cosmos/cosmos-sdk/types"
1720
"github.com/cosmos/cosmos-sdk/types/rest"
21+
"github.com/spf13/viper"
1822
"reflect"
1923
"testing"
2024
)
@@ -75,6 +79,15 @@ func Test_requestPrototype(t *testing.T) {
7579
}
7680

7781
func Test_transactionRequest_FromCLI(t *testing.T) {
82+
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.AssetID, constants.FromID, constants.ToID, constants.ClassificationID, constants.ImmutableMetaProperties, constants.ImmutableProperties, constants.MutableMetaProperties, constants.MutableProperties})
83+
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
84+
viper.Set(constants.FromID.GetName(), fromID.String())
85+
viper.Set(constants.ToID.GetName(), fromID.String())
86+
viper.Set(constants.ClassificationID.GetName(), classificationID.String())
87+
viper.Set(constants.ImmutableMetaProperties.GetName(), immutableMetaPropertiesString)
88+
viper.Set(constants.ImmutableProperties.GetName(), immutablePropertiesString)
89+
viper.Set(constants.MutableMetaProperties.GetName(), mutableMetaPropertiesString)
90+
viper.Set(constants.MutableProperties.GetName(), mutablePropertiesString)
7891
type fields struct {
7992
BaseReq rest.BaseReq
8093
FromID string
@@ -96,7 +109,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
96109
want helpers.TransactionRequest
97110
wantErr bool
98111
}{
99-
// TODO: Add test cases.
112+
{"+ve", fields{}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), fromID.String(), classificationID.String(), immutableMetaPropertiesString, immutablePropertiesString, mutableMetaPropertiesString, mutablePropertiesString}, false},
100113
}
101114
for _, tt := range tests {
102115
t.Run(tt.name, func(t *testing.T) {
@@ -115,7 +128,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
115128
t.Errorf("FromCLI() error = %v, wantErr %v", err, tt.wantErr)
116129
return
117130
}
118-
if !reflect.DeepEqual(got, tt.want) {
131+
if !reflect.DeepEqual(fmt.Sprint(got), fmt.Sprint(tt.want)) {
119132
t.Errorf("FromCLI() got = %v, want %v", got, tt.want)
120133
}
121134
})

0 commit comments

Comments
 (0)