github.com/ChainSafe/chainbridge-core@v1.4.2/chains/evm/cli/utils/utils_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/spf13/cobra"
     7  	"github.com/stretchr/testify/suite"
     8  )
     9  
    10  var (
    11  	validAddr     = "0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66"
    12  	invalidAddr   = "0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EXYZ"
    13  	validTxHash   = "0x455096e686c929229577767350d5c9151c609c2ba3e50a447e7092018d7f2dac"
    14  	invalidTxHash = "455096e686c929229577767350d5c9151c609c2ba3e50a447e7092018d7f2dac"
    15  )
    16  
    17  type UtilsTestSuite struct {
    18  	suite.Suite
    19  }
    20  
    21  func TestUtilsTestSuite(t *testing.T) {
    22  	suite.Run(t, new(UtilsTestSuite))
    23  }
    24  
    25  func (s *UtilsTestSuite) SetupSuite() {
    26  }
    27  func (s *UtilsTestSuite) TearDownSuite() {}
    28  
    29  func (s *UtilsTestSuite) TearDownTest() {}
    30  
    31  func (s *UtilsTestSuite) TestValidateSimulateFlags() {
    32  	cmd := new(cobra.Command)
    33  	BindSimulateFlags(cmd)
    34  
    35  	err := cmd.Flag("from").Value.Set(validAddr)
    36  	s.Nil(err)
    37  	err = cmd.Flag("tx-hash").Value.Set(validTxHash)
    38  	s.Nil(err)
    39  
    40  	err = ValidateSimulateFlags(
    41  		cmd,
    42  		[]string{},
    43  	)
    44  	s.Nil(err)
    45  }
    46  
    47  func (s *UtilsTestSuite) TestValidateSimulateInvalidAddress() {
    48  	cmd := new(cobra.Command)
    49  	BindSimulateFlags(cmd)
    50  
    51  	err := cmd.Flag("from").Value.Set(invalidAddr)
    52  	s.Nil(err)
    53  	err = cmd.Flag("tx-hash").Value.Set(validTxHash)
    54  	s.Nil(err)
    55  
    56  	err = ValidateSimulateFlags(
    57  		cmd,
    58  		[]string{},
    59  	)
    60  	s.NotNil(err)
    61  }
    62  
    63  func (s *UtilsTestSuite) TestValidateSimulateInvalidTxHash() {
    64  	cmd := new(cobra.Command)
    65  	BindSimulateFlags(cmd)
    66  
    67  	err := cmd.Flag("from").Value.Set(validAddr)
    68  	s.Nil(err)
    69  	err = cmd.Flag("tx-hash").Value.Set(invalidTxHash)
    70  	s.Nil(err)
    71  
    72  	err = ValidateSimulateFlags(
    73  		cmd,
    74  		[]string{},
    75  	)
    76  	s.NotNil(err)
    77  }