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

use require.IsType for type assertions in tests #1458

Merged
merged 20 commits into from
May 3, 2023
Prev Previous commit
Next Next commit
reduce diff
  • Loading branch information
dhrubabasu committed May 3, 2023
commit e7410709ebed575f5cbe0f13d85907b78e984b2c
7 changes: 6 additions & 1 deletion snow/engine/avalanche/getter/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func TestAcceptedFrontier(t *testing.T) {
vtxID2 := ids.GenerateTestID()

bsIntf, err := New(manager, config)
if err != nil {
t.Fatal(err)
}
require.IsType(&getter{}, bsIntf)
bs := bsIntf.(*getter)

Expand Down Expand Up @@ -127,7 +130,9 @@ func TestFilterAccepted(t *testing.T) {
}}

bsIntf, err := New(manager, config)
require.NoError(err)
if err != nil {
t.Fatal(err)
}
require.IsType(&getter{}, bsIntf)
bs := bsIntf.(*getter)

Expand Down
4 changes: 1 addition & 3 deletions vms/platformvm/blocks/executor/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ func TestGetBlock(t *testing.T) {
}

func TestManagerLastAccepted(t *testing.T) {
require := require.New(t)

lastAcceptedID := ids.GenerateTestID()
manager := &manager{
backend: &backend{
lastAccepted: lastAcceptedID,
},
}

require.Equal(lastAcceptedID, manager.LastAccepted())
require.Equal(t, lastAcceptedID, manager.LastAccepted())
}
6 changes: 6 additions & 0 deletions vms/platformvm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ func TestGetTx(t *testing.T) {

commit := options[0].(*blockexecutor.Block)
require.IsType(&blocks.BanffCommitBlock{}, commit.Block)

err := commit.Verify(context.Background())
require.NoError(err)

err = commit.Accept(context.Background())
require.NoError(err)
}
}

Expand Down
9 changes: 9 additions & 0 deletions vms/proposervm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,16 @@ func TestPreFork_ParseBlock(t *testing.T) {
}

parsedBlk, err := proVM.ParseBlock(context.Background(), coreBlk.Bytes())
if err != nil {
t.Fatal("Could not parse naked core block")
}
require.IsType(&preForkBlock{}, parsedBlk)
if parsedBlk.ID() != coreBlk.ID() {
t.Fatal("Parsed block does not match expected block")
}
if !bytes.Equal(parsedBlk.Bytes(), coreBlk.Bytes()) {
t.Fatal("Parsed block does not match expected block")
}

coreVM.GetBlockF = func(_ context.Context, id ids.ID) (snowman.Block, error) {
if id != coreBlk.ID() {
Expand Down