Skip to content

Commit

Permalink
Improve vms/ tests with require (ava-labs#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Jun 15, 2023
1 parent f458045 commit 94b9ce6
Show file tree
Hide file tree
Showing 78 changed files with 1,954 additions and 3,394 deletions.
4 changes: 2 additions & 2 deletions ids/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var (
errNoIDWithAlias = errors.New("there is no ID with alias")
ErrNoIDWithAlias = errors.New("there is no ID with alias")
errNoAliasForID = errors.New("there is no alias for ID")
errAliasAlreadyMapped = errors.New("alias already mapped to an ID")
)
Expand Down Expand Up @@ -68,7 +68,7 @@ func (a *aliaser) Lookup(alias string) (ID, error) {
if id, ok := a.dealias[alias]; ok {
return id, nil
}
return ID{}, fmt.Errorf("%w: %s", errNoIDWithAlias, alias)
return ID{}, fmt.Errorf("%w: %s", ErrNoIDWithAlias, alias)
}

func (a *aliaser) PrimaryAlias(id ID) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions utils/formatting/address/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
const addressSep = "-"

var (
errNoSeparator = errors.New("no separator found in address")
ErrNoSeparator = errors.New("no separator found in address")
errBits5To8 = errors.New("unable to convert address from 5-bit to 8-bit formatting")
errBits8To5 = errors.New("unable to convert address from 8-bit to 5-bit formatting")
)
Expand All @@ -25,7 +25,7 @@ var (
func Parse(addrStr string) (string, string, []byte, error) {
addressParts := strings.SplitN(addrStr, addressSep, 2)
if len(addressParts) < 2 {
return "", "", nil, errNoSeparator
return "", "", nil, ErrNoSeparator
}
chainID := addressParts[0]
rawAddr := addressParts[1]
Expand Down
7 changes: 2 additions & 5 deletions vms/avm/blocks/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,12 @@ func TestBuilderBuildBlock(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()

builder := tt.builderFunc(ctrl)
_, err := builder.BuildBlock(context.Background())
require.ErrorIs(err, tt.expectedErr)
require.ErrorIs(t, err, tt.expectedErr)
})
}
}
Expand All @@ -511,9 +510,7 @@ func TestBlockBuilderAddLocalTx(t *testing.T) {
tx := transactions[0]
txID := tx.ID()
require.NoError(mempool.Add(tx))

has := mempool.Has(txID)
require.True(has)
require.True(mempool.Has(txID))

ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down
12 changes: 7 additions & 5 deletions vms/avm/fx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package avm
import (
"errors"
"testing"

"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -48,7 +50,7 @@ func (fx *FxTest) Initialize(vm interface{}) error {
return nil
}
if fx.T != nil {
fx.T.Fatal(errCalledInitialize)
require.FailNow(fx.T, errCalledInitialize.Error())
}
return errCalledInitialize
}
Expand All @@ -61,7 +63,7 @@ func (fx *FxTest) Bootstrapping() error {
return nil
}
if fx.T != nil {
fx.T.Fatal(errCalledBootstrapping)
require.FailNow(fx.T, errCalledBootstrapping.Error())
}
return errCalledBootstrapping
}
Expand All @@ -74,7 +76,7 @@ func (fx *FxTest) Bootstrapped() error {
return nil
}
if fx.T != nil {
fx.T.Fatal(errCalledBootstrapped)
require.FailNow(fx.T, errCalledBootstrapped.Error())
}
return errCalledBootstrapped
}
Expand All @@ -87,7 +89,7 @@ func (fx *FxTest) VerifyTransfer(tx, in, cred, utxo interface{}) error {
return nil
}
if fx.T != nil {
fx.T.Fatal(errCalledVerifyTransfer)
require.FailNow(fx.T, errCalledVerifyTransfer.Error())
}
return errCalledVerifyTransfer
}
Expand All @@ -100,7 +102,7 @@ func (fx *FxTest) VerifyOperation(tx, op, cred interface{}, utxos []interface{})
return nil
}
if fx.T != nil {
fx.T.Fatal(errCalledVerifyOperation)
require.FailNow(fx.T, errCalledVerifyOperation.Error())
}
return errCalledVerifyOperation
}
Loading

0 comments on commit 94b9ce6

Please sign in to comment.