diff --git a/x/plan/types/genesis_test.go b/x/plan/types/genesis_test.go new file mode 100644 index 00000000..13ed40fb --- /dev/null +++ b/x/plan/types/genesis_test.go @@ -0,0 +1,45 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDefaultGenesisState(t *testing.T) { + var ( + state GenesisState + ) + + state = DefaultGenesisState() + require.Equal(t, GenesisState(nil), state) +} + +func TestNewGenesisState(t *testing.T) { + var ( + plans GenesisPlans + state GenesisState + ) + + state = NewGenesisState(nil) + require.Nil(t, state) + require.Len(t, state, 0) + + state = NewGenesisState(plans) + require.Equal(t, GenesisState(nil), state) + require.Len(t, state, 0) + + plans = append(plans, + GenesisPlan{}, + ) + state = NewGenesisState(plans) + require.Equal(t, GenesisState(plans), state) + require.Len(t, state, 1) + + plans = append(plans, + GenesisPlan{}, + ) + state = NewGenesisState(plans) + require.Equal(t, GenesisState(plans), state) + require.Len(t, state, 2) +} diff --git a/x/plan/types/msg_test.go b/x/plan/types/msg_test.go new file mode 100644 index 00000000..ab2cb8b5 --- /dev/null +++ b/x/plan/types/msg_test.go @@ -0,0 +1,590 @@ +package types + +import ( + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + hubtypes "github.com/sentinel-official/hub/types" +) + +func TestMsgAddRequest_ValidateBasic(t *testing.T) { + type fields struct { + From string + Price sdk.Coins + Validity time.Duration + Bytes sdk.Int + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + { + "empty address", + fields{ + From: "", + }, + true, + }, + { + "invalid address", + fields{ + From: "invalid", + }, + true, + }, + { + "invalid prefix address", + fields{ + From: "sent1qypqxpq9qcrsszgszyfpx9q4zct3sxfq0fzduj", + }, + true, + }, + { + "10 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgsutj8xr", + }, + true, + }, + { + "20 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + }, + true, + }, + { + "30 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfqyy3zxfp9ycnjs2fsh33zgx", + }, + true, + }, + { + "nil price", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: nil, + }, + true, + }, + { + "empty price", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{}, + }, + true, + }, + { + "empty denom price", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: ""}}, + }, + true, + }, + { + "invalid denom price", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "o"}}, + }, + true, + }, + { + "negative amount price", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + }, + true, + }, + { + "zero amount price", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + }, + true, + }, + { + "positive amount price", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + }, + true, + }, + { + "negative validity", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: -1000, + }, + true, + }, + { + "zero validity", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 0, + }, + true, + }, + { + "positive validity", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(0), + }, + true, + }, + { + "negative bytes", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(-1000), + }, + true, + }, + { + "zero bytes", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(0), + }, + true, + }, + { + "positive bytes", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + }, + false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &MsgAddRequest{ + From: tt.fields.From, + Price: tt.fields.Price, + Validity: tt.fields.Validity, + Bytes: tt.fields.Bytes, + } + if err := m.ValidateBasic(); (err != nil) != tt.wantErr { + t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMsgSetStatusRequest_ValidateBasic(t *testing.T) { + type fields struct { + From string + Id uint64 + Status hubtypes.Status + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + { + "empty address", + fields{ + From: "", + }, + true, + }, + { + "invalid address", + fields{ + From: "invalid", + }, + true, + }, + { + "invalid prefix address", + fields{ + From: "sent1qypqxpq9qcrsszgszyfpx9q4zct3sxfq0fzduj", + }, + true, + }, + { + "10 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgsutj8xr", + }, + true, + }, + { + "20 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + }, + true, + }, + { + "30 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfqyy3zxfp9ycnjs2fsh33zgx", + }, + true, + }, + { + "zero id", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 0, + }, + true, + }, + { + "positive id", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + }, + true, + }, + { + "unknown status", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Status: hubtypes.StatusUnknown, + }, + true, + }, + { + "active status", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Status: hubtypes.StatusActive, + }, + false, + }, + { + "inactive pending status", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Status: hubtypes.StatusInactivePending, + }, + true, + }, + { + "inactive status", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Status: hubtypes.StatusInactive, + }, + false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &MsgSetStatusRequest{ + From: tt.fields.From, + Id: tt.fields.Id, + Status: tt.fields.Status, + } + if err := m.ValidateBasic(); (err != nil) != tt.wantErr { + t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMsgAddNodeRequest_ValidateBasic(t *testing.T) { + type fields struct { + From string + Id uint64 + Address string + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + { + "empty address", + fields{ + From: "", + }, + true, + }, + { + "invalid address", + fields{ + From: "invalid", + }, + true, + }, + { + "invalid prefix address", + fields{ + From: "sent1qypqxpq9qcrsszgszyfpx9q4zct3sxfq0fzduj", + }, + true, + }, + { + "10 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgsutj8xr", + }, + true, + }, + { + "20 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + }, + true, + }, + { + "30 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfqyy3zxfp9ycnjs2fsh33zgx", + }, + true, + }, + { + "zero id", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 0, + }, + true, + }, + { + "positive id", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + }, + true, + }, + { + "empty address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "", + }, + true, + }, + { + "invalid address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "invalid", + }, + true, + }, + { + "invalid prefix address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sent1qypqxpq9qcrsszgszyfpx9q4zct3sxfq0fzduj", + }, + true, + }, + { + "10 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sentnode1qypqxpq9qcrsszgse4wwrm", + }, + true, + }, + { + "20 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sentnode1qypqxpq9qcrsszgszyfpx9q4zct3sxfqelr5ey", + }, + false, + }, + { + "30 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sentnode1qypqxpq9qcrsszgszyfpx9q4zct3sxfqyy3zxfp9ycnjs2fsxqglcv", + }, + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &MsgAddNodeRequest{ + From: tt.fields.From, + Id: tt.fields.Id, + Address: tt.fields.Address, + } + if err := m.ValidateBasic(); (err != nil) != tt.wantErr { + t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestMsgRemoveNodeRequest_ValidateBasic(t *testing.T) { + type fields struct { + From string + Id uint64 + Address string + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + { + "empty address", + fields{ + From: "", + }, + true, + }, + { + "invalid address", + fields{ + From: "invalid", + }, + true, + }, + { + "invalid prefix address", + fields{ + From: "sent1qypqxpq9qcrsszgszyfpx9q4zct3sxfq0fzduj", + }, + true, + }, + { + "10 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgsutj8xr", + }, + true, + }, + { + "20 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + }, + true, + }, + { + "30 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfqyy3zxfp9ycnjs2fsh33zgx", + }, + true, + }, + { + "zero id", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 0, + }, + true, + }, + { + "positive id", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + }, + true, + }, + { + "empty address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "", + }, + true, + }, + { + "invalid address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "invalid", + }, + true, + }, + { + "invalid prefix address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sent1qypqxpq9qcrsszgszyfpx9q4zct3sxfq0fzduj", + }, + true, + }, + { + "10 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sentnode1qypqxpq9qcrsszgse4wwrm", + }, + true, + }, + { + "20 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sentnode1qypqxpq9qcrsszgszyfpx9q4zct3sxfqelr5ey", + }, + false, + }, + { + "30 bytes address", + fields{ + From: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Id: 1000, + Address: "sentnode1qypqxpq9qcrsszgszyfpx9q4zct3sxfqyy3zxfp9ycnjs2fsxqglcv", + }, + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := &MsgRemoveNodeRequest{ + From: tt.fields.From, + Id: tt.fields.Id, + Address: tt.fields.Address, + } + if err := m.ValidateBasic(); (err != nil) != tt.wantErr { + t.Errorf("ValidateBasic() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} diff --git a/x/plan/types/plan_test.go b/x/plan/types/plan_test.go new file mode 100644 index 00000000..80144c3e --- /dev/null +++ b/x/plan/types/plan_test.go @@ -0,0 +1,447 @@ +package types + +import ( + "reflect" + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + + hubtypes "github.com/sentinel-official/hub/types" +) + +func TestPlan_GetProvider(t *testing.T) { + type fields struct { + Id uint64 + Provider string + Price sdk.Coins + Validity time.Duration + Bytes sdk.Int + Status hubtypes.Status + StatusAt time.Time + } + tests := []struct { + name string + fields fields + want hubtypes.ProvAddress + }{ + { + "empty", + fields{ + Provider: "", + }, + nil, + }, + { + "20 bytes", + fields{ + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + }, + hubtypes.ProvAddress{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &Plan{ + Id: tt.fields.Id, + Provider: tt.fields.Provider, + Price: tt.fields.Price, + Validity: tt.fields.Validity, + Bytes: tt.fields.Bytes, + Status: tt.fields.Status, + StatusAt: tt.fields.StatusAt, + } + if got := p.GetProvider(); !reflect.DeepEqual(got, tt.want) { + t.Errorf("GetProvider() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestPlan_PriceForDenom(t *testing.T) { + type fields struct { + Id uint64 + Provider string + Price sdk.Coins + Validity time.Duration + Bytes sdk.Int + Status hubtypes.Status + StatusAt time.Time + } + type args struct { + d string + } + tests := []struct { + name string + fields fields + args args + want sdk.Coin + want1 bool + }{ + { + "nil price and empty denom", + fields{ + Price: nil, + }, + args{ + d: "", + }, + sdk.Coin{}, + false, + }, + { + "empty price and empty denom", + fields{ + Price: sdk.Coins{}, + }, + args{ + d: "", + }, + sdk.Coin{}, + false, + }, + { + "1one price and empty denom", + fields{ + Price: sdk.Coins{sdk.NewInt64Coin("one", 1)}, + }, + args{ + d: "", + }, + sdk.Coin{}, + false, + }, + { + "1one price and one denom", + fields{ + Price: sdk.Coins{sdk.NewInt64Coin("one", 1)}, + }, + args{ + d: "one", + }, + sdk.NewInt64Coin("one", 1), + true, + }, + { + "1one price and two denom", + fields{ + Price: sdk.Coins{sdk.NewInt64Coin("one", 1)}, + }, + args{ + d: "two", + }, + sdk.Coin{}, + false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &Plan{ + Id: tt.fields.Id, + Provider: tt.fields.Provider, + Price: tt.fields.Price, + Validity: tt.fields.Validity, + Bytes: tt.fields.Bytes, + Status: tt.fields.Status, + StatusAt: tt.fields.StatusAt, + } + got, got1 := p.PriceForDenom(tt.args.d) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("PriceForDenom() got = %v, want %v", got, tt.want) + } + if got1 != tt.want1 { + t.Errorf("PriceForDenom() got1 = %v, want %v", got1, tt.want1) + } + }) + } +} + +func TestPlan_Validate(t *testing.T) { + type fields struct { + Id uint64 + Provider string + Price sdk.Coins + Validity time.Duration + Bytes sdk.Int + Status hubtypes.Status + StatusAt time.Time + } + tests := []struct { + name string + fields fields + wantErr bool + }{ + { + "zero id", + fields{ + Id: 0, + }, + true, + }, + { + "empty provider", + fields{ + Id: 1000, + Provider: "", + }, + true, + }, + { + "invalid provider", + fields{ + Id: 1000, + Provider: "invalid", + }, + true, + }, + { + "invalid prefix provider", + fields{ + Id: 1000, + Provider: "sent1qypqxpq9qcrsszgszyfpx9q4zct3sxfq0fzduj", + }, + true, + }, + { + "10 bytes provider", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgsutj8xr", + }, + true, + }, + { + "20 bytes provider", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + }, + true, + }, + { + "30 bytes provider", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfqyy3zxfp9ycnjs2fsh33zgx", + }, + true, + }, + { + "nil price", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: nil, + }, + true, + }, + { + "empty price", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{}, + }, + true, + }, + { + "empty denom price", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: ""}}, + }, + true, + }, + { + "invalid denom price", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "o"}}, + }, + true, + }, + { + "negative amount price", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(-1000)}}, + }, + true, + }, + { + "zero amount price", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(0)}}, + }, + true, + }, + { + "positive amount price", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + }, + true, + }, + { + "negative validity", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: -1000, + }, + true, + }, + { + "zero validity", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 0, + }, + true, + }, + { + "positive validity", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(0), + }, + true, + }, + { + "negative bytes", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(-1000), + }, + true, + }, + { + "zero bytes", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(0), + }, + true, + }, + { + "positive bytes", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + }, + true, + }, + { + "unknown status", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + Status: hubtypes.StatusUnknown, + }, + true, + }, + { + "active status", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + Status: hubtypes.StatusActive, + }, + true, + }, + { + "inactive pending status", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + Status: hubtypes.StatusInactivePending, + }, + true, + }, + { + "inactive status", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + Status: hubtypes.StatusInactive, + }, + true, + }, + { + "zero status_at", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + Status: hubtypes.StatusInactive, + StatusAt: time.Time{}, + }, + true, + }, + { + "now status_at", + fields{ + Id: 1000, + Provider: "sentprov1qypqxpq9qcrsszgszyfpx9q4zct3sxfq877k82", + Price: sdk.Coins{sdk.Coin{Denom: "one", Amount: sdk.NewInt(1000)}}, + Validity: 1000, + Bytes: sdk.NewInt(1000), + Status: hubtypes.StatusInactive, + StatusAt: time.Now(), + }, + false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &Plan{ + Id: tt.fields.Id, + Provider: tt.fields.Provider, + Price: tt.fields.Price, + Validity: tt.fields.Validity, + Bytes: tt.fields.Bytes, + Status: tt.fields.Status, + StatusAt: tt.fields.StatusAt, + } + if err := p.Validate(); (err != nil) != tt.wantErr { + t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +}