You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.1 KiB
76 lines
2.1 KiB
package node
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/harmony-one/harmony/internal/shardchain"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/harmony-one/harmony/consensus"
|
|
"github.com/harmony-one/harmony/consensus/quorum"
|
|
"github.com/harmony-one/harmony/core/types"
|
|
"github.com/harmony-one/harmony/crypto/bls"
|
|
"github.com/harmony-one/harmony/internal/utils"
|
|
"github.com/harmony-one/harmony/multibls"
|
|
"github.com/harmony-one/harmony/p2p"
|
|
"github.com/harmony-one/harmony/shard"
|
|
staking "github.com/harmony-one/harmony/staking/types"
|
|
)
|
|
|
|
func TestFinalizeNewBlockAsync(t *testing.T) {
|
|
blsKey := bls.RandPrivateKey()
|
|
pubKey := blsKey.GetPublicKey()
|
|
leader := p2p.Peer{IP: "127.0.0.1", Port: "8882", ConsensusPubKey: pubKey}
|
|
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
|
|
host, err := p2p.NewHost(p2p.HostConfig{
|
|
Self: &leader,
|
|
BLSKey: priKey,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("newhost failure: %v", err)
|
|
}
|
|
decider := quorum.NewDecider(
|
|
quorum.SuperMajorityVote, shard.BeaconChainShardID,
|
|
)
|
|
consensus, err := consensus.New(
|
|
host, shard.BeaconChainShardID, leader, multibls.GetPrivateKeys(blsKey), decider,
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("Cannot craeate consensus: %v", err)
|
|
}
|
|
var testDBFactory = &shardchain.MemDBFactory{}
|
|
node := New(host, consensus, testDBFactory, nil, nil, nil, nil, nil)
|
|
|
|
node.Worker.UpdateCurrent()
|
|
|
|
txs := make(map[common.Address]types.Transactions)
|
|
stks := staking.StakingTransactions{}
|
|
node.Worker.CommitTransactions(
|
|
txs, stks, common.Address{},
|
|
)
|
|
commitSigs := make(chan []byte)
|
|
go func() {
|
|
commitSigs <- []byte{}
|
|
}()
|
|
|
|
block, _ := node.Worker.FinalizeNewBlock(
|
|
commitSigs, func() uint64 { return 0 }, common.Address{}, nil, nil,
|
|
)
|
|
|
|
if err := node.VerifyNewBlock(block); err != nil {
|
|
t.Error("New block is not verified successfully:", err)
|
|
}
|
|
|
|
node.Blockchain().InsertChain(types.Blocks{block}, false)
|
|
|
|
node.Worker.UpdateCurrent()
|
|
|
|
_, err = node.Worker.FinalizeNewBlock(
|
|
commitSigs, func() uint64 { return 0 }, common.Address{}, nil, nil,
|
|
)
|
|
|
|
if !strings.Contains(err.Error(), "cannot finalize block") {
|
|
t.Error("expect timeout on FinalizeNewBlock")
|
|
}
|
|
}
|
|
|