Skip to content

Commit 94b9ce6

Browse files
authored
Improve vms/ tests with require (ava-labs#1505)
1 parent f458045 commit 94b9ce6

File tree

78 files changed

+1954
-3394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1954
-3394
lines changed

ids/aliases.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
var (
13-
errNoIDWithAlias = errors.New("there is no ID with alias")
13+
ErrNoIDWithAlias = errors.New("there is no ID with alias")
1414
errNoAliasForID = errors.New("there is no alias for ID")
1515
errAliasAlreadyMapped = errors.New("alias already mapped to an ID")
1616
)
@@ -68,7 +68,7 @@ func (a *aliaser) Lookup(alias string) (ID, error) {
6868
if id, ok := a.dealias[alias]; ok {
6969
return id, nil
7070
}
71-
return ID{}, fmt.Errorf("%w: %s", errNoIDWithAlias, alias)
71+
return ID{}, fmt.Errorf("%w: %s", ErrNoIDWithAlias, alias)
7272
}
7373

7474
func (a *aliaser) PrimaryAlias(id ID) (string, error) {

utils/formatting/address/address.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
const addressSep = "-"
1515

1616
var (
17-
errNoSeparator = errors.New("no separator found in address")
17+
ErrNoSeparator = errors.New("no separator found in address")
1818
errBits5To8 = errors.New("unable to convert address from 5-bit to 8-bit formatting")
1919
errBits8To5 = errors.New("unable to convert address from 8-bit to 5-bit formatting")
2020
)
@@ -25,7 +25,7 @@ var (
2525
func Parse(addrStr string) (string, string, []byte, error) {
2626
addressParts := strings.SplitN(addrStr, addressSep, 2)
2727
if len(addressParts) < 2 {
28-
return "", "", nil, errNoSeparator
28+
return "", "", nil, ErrNoSeparator
2929
}
3030
chainID := addressParts[0]
3131
rawAddr := addressParts[1]

vms/avm/blocks/builder/builder_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,12 @@ func TestBuilderBuildBlock(t *testing.T) {
487487

488488
for _, tt := range tests {
489489
t.Run(tt.name, func(t *testing.T) {
490-
require := require.New(t)
491490
ctrl := gomock.NewController(t)
492491
defer ctrl.Finish()
493492

494493
builder := tt.builderFunc(ctrl)
495494
_, err := builder.BuildBlock(context.Background())
496-
require.ErrorIs(err, tt.expectedErr)
495+
require.ErrorIs(t, err, tt.expectedErr)
497496
})
498497
}
499498
}
@@ -511,9 +510,7 @@ func TestBlockBuilderAddLocalTx(t *testing.T) {
511510
tx := transactions[0]
512511
txID := tx.ID()
513512
require.NoError(mempool.Add(tx))
514-
515-
has := mempool.Has(txID)
516-
require.True(has)
513+
require.True(mempool.Has(txID))
517514

518515
ctrl := gomock.NewController(t)
519516
defer ctrl.Finish()

vms/avm/fx_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package avm
66
import (
77
"errors"
88
"testing"
9+
10+
"github.com/stretchr/testify/require"
911
)
1012

1113
var (
@@ -48,7 +50,7 @@ func (fx *FxTest) Initialize(vm interface{}) error {
4850
return nil
4951
}
5052
if fx.T != nil {
51-
fx.T.Fatal(errCalledInitialize)
53+
require.FailNow(fx.T, errCalledInitialize.Error())
5254
}
5355
return errCalledInitialize
5456
}
@@ -61,7 +63,7 @@ func (fx *FxTest) Bootstrapping() error {
6163
return nil
6264
}
6365
if fx.T != nil {
64-
fx.T.Fatal(errCalledBootstrapping)
66+
require.FailNow(fx.T, errCalledBootstrapping.Error())
6567
}
6668
return errCalledBootstrapping
6769
}
@@ -74,7 +76,7 @@ func (fx *FxTest) Bootstrapped() error {
7476
return nil
7577
}
7678
if fx.T != nil {
77-
fx.T.Fatal(errCalledBootstrapped)
79+
require.FailNow(fx.T, errCalledBootstrapped.Error())
7880
}
7981
return errCalledBootstrapped
8082
}
@@ -87,7 +89,7 @@ func (fx *FxTest) VerifyTransfer(tx, in, cred, utxo interface{}) error {
8789
return nil
8890
}
8991
if fx.T != nil {
90-
fx.T.Fatal(errCalledVerifyTransfer)
92+
require.FailNow(fx.T, errCalledVerifyTransfer.Error())
9193
}
9294
return errCalledVerifyTransfer
9395
}
@@ -100,7 +102,7 @@ func (fx *FxTest) VerifyOperation(tx, op, cred interface{}, utxos []interface{})
100102
return nil
101103
}
102104
if fx.T != nil {
103-
fx.T.Fatal(errCalledVerifyOperation)
105+
require.FailNow(fx.T, errCalledVerifyOperation.Error())
104106
}
105107
return errCalledVerifyOperation
106108
}

0 commit comments

Comments
 (0)