App Integration Suites
Overview
When to Use Test Suites
Using an Existing Integration Suite
Example (ParamsSuite)
package suites
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
cosmostypes "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
)
type ExampleTestSuite struct {
suites.ParamsSuite
}
// SetupTest is called before each test method in the suite.
func (s *ExampleTestSuite) SetupTest() {
// Initialize a new app instance for each test.
s.app = NewApp(s.T())
// Setup the authz accounts and grants for updating parameters.
s.SetupTestAuthzAccounts()
s.SetupTestAuthzGrants()
// Set the module params using the ParamsSuite.
s.RunUpdateParam(s.T(),
sharedtypes.ModuleName,
string(sharedtypes.KeyNumBlocksPerSession),
9001,
)
}
func (s *ExampleTestSuite) TestExample() {
// Query module params using the ParamsSuite.
sharedParams, err := s.QueryModuleParams(s.T(), sharedtypes.ModuleName)
require.NoError(s.T(), err)
// Utilize other BaseIntegrationSuite methods to interact with the app...
fundAmount := int64(1000)
fundAddr, err := cosmostypes.AccAddressFromBech32("cosmos1exampleaddress...")
require.NoError(s.T(), err)
// Fund an address using the suite's FundAddress method.
s.FundAddress(s.T(), fundAddr, fundAmount)
// Use the bank query client to verify the balance.
bankQueryClient := s.GetBankQueryClient()
balRes, err := bankQueryClient.Balance(s.SdkCtx(), &banktypes.QueryBalanceRequest{
Address: fundAddr.String(),
Denom: "upokt",
})
// Validate the balance.
require.NoError(s.T(), err)
require.Equal(s.T(), fundAmount, balRes.GetBalance().Amount.Int64())
}
// Run the ExampleIntegrationSuite.
func TestExampleTestSuite(t *testing.T) {
suite.Run(t, new(ExampleTestSuite))
}Implementing a Test Suite
Test Suite Gotchas
Last updated
Was this helpful?
