github.com/Finschia/finschia-sdk@v0.48.1/testutil/network/doc.go (about) 1 /* 2 Package network implements and exposes a fully operational in-process Tendermint 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 Tendermint local RPC client is also provided 14 which can be handy for making direct RPC calls to Tendermint. 15 16 Note, due to limitations in concurrency and the design of the RPC layer in 17 Tendermint, 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 testutil.Config 28 network *testutil.Network 29 } 30 31 func (s *IntegrationTestSuite) SetupSuite() { 32 s.T().Log("setting up integration test suite") 33 34 cfg := testutil.DefaultConfig() 35 cfg.NumValidators = 1 36 37 s.cfg = cfg 38 s.network = testutil.New(s.T(), cfg) 39 40 _, err := s.network.WaitForHeight(1) 41 s.Require().NoError(err) 42 } 43 44 func (s *IntegrationTestSuite) TearDownSuite() { 45 s.T().Log("tearing down integration test suite") 46 47 // This is important and must be called to ensure other tests can create 48 // a network! 49 s.network.Cleanup() 50 } 51 52 func (s *IntegrationTestSuite) TestQueryBalancesRequestHandlerFn() { 53 val := s.network.Validators[0] 54 baseURL := val.APIAddress 55 56 // Use baseURL to make API HTTP requests or use val.RPCClient to make direct 57 // Tendermint RPC calls. 58 // ... 59 } 60 61 func TestIntegrationTestSuite(t *testing.T) { 62 suite.Run(t, new(IntegrationTestSuite)) 63 } 64 */ 65 package network