Skip to content
Open
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 vm/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (block *Block) Accept(context.Context) error {
func (block *Block) Reject(context.Context) error {
block.vm.log.Debug("try to reject block", "block", block.ID())
block.st = choices.Rejected
panic("implement me")
return nil
}

// Status returns this element's current status.
Expand Down
58 changes: 56 additions & 2 deletions vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"context"
_ "embed"
"fmt"
"github.com/consideritdone/landslidecore/abci/example/kvstore"
rpctypes "github.com/consideritdone/landslidecore/rpc/jsonrpc/types"
"github.com/consideritdone/landslidecore/types"
"os"
"reflect"
"testing"

"github.com/consideritdone/landslidecore/abci/example/kvstore"

"github.com/ava-labs/avalanchego/database/manager"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
Expand Down Expand Up @@ -152,3 +154,55 @@ func TestInitVm(t *testing.T) {
t.Logf("Block: %d", blk2.Height())
t.Logf("TM Block Tx count: %d", len(tmBlk2.Data.Txs))
}

func TestRejectBlock(t *testing.T) {
tx1 := []byte{0x01}
tx2 := []byte{0x02}
tx3 := []byte{0x03}
txs := []types.Tx{tx1, tx2, tx3}
vm, service, _ := mustNewKVTestVm(t)

blk0, err := vm.BuildBlock(context.Background())
assert.ErrorIs(t, err, errNoPendingTxs, "expecting error no txs")
assert.Nil(t, blk0)

for _, tx := range txs {
txReply, err := service.BroadcastTxSync(&rpctypes.Context{}, tx)
assert.NoError(t, err)
assert.Equal(t, atypes.CodeTypeOK, txReply.Code)
}

// build 1st block
blk1, err := vm.BuildBlock(context.Background())
assert.NoError(t, err)
assert.NotNil(t, blk1)
assert.NoError(t, blk1.Reject(context.Background()))
height1 := int64(blk1.Height())

// build 1st block
blk2, err := vm.BuildBlock(context.Background())
assert.NoError(t, err)
assert.NotNil(t, blk1)
assert.NoError(t, blk1.Accept(context.Background()))
height2 := int64(blk2.Height())

assert.Equal(t, height1, height2)

reply, err := service.Block(&rpctypes.Context{}, &height2)
assert.NoError(t, err)
if assert.NotNil(t, reply.Block) {
assert.EqualValues(t, height2, reply.Block.Height)
}
assert.EqualValues(t, height2, reply.Block.Height)
assert.EqualValues(t, len(txs), len(reply.Block.Txs))
for _, tx := range txs {
match := false
for _, blkTx := range reply.Block.Txs {
if reflect.DeepEqual(tx, blkTx) {
match = true
break
}
}
require.True(t, match)
}
}