2020-03-04 09:49:59 -08:00
|
|
|
package types_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2020-09-28 03:46:49 -07:00
|
|
|
"github.com/stretchr/testify/suite"
|
2020-03-04 09:49:59 -08:00
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
2020-09-28 03:46:49 -07:00
|
|
|
type configTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(configTestSuite))
|
|
|
|
}
|
|
|
|
|
2021-02-22 07:14:09 -08:00
|
|
|
func (s *contextTestSuite) TestConfig_SetPurpose() {
|
|
|
|
config := sdk.NewConfig()
|
|
|
|
config.SetPurpose(44)
|
|
|
|
s.Require().Equal(uint32(44), config.GetPurpose())
|
|
|
|
|
|
|
|
config.SetPurpose(0)
|
|
|
|
s.Require().Equal(uint32(0), config.GetPurpose())
|
|
|
|
|
|
|
|
config.Seal()
|
|
|
|
s.Require().Panics(func() { config.SetPurpose(10) })
|
|
|
|
}
|
|
|
|
|
2020-09-28 03:46:49 -07:00
|
|
|
func (s *configTestSuite) TestConfig_SetCoinType() {
|
2020-05-08 01:30:55 -07:00
|
|
|
config := sdk.NewConfig()
|
|
|
|
config.SetCoinType(1)
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Equal(uint32(1), config.GetCoinType())
|
2020-03-04 09:49:59 -08:00
|
|
|
config.SetCoinType(99)
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Equal(uint32(99), config.GetCoinType())
|
2020-03-04 09:49:59 -08:00
|
|
|
|
|
|
|
config.Seal()
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Panics(func() { config.SetCoinType(99) })
|
2020-03-04 09:49:59 -08:00
|
|
|
}
|
|
|
|
|
2020-09-28 03:46:49 -07:00
|
|
|
func (s *configTestSuite) TestConfig_SetTxEncoder() {
|
2020-03-04 09:49:59 -08:00
|
|
|
mockErr := errors.New("test")
|
2020-05-08 01:30:55 -07:00
|
|
|
config := sdk.NewConfig()
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Nil(config.GetTxEncoder())
|
2020-03-04 09:49:59 -08:00
|
|
|
encFunc := sdk.TxEncoder(func(tx sdk.Tx) ([]byte, error) { return nil, nil })
|
|
|
|
config.SetTxEncoder(encFunc)
|
|
|
|
_, err := config.GetTxEncoder()(sdk.Tx(nil))
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Error(mockErr, err)
|
2020-03-04 09:49:59 -08:00
|
|
|
|
|
|
|
config.Seal()
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Panics(func() { config.SetTxEncoder(encFunc) })
|
2020-03-04 09:49:59 -08:00
|
|
|
}
|
|
|
|
|
2020-09-28 03:46:49 -07:00
|
|
|
func (s *configTestSuite) TestConfig_SetFullFundraiserPath() {
|
2020-05-08 01:30:55 -07:00
|
|
|
config := sdk.NewConfig()
|
2020-03-04 09:49:59 -08:00
|
|
|
config.SetFullFundraiserPath("test/path")
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Equal("test/path", config.GetFullFundraiserPath())
|
2020-03-04 09:49:59 -08:00
|
|
|
|
2020-05-08 01:30:55 -07:00
|
|
|
config.SetFullFundraiserPath("test/poth")
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Equal("test/poth", config.GetFullFundraiserPath())
|
2020-05-08 01:30:55 -07:00
|
|
|
|
2020-03-04 09:49:59 -08:00
|
|
|
config.Seal()
|
2020-09-28 03:46:49 -07:00
|
|
|
s.Require().Panics(func() { config.SetFullFundraiserPath("x/test/path") })
|
2020-03-04 09:49:59 -08:00
|
|
|
}
|
|
|
|
|
2020-09-28 03:46:49 -07:00
|
|
|
func (s *configTestSuite) TestKeyringServiceName() {
|
|
|
|
s.Require().Equal(sdk.DefaultKeyringServiceName, sdk.KeyringServiceName())
|
2020-03-04 09:49:59 -08:00
|
|
|
}
|