Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename SanityCheck to BasicCheck #643

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func StartNode(workingDir string, passwordFetcher func(*wallet.Wallet) (string,
conf, _ = config.LoadFromFile(confPath, true) // This time it should be OK
}

err = conf.SanityCheck()
err = conf.BasicCheck()
if err != nil {
return nil, nil, err
}
Expand Down
24 changes: 12 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func DefaultNodeConfig() *NodeConfig {
}
}

// SanityCheck performs basic checks on the configuration.
func (conf *NodeConfig) SanityCheck() error {
// BasicCheck performs basic checks on the configuration.
func (conf *NodeConfig) BasicCheck() error {
if conf.NumValidators < 1 || conf.NumValidators > 32 {
return errors.Errorf(errors.ErrInvalidConfig, "number of validators must be between 1 and 32")
}
Expand Down Expand Up @@ -174,28 +174,28 @@ func LoadFromFile(file string, strict bool) (*Config, error) {
return conf, nil
}

// SanityCheck performs basic checks on the configuration.
func (conf *Config) SanityCheck() error {
if err := conf.Store.SanityCheck(); err != nil {
// BasicCheck performs basic checks on the configuration.
func (conf *Config) BasicCheck() error {
if err := conf.Store.BasicCheck(); err != nil {
return err
}
if err := conf.TxPool.SanityCheck(); err != nil {
if err := conf.TxPool.BasicCheck(); err != nil {
return err
}
if err := conf.Consensus.SanityCheck(); err != nil {
if err := conf.Consensus.BasicCheck(); err != nil {
return err
}
if err := conf.Network.SanityCheck(); err != nil {
if err := conf.Network.BasicCheck(); err != nil {
return err
}
if err := conf.Logger.SanityCheck(); err != nil {
if err := conf.Logger.BasicCheck(); err != nil {
return err
}
if err := conf.Sync.SanityCheck(); err != nil {
if err := conf.Sync.BasicCheck(); err != nil {
return err
}
if err := conf.Nanomsg.SanityCheck(); err != nil {
if err := conf.Nanomsg.BasicCheck(); err != nil {
return err
}
return conf.HTTP.SanityCheck()
return conf.HTTP.BasicCheck()
}
16 changes: 8 additions & 8 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestSaveMainnetConfig(t *testing.T) {
conf, err := LoadFromFile(path, true)
assert.NoError(t, err)

assert.NoError(t, conf.SanityCheck())
assert.NoError(t, conf.BasicCheck())
assert.Equal(t, conf.Network.Name, "pactus")
}

Expand All @@ -27,7 +27,7 @@ func TestSaveTestnetConfig(t *testing.T) {
conf, err := LoadFromFile(path, true)
assert.NoError(t, err)

assert.NoError(t, conf.SanityCheck())
assert.NoError(t, conf.BasicCheck())
assert.Equal(t, conf.Network.Name, "pactus-testnet")
}

Expand All @@ -38,7 +38,7 @@ func TestSaveLocalnetConfig(t *testing.T) {
conf, err := LoadFromFile(path, true)
assert.NoError(t, err)

assert.NoError(t, conf.SanityCheck())
assert.NoError(t, conf.BasicCheck())
assert.Equal(t, conf.Network.Name, "pactus-localnet")
assert.Empty(t, conf.Network.Listens)
assert.Empty(t, conf.Network.RelayAddrs)
Expand Down Expand Up @@ -84,14 +84,14 @@ func TestExampleConfig(t *testing.T) {
assert.Equal(t, defaultToml, exampleToml)
}

func TestNodeConfigSanityCheck(t *testing.T) {
func TestNodeConfigBasicCheck(t *testing.T) {
ts := testsuite.NewTestSuite(t)

t.Run("invalid number of validators", func(t *testing.T) {
conf := DefaultNodeConfig()
conf.NumValidators = 0

assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())
})

t.Run("invalid number of reward addresses", func(t *testing.T) {
Expand All @@ -100,7 +100,7 @@ func TestNodeConfigSanityCheck(t *testing.T) {
ts.RandomAddress().String(),
}

assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())
})

t.Run("invalid reward addresses", func(t *testing.T) {
Expand All @@ -111,7 +111,7 @@ func TestNodeConfigSanityCheck(t *testing.T) {
"abcd",
}

assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())
})

t.Run("ok", func(t *testing.T) {
Expand All @@ -122,6 +122,6 @@ func TestNodeConfigSanityCheck(t *testing.T) {
ts.RandomAddress().String(),
}

assert.NoError(t, conf.SanityCheck())
assert.NoError(t, conf.BasicCheck())
})
}
4 changes: 2 additions & 2 deletions consensus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func DefaultConfig() *Config {
}
}

// SanityCheck performs basic checks on the configuration.
func (conf *Config) SanityCheck() error {
// BasicCheck performs basic checks on the configuration.
func (conf *Config) BasicCheck() error {
if conf.ChangeProposerTimeout <= 0 {
return errors.Errorf(errors.ErrInvalidConfig, "timeout for change proposer can't be negative")
}
Expand Down
8 changes: 4 additions & 4 deletions consensus/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ func TestDefaultConfigCheck(t *testing.T) {
c2 := DefaultConfig()
c3 := DefaultConfig()
c4 := DefaultConfig()
assert.NoError(t, c1.SanityCheck())
assert.NoError(t, c1.BasicCheck())

c2.ChangeProposerDelta = 0 * time.Second
assert.Error(t, c2.SanityCheck())
assert.Error(t, c2.BasicCheck())

c3.ChangeProposerTimeout = 0 * time.Second
assert.Error(t, c3.SanityCheck())
assert.Error(t, c3.BasicCheck())

c4.ChangeProposerTimeout = -1 * time.Second
assert.Error(t, c4.SanityCheck())
assert.Error(t, c4.BasicCheck())
}

func TestCalculateChangeProposerTimeout(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions consensus/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ func TestByzantineVote2(t *testing.T) {
p := td.makeProposal(t, h, r)

// This simple trick prevents "DATA RACE" errors in this test
// by memoizing tx.sanityChecked.
assert.NoError(t, p.SanityCheck())
// by memoizing tx.basicChecked.
assert.NoError(t, p.BasicCheck())

wg := sync.WaitGroup{}
wg.Add(2)
Expand Down
2 changes: 1 addition & 1 deletion crypto/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (addr Address) String() string {
return str
}

func (addr *Address) SanityCheck() error {
func (addr *Address) BasicCheck() error {
if addr[0] == 0 {
if !addr.EqualsTo(TreasuryAddress) {
return errors.Errorf(errors.ErrInvalidAddress, "invalid address data")
Expand Down
4 changes: 2 additions & 2 deletions crypto/address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestToString(t *testing.T) {
}
}

func TestAddressSanityCheck(t *testing.T) {
func TestAddressBasicCheck(t *testing.T) {
tests := []struct {
errMsg string
hex string
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestAddressSanityCheck(t *testing.T) {
addr := crypto.Address{}
copy(addr[:], data)

err := addr.SanityCheck()
err := addr.BasicCheck()
if !test.invalid {
assert.NoError(t, err, "test %v unexpected error", no)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crypto/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h Hash) IsUndef() bool {
return h.EqualsTo(UndefHash)
}

func (h Hash) SanityCheck() error {
func (h Hash) BasicCheck() error {
if h.IsUndef() {
return fmt.Errorf("hash is zero")
}
Expand Down
6 changes: 3 additions & 3 deletions crypto/hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestHashFromString(t *testing.T) {

func TestHashEmpty(t *testing.T) {
h := hash.Hash{}
assert.Error(t, h.SanityCheck())
assert.Error(t, h.BasicCheck())

_, err := hash.FromBytes(nil)
assert.Error(t, err)
Expand All @@ -58,10 +58,10 @@ func TestHash160(t *testing.T) {
assert.Equal(t, h, expected)
}

func TestHashSanityCheck(t *testing.T) {
func TestHashBasicCheck(t *testing.T) {
h, err := hash.FromString("0000000000000000000000000000000000000000000000000000000000000000")
assert.NoError(t, err)
assert.True(t, h.IsUndef())
assert.Error(t, h.SanityCheck())
assert.Error(t, h.BasicCheck())
assert.Equal(t, hash.UndefHash.Bytes(), h.Bytes())
}
2 changes: 1 addition & 1 deletion execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewChecker() *Execution {
}

func (exe *Execution) Execute(trx *tx.Tx, sb sandbox.Sandbox) error {
if err := trx.SanityCheck(); err != nil {
if err := trx.BasicCheck(); err != nil {
return err
}
if trx.IsLockTime() {
Expand Down
4 changes: 2 additions & 2 deletions network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func validateAddresses(address []string) error {
return nil
}

// SanityCheck performs basic checks on the configuration.
func (conf *Config) SanityCheck() error {
// BasicCheck performs basic checks on the configuration.
func (conf *Config) BasicCheck() error {
if conf.EnableRelay {
if len(conf.RelayAddrs) == 0 {
return errors.Errorf(errors.ErrInvalidConfig, "at least one relay address should be defined")
Expand Down
14 changes: 7 additions & 7 deletions network/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ func TestDefaultConfigCheck(t *testing.T) {
conf := DefaultConfig()

conf.EnableRelay = true
assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())

conf.Listens = []string{""}
assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())

conf.Listens = []string{"127.0.0.1"}
assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())

conf.Listens = []string{"/ip4"}
assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())

conf.RelayAddrs = []string{"/ip4"}
assert.Error(t, conf.SanityCheck())
assert.Error(t, conf.BasicCheck())

conf.RelayAddrs = []string{}
conf.Listens = []string{}

conf.RelayAddrs = []string{"/ip4/127.0.0.1"}
assert.NoError(t, conf.SanityCheck())
assert.NoError(t, conf.BasicCheck())

conf.Listens = []string{"/ip4/127.0.0.1"}
assert.NoError(t, conf.SanityCheck())
assert.NoError(t, conf.BasicCheck())
}
4 changes: 2 additions & 2 deletions state/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func (st *state) validateBlock(block *block.Block) error {
if err := block.SanityCheck(); err != nil {
if err := block.BasicCheck(); err != nil {
return err
}

Expand All @@ -27,7 +27,7 @@ func (st *state) validateBlock(block *block.Block) error {
}

func (st *state) checkCertificate(blockHash hash.Hash, cert *block.Certificate) error {
if err := cert.SanityCheck(); err != nil {
if err := cert.BasicCheck(); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion state/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestBlockValidation(t *testing.T) {
// UnixTime (TestValidateBlockTime)
// PrevBlockHash (OK)
// StateRoot (OK)
// TxsRoot (SanityCheck)
// TxsRoot (BasicCheck)
// PrevCertificate (OK)
// SortitionSeed (OK)
// ProposerAddress (OK)
Expand Down
4 changes: 2 additions & 2 deletions store/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func (conf *Config) StorePath() string {
return fmt.Sprintf("%s%c%s", conf.DataPath(), os.PathSeparator, "store.db")
}

// SanityCheck performs basic checks on the configuration.
func (conf *Config) SanityCheck() error {
// BasicCheck performs basic checks on the configuration.
func (conf *Config) BasicCheck() error {
if !util.IsValidDirPath(conf.Path) {
return errors.Errorf(errors.ErrInvalidConfig, "path is not valid")
}
Expand Down
4 changes: 2 additions & 2 deletions store/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

func TestDefaultConfigCheck(t *testing.T) {
c := DefaultConfig()
assert.NoError(t, c.SanityCheck())
assert.NoError(t, c.BasicCheck())

if runtime.GOOS != "windows" {
c.Path = util.TempDirPath()
assert.NoError(t, c.SanityCheck())
assert.NoError(t, c.BasicCheck())
assert.Equal(t, c.StorePath(), c.Path+"/store.db")
}
}
4 changes: 2 additions & 2 deletions sync/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func NewBundle(initiator peer.ID, msg message.Message) *Bundle {
}
}

func (b *Bundle) SanityCheck() error {
if err := b.Message.SanityCheck(); err != nil {
func (b *Bundle) BasicCheck() error {
if err := b.Message.BasicCheck(); err != nil {
return err
}
if err := b.Initiator.Validate(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions sync/bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func TestMessageCompress(t *testing.T) {
assert.NoError(t, err)
_, err = msg3.Decode(bytes.NewReader(bs1))
assert.NoError(t, err)
assert.NoError(t, msg2.SanityCheck())
assert.NoError(t, msg3.SanityCheck())
assert.NoError(t, msg2.BasicCheck())
assert.NoError(t, msg3.BasicCheck())
assert.True(t, util.IsFlagSet(bdl.Flags, BundleFlagCompressed))
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func TestDecodeVoteCBOR(t *testing.T) {
assert.NoError(t, err)
_, err = m2.Decode(bytes.NewReader(d2))
assert.NoError(t, err)
assert.NoError(t, m2.SanityCheck())
assert.NoError(t, m2.BasicCheck())

assert.Equal(t, m1.Message, m2.Message)
}
6 changes: 3 additions & 3 deletions sync/bundle/message/block_announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ func NewBlockAnnounceMessage(h uint32, b *block.Block, c *block.Certificate) *Bl
}
}

func (m *BlockAnnounceMessage) SanityCheck() error {
if err := m.Block.SanityCheck(); err != nil {
func (m *BlockAnnounceMessage) BasicCheck() error {
if err := m.Block.BasicCheck(); err != nil {
return err
}
return m.Certificate.SanityCheck()
return m.Certificate.BasicCheck()
}

func (m *BlockAnnounceMessage) Type() Type {
Expand Down
4 changes: 2 additions & 2 deletions sync/bundle/message/block_announce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ func TestBlockAnnounceMessage(t *testing.T) {
c := block.NewCertificate(-1, nil, nil, nil)
m := NewBlockAnnounceMessage(100, b, c)

assert.Equal(t, errors.Code(m.SanityCheck()), errors.ErrInvalidRound)
assert.Equal(t, errors.Code(m.BasicCheck()), errors.ErrInvalidRound)
})

t.Run("OK", func(t *testing.T) {
b := ts.GenerateTestBlock(nil, nil)
c := ts.GenerateTestCertificate(b.Hash())
m := NewBlockAnnounceMessage(100, b, c)

assert.NoError(t, m.SanityCheck())
assert.NoError(t, m.BasicCheck())
assert.Contains(t, m.String(), "100")
})
}
Loading
Loading