Add e2e tests for gRPC requests and CLI commands #13
17
tests/e2e/registry/cli_test.go
Normal file
17
tests/e2e/registry/cli_test.go
Normal file
@ -0,0 +1,17 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"git.vdb.to/cerc-io/laconic2d/tests/e2e"
|
||||
)
|
||||
|
||||
func TestRegistryE2ETestSuite(t *testing.T) {
|
||||
cfg := network.DefaultConfig(e2e.NewTestNetworkFixture)
|
||||
cfg.NumValidators = 1
|
||||
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
}
|
58
tests/e2e/registry/grpc.go
Normal file
58
tests/e2e/registry/grpc.go
Normal file
@ -0,0 +1,58 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
|
||||
)
|
||||
|
||||
const badPath = "/asdasd"
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryParams() {
|
||||
val := ets.network.Validators[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.APIAddress + "/cerc/registry/v1/params"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
}{
|
||||
{
|
||||
"invalid request",
|
||||
reqURL + badPath,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqURL,
|
||||
false,
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryParamsResponse
|
||||
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
params := registrytypes.DefaultParams()
|
||||
params.RecordRent = sdk.NewCoin(ets.cfg.BondDenom, registrytypes.DefaultRecordRent)
|
||||
params.RecordRentDuration = 10 * time.Second
|
||||
params.AuthorityGracePeriod = 10 * time.Second
|
||||
sr.Equal(response.GetParams().String(), params.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
102
tests/e2e/registry/suite.go
Normal file
102
tests/e2e/registry/suite.go
Normal file
@ -0,0 +1,102 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
|
||||
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
|
||||
)
|
||||
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
|
||||
accountName string
|
||||
accountAddress string
|
||||
|
||||
bondId string
|
||||
}
|
||||
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) SetupSuite() {
|
||||
sr := ets.Require()
|
||||
ets.T().Log("setting up e2e test suite")
|
||||
|
||||
var err error
|
||||
|
||||
genesisState := ets.cfg.GenesisState
|
||||
var registryGenesis registrytypes.GenesisState
|
||||
ets.Require().NoError(ets.cfg.Codec.UnmarshalJSON(genesisState[registrytypes.ModuleName], ®istryGenesis))
|
||||
|
||||
registryGenesis.Params.RecordRent = sdk.NewCoin(ets.cfg.BondDenom, registrytypes.DefaultRecordRent)
|
||||
registryGenesis.Params.RecordRentDuration = 10 * time.Second
|
||||
registryGenesis.Params.AuthorityGracePeriod = 10 * time.Second
|
||||
registryGenesisBz, err := ets.cfg.Codec.MarshalJSON(®istryGenesis)
|
||||
ets.Require().NoError(err)
|
||||
genesisState[registrytypes.ModuleName] = registryGenesisBz
|
||||
ets.cfg.GenesisState = genesisState
|
||||
|
||||
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
||||
sr.NoError(err)
|
||||
|
||||
_, err = ets.network.WaitForHeight(2)
|
||||
sr.NoError(err)
|
||||
|
||||
// setting up random account
|
||||
ets.accountName = "accountName"
|
||||
ets.createAccountWithBalance(ets.accountName, &ets.accountAddress)
|
||||
|
||||
// ets.bondId = ets.createBond()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TearDownSuite() {
|
||||
ets.T().Log("tearing down e2e test suite")
|
||||
ets.network.Cleanup()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAddress *string) {
|
||||
val := ets.network.Validators[0]
|
||||
sr := ets.Require()
|
||||
|
||||
info, _, err := val.ClientCtx.Keyring.NewMnemonic(accountName, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
sr.NoError(err)
|
||||
|
||||
newAddr, _ := info.GetAddress()
|
||||
_, err = clitestutil.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
newAddr,
|
||||
sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(1000000000000000000))),
|
||||
addresscodec.NewBech32Codec("laconic"),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
)
|
||||
sr.NoError(err)
|
||||
*accountAddress = newAddr.String()
|
||||
|
||||
// wait for tx to take effect
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user