Skip to content

Commit

Permalink
Added types for Querier types
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Jul 19, 2021
1 parent 7ff76fa commit dc299e9
Show file tree
Hide file tree
Showing 7 changed files with 700 additions and 0 deletions.
53 changes: 53 additions & 0 deletions x/deposit/types/querier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package types

import (
"crypto/rand"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"
)

func TestNewQueryDepositRequest(t *testing.T) {
var (
address []byte
)

for i := 0; i < 40; i++ {
address = make([]byte, i)
_, _ = rand.Read(address)

require.Equal(
t,
&QueryDepositRequest{
Address: sdk.AccAddress(address).String(),
},
NewQueryDepositRequest(address),
)
}
}

func TestNewQueryDepositsRequest(t *testing.T) {
var (
pagination *query.PageRequest
)

for i := 0; i < 20; i++ {
pagination = &query.PageRequest{
Key: make([]byte, i),
Offset: uint64(i),
Limit: uint64(i),
CountTotal: i/2 == 0,
}
_, _ = rand.Read(pagination.Key)

require.Equal(
t,
&QueryDepositsRequest{
Pagination: pagination,
},
NewQueryDepositsRequest(pagination),
)
}
}
97 changes: 97 additions & 0 deletions x/node/types/querier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package types

import (
"crypto/rand"
"testing"

"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"

hubtypes "github.com/sentinel-official/hub/types"
)

func TestNewQueryNodeRequest(t *testing.T) {
var (
address []byte
)

for i := 0; i < 40; i++ {
address = make([]byte, i)
_, _ = rand.Read(address)

require.Equal(
t,
&QueryNodeRequest{
Address: hubtypes.NodeAddress(address).String(),
},
NewQueryNodeRequest(address),
)
}
}

func TestNewQueryNodesForProviderRequest(t *testing.T) {
var (
address []byte
status hubtypes.Status
pagination *query.PageRequest
)

for i := 0; i < 40; i++ {
address = make([]byte, i)
status = hubtypes.Status(i % 4)
pagination = &query.PageRequest{
Key: make([]byte, i),
Offset: uint64(i),
Limit: uint64(i),
CountTotal: i/2 == 0,
}

_, _ = rand.Read(address)
_, _ = rand.Read(pagination.Key)

require.Equal(
t,
&QueryNodesForProviderRequest{
Address: hubtypes.ProvAddress(address).String(),
Status: status,
Pagination: pagination,
},
NewQueryNodesForProviderRequest(address, status, pagination),
)
}
}

func TestNewQueryNodesRequest(t *testing.T) {
var (
status hubtypes.Status
pagination *query.PageRequest
)

for i := 0; i < 20; i++ {
status = hubtypes.Status(i % 4)
pagination = &query.PageRequest{
Key: make([]byte, i),
Offset: uint64(i),
Limit: uint64(i),
CountTotal: i/2 == 0,
}

_, _ = rand.Read(pagination.Key)

require.Equal(
t,
&QueryNodesRequest{
Status: status,
Pagination: pagination,
},
NewQueryNodesRequest(status, pagination),
)
}
}

func TestNewQueryParamsRequest(t *testing.T) {
require.Equal(t,
&QueryParamsRequest{},
NewQueryParamsRequest(),
)
}
107 changes: 107 additions & 0 deletions x/plan/types/querier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package types

import (
"crypto/rand"
"testing"

"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"

hubtypes "github.com/sentinel-official/hub/types"
)

func TestNewQueryNodesForPlanRequest(t *testing.T) {
var (
pagination *query.PageRequest
)

for i := 0; i < 20; i++ {
pagination = &query.PageRequest{
Key: make([]byte, i),
Offset: uint64(i),
Limit: uint64(i),
CountTotal: i/2 == 0,
}

require.Equal(
t,
&QueryNodesForPlanRequest{
Id: uint64(i),
Pagination: pagination,
},
NewQueryNodesForPlanRequest(uint64(i), pagination),
)
}
}

func TestNewQueryPlanRequest(t *testing.T) {
for i := 0; i < 20; i++ {
require.Equal(
t,
&QueryPlanRequest{
Id: uint64(i),
},
NewQueryPlanRequest(uint64(i)),
)
}
}

func TestNewQueryPlansForProviderRequest(t *testing.T) {
var (
address []byte
status hubtypes.Status
pagination *query.PageRequest
)

for i := 0; i < 40; i++ {
address = make([]byte, i)
status = hubtypes.Status(i % 4)
pagination = &query.PageRequest{
Key: make([]byte, i),
Offset: uint64(i),
Limit: uint64(i),
CountTotal: i/2 == 0,
}

_, _ = rand.Read(address)
_, _ = rand.Read(pagination.Key)

require.Equal(
t,
&QueryPlansForProviderRequest{
Address: hubtypes.ProvAddress(address).String(),
Status: status,
Pagination: pagination,
},
NewQueryPlansForProviderRequest(address, status, pagination),
)
}
}

func TestNewQueryPlansRequest(t *testing.T) {
var (
status hubtypes.Status
pagination *query.PageRequest
)

for i := 0; i < 20; i++ {
status = hubtypes.Status(i % 4)
pagination = &query.PageRequest{
Key: make([]byte, i),
Offset: uint64(i),
Limit: uint64(i),
CountTotal: i/2 == 0,
}

_, _ = rand.Read(pagination.Key)

require.Equal(
t,
&QueryPlansRequest{
Status: status,
Pagination: pagination,
},
NewQueryPlansRequest(status, pagination),
)
}
}
62 changes: 62 additions & 0 deletions x/provider/types/querier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package types

import (
"crypto/rand"
"testing"

"github.com/cosmos/cosmos-sdk/types/query"
"github.com/stretchr/testify/require"

hubtypes "github.com/sentinel-official/hub/types"
)

func TestNewQueryParamsRequest(t *testing.T) {
require.Equal(t,
&QueryParamsRequest{},
NewQueryParamsRequest(),
)
}

func TestNewQueryProviderRequest(t *testing.T) {
var (
address []byte
)

for i := 0; i < 40; i++ {
address = make([]byte, i)
_, _ = rand.Read(address)

require.Equal(
t,
&QueryProviderRequest{
Address: hubtypes.ProvAddress(address).String(),
},
NewQueryProviderRequest(address),
)
}
}

func TestNewQueryProvidersRequest(t *testing.T) {
var (
pagination *query.PageRequest
)

for i := 0; i < 20; i++ {
pagination = &query.PageRequest{
Key: make([]byte, i),
Offset: uint64(i),
Limit: uint64(i),
CountTotal: i/2 == 0,
}

_, _ = rand.Read(pagination.Key)

require.Equal(
t,
&QueryProvidersRequest{
Pagination: pagination,
},
NewQueryProvidersRequest(pagination),
)
}
}
Loading

0 comments on commit dc299e9

Please sign in to comment.