go-ethereum/consensus/tests/sync_info_test.go
Liam 5a3acd173d
Xin-124 Deal with Block Time mine time (#55)
* add wait v2 period in miner

* add perido initial

* add mine and wait time

* update todo

* merge all xdc test config into 1
2022-02-13 11:40:47 +11:00

72 lines
2.3 KiB
Go

package tests
import (
"math/big"
"testing"
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
"github.com/XinFinOrg/XDPoSChain/params"
"github.com/stretchr/testify/assert"
)
func TestSyncInfoShouldSuccessfullyUpdateByQC(t *testing.T) {
// Block 901 is the first v2 block with starting round of 0
blockchain, _, currentBlock, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, 0)
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
var extraField utils.ExtraFields_v2
err := utils.DecodeBytesExtraFields(currentBlock.Extra(), &extraField)
if err != nil {
t.Fatal("Fail to decode extra data", err)
}
syncInfoMsg := &utils.SyncInfo{
HighestQuorumCert: extraField.QuorumCert,
HighestTimeoutCert: &utils.TimeoutCert{
Round: utils.Round(2),
Signatures: []utils.Signature{},
},
}
err = engineV2.SyncInfoHandler(blockchain, syncInfoMsg)
if err != nil {
t.Fatal(err)
}
round, _, highestQuorumCert, _, highestCommitBlock := engineV2.GetProperties()
// QC is parent block's qc, which is pointing at round 4, hence 4 + 1 = 5
assert.Equal(t, utils.Round(5), round)
assert.Equal(t, extraField.QuorumCert, highestQuorumCert)
assert.Equal(t, utils.Round(2), highestCommitBlock.Round)
assert.Equal(t, big.NewInt(902), highestCommitBlock.Number)
}
func TestSyncInfoShouldSuccessfullyUpdateByTC(t *testing.T) {
// Block 901 is the first v2 block with starting round of 0
blockchain, _, currentBlock, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, 0)
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
var extraField utils.ExtraFields_v2
err := utils.DecodeBytesExtraFields(currentBlock.Extra(), &extraField)
if err != nil {
t.Fatal("Fail to decode extra data", err)
}
highestTC := &utils.TimeoutCert{
Round: utils.Round(6),
Signatures: []utils.Signature{},
}
syncInfoMsg := &utils.SyncInfo{
HighestQuorumCert: extraField.QuorumCert,
HighestTimeoutCert: highestTC,
}
err = engineV2.SyncInfoHandler(blockchain, syncInfoMsg)
if err != nil {
t.Fatal(err)
}
round, _, highestQuorumCert, _, _ := engineV2.GetProperties()
assert.Equal(t, utils.Round(7), round)
assert.Equal(t, extraField.QuorumCert, highestQuorumCert)
}