mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
* V2 truncate MaxMasternodes from candidates after penalty, V1 same as before TestUpdateMultipleMasterNodes: test V2, in snapshot we have all candidates, but at epoch switch, we pick MaxMasternodes * code looks better
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package engine_v2_tests
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
|
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
|
"github.com/XinFinOrg/XDPoSChain/params"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestShouldVerifyBlockInfo(t *testing.T) {
|
|
// Block 901 is the first v2 block with round of 1
|
|
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 901, params.TestXDPoSMockChainConfig, nil)
|
|
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
|
|
|
|
blockInfo := &types.BlockInfo{
|
|
Hash: currentBlock.Hash(),
|
|
Round: types.Round(1),
|
|
Number: currentBlock.Number(),
|
|
}
|
|
err := engineV2.VerifyBlockInfo(blockchain, blockInfo, nil)
|
|
assert.Nil(t, err)
|
|
|
|
// Insert another Block, but it won't trigger commit
|
|
blockNum := 902
|
|
blockCoinBase := fmt.Sprintf("0x111000000000000000000000000000000%03d", blockNum)
|
|
block902 := CreateBlock(blockchain, params.TestXDPoSMockChainConfig, currentBlock, blockNum, 2, blockCoinBase, signer, signFn, nil, nil, "")
|
|
err = blockchain.InsertBlock(block902)
|
|
assert.Nil(t, err)
|
|
|
|
blockInfo = &types.BlockInfo{
|
|
Hash: block902.Hash(),
|
|
Round: types.Round(2),
|
|
Number: block902.Number(),
|
|
}
|
|
err = engineV2.VerifyBlockInfo(blockchain, blockInfo, nil)
|
|
assert.Nil(t, err)
|
|
|
|
blockInfo = &types.BlockInfo{
|
|
Hash: currentBlock.Hash(),
|
|
Round: types.Round(2),
|
|
Number: currentBlock.Number(),
|
|
}
|
|
err = engineV2.VerifyBlockInfo(blockchain, blockInfo, nil)
|
|
assert.NotNil(t, err)
|
|
|
|
blockInfo = &types.BlockInfo{
|
|
Hash: block902.Hash(),
|
|
Round: types.Round(3),
|
|
Number: block902.Number(),
|
|
}
|
|
err = engineV2.VerifyBlockInfo(blockchain, blockInfo, nil)
|
|
assert.NotNil(t, err)
|
|
|
|
blockInfo = &types.BlockInfo{
|
|
Hash: block902.Hash(),
|
|
Round: types.Round(2),
|
|
Number: currentBlock.Number(),
|
|
}
|
|
err = engineV2.VerifyBlockInfo(blockchain, blockInfo, nil)
|
|
assert.NotNil(t, err)
|
|
}
|