Skip to content

Commit

Permalink
test(splits): add tests for fromCLI methods
Browse files Browse the repository at this point in the history
  • Loading branch information
0xankit committed Dec 13, 2022
1 parent 9586148 commit fc96647
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
14 changes: 12 additions & 2 deletions modules/splits/internal/transactions/send/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ package send

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"
"github.com/stretchr/testify/require"
"reflect"
"testing"
Expand Down Expand Up @@ -73,6 +77,12 @@ func Test_requestPrototype(t *testing.T) {
}

func Test_transactionRequest_FromCLI(t *testing.T) {
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.ToID, constants.FromID, constants.OwnableID, constants.Value})
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.OwnableID.GetName(), ownableID.String())
viper.Set(constants.Value.GetName(), testRate.String())
type fields struct {
BaseReq rest.BaseReq
FromID string
Expand All @@ -91,7 +101,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
want helpers.TransactionRequest
wantErr bool
}{
// TODO: Add test cases.
{"+ve", fields{testBaseRequest, fromID.String(), fromID.String(), ownableID.String(), testRate.String()}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), fromID.String(), ownableID.String(), testRate.String()}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -107,7 +117,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
13 changes: 11 additions & 2 deletions modules/splits/internal/transactions/unwrap/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ package unwrap

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"
"github.com/stretchr/testify/require"
"math/big"
"reflect"
Expand Down Expand Up @@ -73,6 +77,11 @@ func Test_requestPrototype(t *testing.T) {
}

func Test_transactionRequest_FromCLI(t *testing.T) {
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.OwnableID, constants.FromID, constants.Value})
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
viper.Set(constants.FromID.GetName(), fromID.String())
viper.Set(constants.OwnableID.GetName(), ownableID.String())
viper.Set(constants.Value.GetName(), testRate.String())
type fields struct {
BaseReq rest.BaseReq
FromID string
Expand All @@ -90,7 +99,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
want helpers.TransactionRequest
wantErr bool
}{
// TODO: Add test cases.
{"+ve", fields{testBaseRequest, fromID.String(), ownableID.String(), testRate.String()}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), ownableID.String(), testRate.String()}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -105,7 +114,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
11 changes: 9 additions & 2 deletions modules/splits/internal/transactions/wrap/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"
"github.com/stretchr/testify/require"
"reflect"
"testing"
Expand Down Expand Up @@ -72,6 +75,10 @@ func Test_requestPrototype(t *testing.T) {
}

func Test_transactionRequest_FromCLI(t *testing.T) {
cliCommand := base.NewCLICommand("", "", "", []helpers.CLIFlag{constants.Coins, constants.FromID})
cliContext := context.NewCLIContext().WithCodec(codec.New()).WithFromAddress(fromAccAddress).WithChainID("test")
viper.Set(constants.FromID.GetName(), fromID.String())
viper.Set(constants.Coins.GetName(), testRate.String())
type fields struct {
BaseReq rest.BaseReq
FromID string
Expand All @@ -88,7 +95,7 @@ func Test_transactionRequest_FromCLI(t *testing.T) {
want helpers.TransactionRequest
wantErr bool
}{
// TODO: Add test cases.
{"+ve", fields{testBaseRequest, fromID.String(), testRate.String()}, args{cliCommand, cliContext}, transactionRequest{testBaseRequest, fromID.String(), testRate.String()}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -102,7 +109,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

0 comments on commit fc96647

Please sign in to comment.