mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Merge pull request #478 from dinhln89/random
Fixed unit test for moveM2.
This commit is contained in:
commit
f2f5aacb88
2 changed files with 12 additions and 10 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.Posv.Epoch) / uint64(maxMNs)
|
moveM2 = ((currentHeader.Number.Uint64() % config.Posv.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 posv
|
package posv
|
||||||
|
|
||||||
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,16 +21,18 @@ func TestGetM1M2FromCheckpointHeader(t *testing.T) {
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
}
|
}
|
||||||
epoch := int64(900)
|
epoch := uint64(900)
|
||||||
config := ¶ms.ChainConfig{
|
config := ¶ms.ChainConfig{
|
||||||
Posv: ¶ms.PosvConfig{
|
Posv: ¶ms.PosvConfig{
|
||||||
Epoch: uint64(epoch),
|
Epoch: uint64(epoch),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
//try from block 900 to 909
|
testMoveM2 := []uint64{0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2}
|
||||||
for i:=int64(0); i<9; i++ {
|
//try from block 3410001 to 3410018
|
||||||
|
for i := uint64(3410001); i <= 3410018; 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 {
|
||||||
|
|
@ -40,8 +42,8 @@ func TestGetM1M2FromCheckpointHeader(t *testing.T) {
|
||||||
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)
|
if moveM2 != testMoveM2[i-3410001] {
|
||||||
t.Error("wrong moveM2", "want", uint64(i/3), "have", moveM2)
|
t.Error("wrong moveM2", "currentNumber", currentNumber, "want", testMoveM2, "have", moveM2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue