mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 06:53:46 +00:00
new: add cases
This commit is contained in:
parent
09e62ca35c
commit
4e7cf125ae
1 changed files with 106 additions and 62 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -15,6 +16,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/fdlimit"
|
"github.com/ethereum/go-ethereum/common/fdlimit"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
|
|
@ -299,6 +301,27 @@ func TestValidatorWentOffline(t *testing.T) {
|
||||||
|
|
||||||
// TODO: Need to find a better name
|
// TODO: Need to find a better name
|
||||||
func TestForkWithTwoNodeNet(t *testing.T) {
|
func TestForkWithTwoNodeNet(t *testing.T) {
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
sprint uint64
|
||||||
|
blockTime map[string]uint64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
sprint: 128,
|
||||||
|
blockTime: map[string]uint64{
|
||||||
|
"0": 5,
|
||||||
|
"128": 2,
|
||||||
|
"256": 8,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sprint: 64,
|
||||||
|
blockTime: map[string]uint64{
|
||||||
|
"0": 5,
|
||||||
|
"64": 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stderr, log.TerminalFormat(true))))
|
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StreamHandler(os.Stderr, log.TerminalFormat(true))))
|
||||||
fdlimit.Raise(2048)
|
fdlimit.Raise(2048)
|
||||||
|
|
||||||
|
|
@ -309,7 +332,11 @@ func TestForkWithTwoNodeNet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an Ethash network based off of the Ropsten config
|
// Create an Ethash network based off of the Ropsten config
|
||||||
genesis := initGenesis2(t, faucets)
|
genesis := initGenesis(t, faucets)
|
||||||
|
|
||||||
|
for _, test := range cases {
|
||||||
|
genesis.Config.Bor.Sprint = test.sprint
|
||||||
|
genesis.Config.Bor.Period = test.blockTime
|
||||||
|
|
||||||
var (
|
var (
|
||||||
stacks []*node.Node
|
stacks []*node.Node
|
||||||
|
|
@ -346,11 +373,28 @@ func TestForkWithTwoNodeNet(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(700 * time.Second)
|
var wg sync.WaitGroup
|
||||||
|
blockHeaders := make([]*types.Header, 2)
|
||||||
|
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
|
go func(i int) {
|
||||||
|
defer wg.Done()
|
||||||
|
for {
|
||||||
|
blockHeaders[i] = nodes[i].BlockChain().GetHeaderByNumber(test.sprint + 1)
|
||||||
|
if blockHeaders[i] != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
// Before the end of sprint
|
// Before the end of sprint
|
||||||
blockHeaderVal0 := nodes[0].BlockChain().GetHeaderByNumber(120)
|
blockHeaderVal0 := nodes[0].BlockChain().GetHeaderByNumber(test.sprint - 1)
|
||||||
blockHeaderVal1 := nodes[1].BlockChain().GetHeaderByNumber(120)
|
blockHeaderVal1 := nodes[1].BlockChain().GetHeaderByNumber(test.sprint - 1)
|
||||||
assert.Equal(t, blockHeaderVal0.Hash(), blockHeaderVal1.Hash())
|
assert.Equal(t, blockHeaderVal0.Hash(), blockHeaderVal1.Hash())
|
||||||
assert.Equal(t, blockHeaderVal0.Time, blockHeaderVal1.Time)
|
assert.Equal(t, blockHeaderVal0.Time, blockHeaderVal1.Time)
|
||||||
|
|
||||||
|
|
@ -366,19 +410,19 @@ func TestForkWithTwoNodeNet(t *testing.T) {
|
||||||
|
|
||||||
// After the end of sprint
|
// After the end of sprint
|
||||||
// FIXME: POS-845
|
// FIXME: POS-845
|
||||||
blockHeaderVal2 := nodes[0].BlockChain().GetHeaderByNumber(130)
|
assert.NotEqual(t, blockHeaders[0].Hash(), blockHeaders[1].Hash())
|
||||||
blockHeaderVal3 := nodes[1].BlockChain().GetHeaderByNumber(130)
|
assert.NotEqual(t, blockHeaders[0].Time, blockHeaders[1].Time)
|
||||||
assert.NotEqual(t, blockHeaderVal2.Hash(), blockHeaderVal3.Hash())
|
|
||||||
assert.NotEqual(t, blockHeaderVal2.Time, blockHeaderVal3.Time)
|
|
||||||
|
|
||||||
author2, err := nodes[0].Engine().Author(blockHeaderVal2)
|
author2, err := nodes[0].Engine().Author(blockHeaders[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error occured while fetching author", "err", err)
|
log.Error("Error occured while fetching author", "err", err)
|
||||||
}
|
}
|
||||||
author3, err := nodes[1].Engine().Author(blockHeaderVal3)
|
author3, err := nodes[1].Engine().Author(blockHeaders[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error occured while fetching author", "err", err)
|
log.Error("Error occured while fetching author", "err", err)
|
||||||
}
|
}
|
||||||
assert.NotEqual(t, author2, author3)
|
assert.NotEqual(t, author2, author3)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue