mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 19:00:46 +00:00
move m2 for unit test
This commit is contained in:
parent
2d1eddf74f
commit
8000ce3c93
2 changed files with 12 additions and 9 deletions
|
|
@ -1149,7 +1149,7 @@ func getM1M2(masternodes []common.Address, validators []int64, currentHeader *ty
|
||||||
if maxMNs > 0 {
|
if maxMNs > 0 {
|
||||||
isForked := config.IsTIPRandomize(currentHeader.Number)
|
isForked := config.IsTIPRandomize(currentHeader.Number)
|
||||||
if isForked {
|
if isForked {
|
||||||
moveM2 = (currentHeader.Number.Uint64() % config.XDPoS.Epoch) / uint64(maxMNs)
|
moveM2 = ((currentHeader.Number.Uint64() % config.XDPoS.Epoch) / uint64(maxMNs)) % uint64(maxMNs)
|
||||||
}
|
}
|
||||||
for i, m1 := range masternodes {
|
for i, m1 := range masternodes {
|
||||||
m2Index := uint64(validators[i] % int64(maxMNs))
|
m2Index := uint64(validators[i] % int64(maxMNs))
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package XDPoS
|
package XDPoS
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"math/big"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
@ -21,27 +21,30 @@ func TestGetM1M2FromCheckpointHeader(t *testing.T) {
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
}
|
}
|
||||||
epoch := int64(900)
|
epoch := uint64(900)
|
||||||
config := ¶ms.ChainConfig{
|
config := ¶ms.ChainConfig{
|
||||||
XDPoS: ¶ms.XDPoSConfig{
|
XDPoS: ¶ms.XDPoSConfig{
|
||||||
Epoch: uint64(epoch),
|
Epoch: uint64(epoch),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
//try from block 900 to 909
|
//try from block 900 to 909
|
||||||
for i:=int64(0); i<9; i++ {
|
for i := uint64(3410001); i < 3411027; i++ {
|
||||||
|
currentNumber := int64(i)
|
||||||
currentHeader := &types.Header{
|
currentHeader := &types.Header{
|
||||||
Number: big.NewInt(epoch+i),
|
Number: big.NewInt(currentNumber),
|
||||||
}
|
}
|
||||||
m1m2, moveM2, err := getM1M2(masternodes, validators, currentHeader, config)
|
m1m2, moveM2, err := getM1M2(masternodes, validators, currentHeader, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("can't get m1m2", "err", err)
|
t.Error("can't get m1m2", "err", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("block: %v, moveM2: %v\n", currentHeader.Number.Int64(), moveM2)
|
fmt.Printf("block: %v, moveM2: %v\n", currentHeader.Number.Int64(), moveM2)
|
||||||
for _,k := range masternodes {
|
for _, k := range masternodes {
|
||||||
fmt.Printf("m1: %v - m2: %v\n", k.Str(), m1m2[k].Str())
|
fmt.Printf("m1: %v - m2: %v\n", k.Str(), m1m2[k].Str())
|
||||||
}
|
}
|
||||||
if moveM2 != uint64(i/3) { //3 = len(masternodes)
|
maxMNs := len(masternodes)
|
||||||
t.Error("wrong moveM2", "want", uint64(i/3), "have", moveM2)
|
testMoveM2 := ((uint64(currentNumber) % config.XDPoS.Epoch) / uint64(maxMNs)) % uint64(maxMNs)
|
||||||
|
if moveM2 != testMoveM2 { //3 = len(masternodes)
|
||||||
|
t.Error("wrong moveM2", "currentNumber", currentNumber, "want", testMoveM2, "have", moveM2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue