laconicd/tests/e2e/bond/grpc.go
Prathamesh Musale aed2d6d4c6
Some checks failed
Integration Tests / test-integration (push) Successful in 2m0s
E2E Tests / test-e2e (push) Failing after 2m2s
Unit Tests / test-unit (push) Successful in 1m19s
Lint / Run golangci-lint (push) Successful in 4m26s
Rename RPC method to reserve authority and fix proto lint errors (#17)
- Rename RPC method to reserve authority from `ReserveName` to `ReserveAuthority`
  and `GetBondsModuleBalance` to `GetBondModuleBalance`
- Run lint formatter
- Fix proto lint errors and regenerate proto bindings

Reviewed-on: deep-stack/laconic2d#17
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
2024-03-07 11:25:15 +00:00

184 lines
3.8 KiB
Go

package bond
import (
"fmt"
"github.com/cosmos/cosmos-sdk/testutil"
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
)
func (ets *E2ETestSuite) TestGRPCGetParams() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/bond/v1/params", val.APIAddress)
resp, err := testutil.GetRequest(reqURL)
ets.Require().NoError(err)
var params bondtypes.QueryParamsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &params)
sr.NoError(err)
sr.Equal(params.GetParams().MaxBondAmount, bondtypes.DefaultParams().MaxBondAmount)
}
func (ets *E2ETestSuite) TestGRPCGetBonds() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/bond/v1/bonds", val.APIAddress)
testCases := []struct {
name string
url string
expErr bool
errorMsg string
preRun func() string
}{
{
"invalid request with headers",
reqURL + "asdasdas",
true,
"",
func() string { return "" },
},
{
"valid request",
reqURL,
false,
"",
func() string { return ets.createBond() },
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
tc.preRun()
resp, _ := testutil.GetRequest(tc.url)
if tc.expErr {
sr.Contains(string(resp), tc.errorMsg)
} else {
var response bondtypes.QueryBondsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
sr.NotZero(len(response.GetBonds()))
}
})
}
}
func (ets *E2ETestSuite) TestGRPCGetBondsByOwner() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := val.APIAddress + "/cerc/bond/v1/by-owner/%s"
testCases := []struct {
name string
url string
expErr bool
preRun func() string
}{
{
"empty list",
fmt.Sprintf(reqURL, "asdasd"),
true,
func() string { return "" },
},
{
"valid request",
fmt.Sprintf(reqURL, ets.accountAddress),
false,
func() string { return ets.createBond() },
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
tc.preRun()
resp, err := testutil.GetRequest(tc.url)
ets.Require().NoError(err)
var bonds bondtypes.QueryGetBondsByOwnerResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bonds)
sr.NoError(err)
if tc.expErr {
sr.Empty(bonds.GetBonds())
} else {
bondsList := bonds.GetBonds()
sr.NotZero(len(bondsList))
sr.Equal(ets.accountAddress, bondsList[0].GetOwner())
}
})
}
}
func (ets *E2ETestSuite) TestGRPCGetBondById() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := val.APIAddress + "/cerc/bond/v1/bonds/%s"
testCases := []struct {
name string
url string
expErr bool
preRun func() string
}{
{
"invalid request",
fmt.Sprintf(reqURL, "asdadad"),
true,
func() string { return "" },
},
{
"valid request",
reqURL,
false,
func() string { return ets.createBond() },
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
var bondId string
if !tc.expErr {
bondId = tc.preRun()
tc.url = fmt.Sprintf(reqURL, bondId)
}
resp, err := testutil.GetRequest(tc.url)
ets.Require().NoError(err)
var bonds bondtypes.QueryGetBondByIdResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bonds)
if tc.expErr {
sr.Empty(bonds.GetBond().GetId())
} else {
sr.NoError(err)
sr.NotZero(bonds.GetBond().GetId())
sr.Equal(bonds.GetBond().GetId(), bondId)
}
})
}
}
func (ets *E2ETestSuite) TestGRPCGetBondModuleBalance() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := fmt.Sprintf("%s/cerc/bond/v1/balance", val.APIAddress)
// creating the bond
ets.createBond()
ets.Run("valid request", func() {
resp, err := testutil.GetRequest(reqURL)
sr.NoError(err)
var response bondtypes.QueryGetBondModuleBalanceResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
sr.False(response.GetBalance().IsZero())
})
}