github.com/cosmos/cosmos-sdk@v0.50.10/testutil/network/doc.go (about)

     1  /*
     2  Package network implements and exposes a fully operational in-process CometBFT
     3  test network that consists of at least one or potentially many validators. This
     4  test network can be used primarily for integration tests or unit test suites.
     5  
     6  The test network utilizes SimApp as the ABCI application and uses all the modules
     7  defined in the Cosmos SDK. An in-process test network can be configured with any
     8  number of validators as well as account funds and even custom genesis state.
     9  
    10  When creating a test network, a series of Validator objects are returned. Each
    11  Validator object has useful information such as their address and public key. A
    12  Validator will also provide its RPC, P2P, and API addresses that can be useful
    13  for integration testing. In addition, a CometBFT local RPC client is also provided
    14  which can be handy for making direct RPC calls to CometBFT.
    15  
    16  Note, due to limitations in concurrency and the design of the RPC layer in
    17  CometBFT, only the first Validator object will have an RPC and API client
    18  exposed. Due to this exact same limitation, only a single test network can exist
    19  at a time. A caller must be certain it calls Cleanup after it no longer needs
    20  the network.
    21  
    22  A typical testing flow might look like the following:
    23  
    24  	type IntegrationTestSuite struct {
    25  		suite.Suite
    26  
    27  		cfg     network.Config
    28  		network *network.Network
    29  	}
    30  
    31  	func (s *IntegrationTestSuite) SetupSuite() {
    32  		s.T().Log("setting up integration test suite")
    33  
    34  		cfg := network.DefaultConfig()
    35  		cfg.NumValidators = 1
    36  		s.cfg = cfg
    37  
    38  		var err error
    39  		s.network, err = network.New(s.T(), s.T().TempDir(), cfg)
    40  		s.Require().NoError(err)
    41  
    42  		s.Require().NoError(s.network.WaitForNextBlock())
    43  	}
    44  
    45  	func (s *IntegrationTestSuite) TearDownSuite() {
    46  		s.T().Log("tearing down integration test suite")
    47  
    48  		// This is important and must be called to ensure other tests can create
    49  		// a network!
    50  		s.network.Cleanup()
    51  	}
    52  
    53  	func (s *IntegrationTestSuite) TestQueryBalancesRequestHandlerFn() {
    54  		val := s.network.Validators[0]
    55  		baseURL := val.APIAddress
    56  
    57  		// Use baseURL to make API HTTP requests or use val.RPCClient to make direct
    58  		// CometBFT RPC calls.
    59  		// ...
    60  	}
    61  
    62  	func TestIntegrationTestSuite(t *testing.T) {
    63  		suite.Run(t, new(IntegrationTestSuite))
    64  	}
    65  */
    66  package network