github.com/Finschia/finschia-sdk@v0.49.1/x/fswap/client/testutil/suite.go (about)

     1  package testutil
     2  
     3  import (
     4  	"github.com/stretchr/testify/suite"
     5  
     6  	"github.com/Finschia/finschia-sdk/testutil/network"
     7  	sdk "github.com/Finschia/finschia-sdk/types"
     8  	banktypes "github.com/Finschia/finschia-sdk/x/bank/types"
     9  	fswaptypes "github.com/Finschia/finschia-sdk/x/fswap/types"
    10  )
    11  
    12  const jsonOutputFormat string = "JSON"
    13  
    14  type IntegrationTestSuite struct {
    15  	suite.Suite
    16  
    17  	cfg     network.Config
    18  	network *network.Network
    19  
    20  	authority sdk.AccAddress
    21  	toDenom   banktypes.Metadata
    22  	dummySwap fswaptypes.Swap
    23  }
    24  
    25  func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
    26  	return &IntegrationTestSuite{cfg: cfg}
    27  }
    28  
    29  func (s *IntegrationTestSuite) SetupSuite() {
    30  	s.T().Log("setting up integration test suite")
    31  
    32  	genesisState := s.cfg.GenesisState
    33  	var bankGenesis banktypes.GenesisState
    34  	s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[banktypes.ModuleName], &bankGenesis))
    35  	s.toDenom = banktypes.Metadata{
    36  		Name:        "Dummy Coin",
    37  		Symbol:      "Dummy",
    38  		Description: "The native token of Dummy chain",
    39  		DenomUnits: []*banktypes.DenomUnit{
    40  			{
    41  				Denom:    "dummy",
    42  				Exponent: 0,
    43  				Aliases:  []string{},
    44  			},
    45  		},
    46  		Base:    "dummy",
    47  		Display: "dummy",
    48  	}
    49  	bankGenesis.DenomMetadata = []banktypes.Metadata{s.toDenom}
    50  	bankDataBz, err := s.cfg.Codec.MarshalJSON(&bankGenesis)
    51  	s.Require().NoError(err)
    52  	genesisState[banktypes.ModuleName] = bankDataBz
    53  
    54  	bondDenom := s.cfg.BondDenom
    55  	toDenom := s.toDenom.Base
    56  
    57  	var fswapData fswaptypes.GenesisState
    58  	s.Require().NoError(s.cfg.Codec.UnmarshalJSON(genesisState[fswaptypes.ModuleName], &fswapData))
    59  	fswapData.SwapStats.SwapCount = 1
    60  	s.dummySwap = fswaptypes.Swap{
    61  		FromDenom:           bondDenom,
    62  		ToDenom:             toDenom,
    63  		AmountCapForToDenom: sdk.NewInt(12340000000000),
    64  		SwapRate:            sdk.MustNewDecFromStr("1234"),
    65  	}
    66  
    67  	fswapData.Swaps = []fswaptypes.Swap{s.dummySwap}
    68  	fswapData.Swappeds = []fswaptypes.Swapped{
    69  		{
    70  			FromCoinAmount: sdk.Coin{
    71  				Denom:  bondDenom,
    72  				Amount: sdk.ZeroInt(),
    73  			},
    74  			ToCoinAmount: sdk.Coin{
    75  				Denom:  toDenom,
    76  				Amount: sdk.ZeroInt(),
    77  			},
    78  		},
    79  	}
    80  
    81  	fswapDataBz, err := s.cfg.Codec.MarshalJSON(&fswapData)
    82  	s.Require().NoError(err)
    83  	genesisState[fswaptypes.ModuleName] = fswapDataBz
    84  	s.cfg.GenesisState = genesisState
    85  
    86  	s.network = network.New(s.T(), s.cfg)
    87  	s.authority = fswaptypes.DefaultAuthority()
    88  
    89  	_, err = s.network.WaitForHeight(1)
    90  	s.Require().NoError(err)
    91  }
    92  
    93  func (s *IntegrationTestSuite) TearDownSuite() {
    94  	s.T().Log("tearing down integration test suite")
    95  	s.network.Cleanup()
    96  }