|
|
@ -7,9 +7,12 @@ import ( |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/harmony-one/harmony/consensus" |
|
|
|
"github.com/harmony-one/harmony/consensus" |
|
|
|
"github.com/harmony-one/harmony/consensus/quorum" |
|
|
|
"github.com/harmony-one/harmony/consensus/quorum" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/core" |
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
"github.com/harmony-one/harmony/crypto/bls" |
|
|
|
"github.com/harmony-one/harmony/crypto/bls" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/chain" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/shardchain" |
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
"github.com/harmony-one/harmony/multibls" |
|
|
|
"github.com/harmony-one/harmony/multibls" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
@ -29,17 +32,22 @@ func TestAddNewBlock(t *testing.T) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("newhost failure: %v", err) |
|
|
|
t.Fatalf("newhost failure: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
engine := chain.NewEngine() |
|
|
|
|
|
|
|
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() |
|
|
|
|
|
|
|
collection := shardchain.NewCollection( |
|
|
|
|
|
|
|
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, |
|
|
|
|
|
|
|
) |
|
|
|
decider := quorum.NewDecider( |
|
|
|
decider := quorum.NewDecider( |
|
|
|
quorum.SuperMajorityVote, shard.BeaconChainShardID, |
|
|
|
quorum.SuperMajorityVote, shard.BeaconChainShardID, |
|
|
|
) |
|
|
|
) |
|
|
|
consensus, err := consensus.New( |
|
|
|
consensus, err := consensus.New( |
|
|
|
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsKey), decider, |
|
|
|
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsKey), nil, decider, 3, false, |
|
|
|
) |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Cannot craeate consensus: %v", err) |
|
|
|
t.Fatalf("Cannot craeate consensus: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
nodeconfig.SetNetworkType(nodeconfig.Devnet) |
|
|
|
nodeconfig.SetNetworkType(nodeconfig.Devnet) |
|
|
|
node := New(host, consensus, testDBFactory, nil, nil, nil, nil, nil) |
|
|
|
node := New(host, consensus, engine, collection, nil, nil, nil, nil, nil) |
|
|
|
|
|
|
|
|
|
|
|
txs := make(map[common.Address]types.Transactions) |
|
|
|
txs := make(map[common.Address]types.Transactions) |
|
|
|
stks := staking.StakingTransactions{} |
|
|
|
stks := staking.StakingTransactions{} |
|
|
@ -76,11 +84,16 @@ func TestVerifyNewBlock(t *testing.T) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("newhost failure: %v", err) |
|
|
|
t.Fatalf("newhost failure: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
engine := chain.NewEngine() |
|
|
|
|
|
|
|
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() |
|
|
|
|
|
|
|
collection := shardchain.NewCollection( |
|
|
|
|
|
|
|
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, |
|
|
|
|
|
|
|
) |
|
|
|
decider := quorum.NewDecider( |
|
|
|
decider := quorum.NewDecider( |
|
|
|
quorum.SuperMajorityVote, shard.BeaconChainShardID, |
|
|
|
quorum.SuperMajorityVote, shard.BeaconChainShardID, |
|
|
|
) |
|
|
|
) |
|
|
|
consensus, err := consensus.New( |
|
|
|
consensus, err := consensus.New( |
|
|
|
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsKey), decider, |
|
|
|
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsKey), nil, decider, 3, false, |
|
|
|
) |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Cannot craeate consensus: %v", err) |
|
|
|
t.Fatalf("Cannot craeate consensus: %v", err) |
|
|
@ -88,7 +101,7 @@ func TestVerifyNewBlock(t *testing.T) { |
|
|
|
archiveMode := make(map[uint32]bool) |
|
|
|
archiveMode := make(map[uint32]bool) |
|
|
|
archiveMode[0] = true |
|
|
|
archiveMode[0] = true |
|
|
|
archiveMode[1] = false |
|
|
|
archiveMode[1] = false |
|
|
|
node := New(host, consensus, testDBFactory, nil, nil, nil, archiveMode, nil) |
|
|
|
node := New(host, consensus, engine, collection, nil, nil, nil, archiveMode, nil) |
|
|
|
|
|
|
|
|
|
|
|
txs := make(map[common.Address]types.Transactions) |
|
|
|
txs := make(map[common.Address]types.Transactions) |
|
|
|
stks := staking.StakingTransactions{} |
|
|
|
stks := staking.StakingTransactions{} |
|
|
@ -105,7 +118,7 @@ func TestVerifyNewBlock(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
// work around vrf verification as it's tested in another test.
|
|
|
|
// work around vrf verification as it's tested in another test.
|
|
|
|
node.Blockchain().Config().VRFEpoch = big.NewInt(2) |
|
|
|
node.Blockchain().Config().VRFEpoch = big.NewInt(2) |
|
|
|
if err := node.VerifyNewBlock(block); err != nil { |
|
|
|
if err := VerifyNewBlock(nil, node.Blockchain(), node.Beaconchain())(block); err != nil { |
|
|
|
t.Error("New block is not verified successfully:", err) |
|
|
|
t.Error("New block is not verified successfully:", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -122,11 +135,20 @@ func TestVerifyVRF(t *testing.T) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("newhost failure: %v", err) |
|
|
|
t.Fatalf("newhost failure: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
engine := chain.NewEngine() |
|
|
|
|
|
|
|
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() |
|
|
|
|
|
|
|
collection := shardchain.NewCollection( |
|
|
|
|
|
|
|
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
blockchain, err := collection.ShardChain(shard.BeaconChainShardID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatal("cannot get blockchain") |
|
|
|
|
|
|
|
} |
|
|
|
decider := quorum.NewDecider( |
|
|
|
decider := quorum.NewDecider( |
|
|
|
quorum.SuperMajorityVote, shard.BeaconChainShardID, |
|
|
|
quorum.SuperMajorityVote, shard.BeaconChainShardID, |
|
|
|
) |
|
|
|
) |
|
|
|
consensus, err := consensus.New( |
|
|
|
consensus, err := consensus.New( |
|
|
|
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsKey), decider, |
|
|
|
host, shard.BeaconChainShardID, multibls.GetPrivateKeys(blsKey), blockchain, decider, 3, false, |
|
|
|
) |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Cannot craeate consensus: %v", err) |
|
|
|
t.Fatalf("Cannot craeate consensus: %v", err) |
|
|
@ -134,9 +156,8 @@ func TestVerifyVRF(t *testing.T) { |
|
|
|
archiveMode := make(map[uint32]bool) |
|
|
|
archiveMode := make(map[uint32]bool) |
|
|
|
archiveMode[0] = true |
|
|
|
archiveMode[0] = true |
|
|
|
archiveMode[1] = false |
|
|
|
archiveMode[1] = false |
|
|
|
node := New(host, consensus, testDBFactory, nil, nil, nil, archiveMode, nil) |
|
|
|
node := New(host, consensus, engine, collection, nil, nil, nil, archiveMode, nil) |
|
|
|
|
|
|
|
|
|
|
|
consensus.Blockchain = node.Blockchain() |
|
|
|
|
|
|
|
txs := make(map[common.Address]types.Transactions) |
|
|
|
txs := make(map[common.Address]types.Transactions) |
|
|
|
stks := staking.StakingTransactions{} |
|
|
|
stks := staking.StakingTransactions{} |
|
|
|
node.Worker.CommitTransactions( |
|
|
|
node.Worker.CommitTransactions( |
|
|
|