mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 15:33:47 +00:00
refactor tests
This commit is contained in:
parent
9f85e71935
commit
7e635edf23
3 changed files with 87 additions and 182 deletions
|
|
@ -1,116 +1,21 @@
|
||||||
|
//go:build integration
|
||||||
|
|
||||||
package bor
|
package bor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/json"
|
|
||||||
"math/big"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
||||||
"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/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/ethconfig"
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// addr1 = 0x71562b71999873DB5b286dF957af199Ec94617F7
|
|
||||||
pkey1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
||||||
// addr2 = 0x9fB29AAc15b9A4B7F17c3385939b007540f4d791
|
|
||||||
pkey2, _ = crypto.HexToECDSA("9b28f36fbd67381120752d6172ecdcf10e06ab2d9a1367aac00cdcd6ac7855d3")
|
|
||||||
keys = []*ecdsa.PrivateKey{pkey1, pkey2}
|
|
||||||
)
|
|
||||||
|
|
||||||
func InitMiner(genesis *core.Genesis, privKey *ecdsa.PrivateKey) (*node.Node, *eth.Ethereum, error) {
|
|
||||||
// Define the basic configurations for the Ethereum node
|
|
||||||
datadir := os.TempDir()
|
|
||||||
|
|
||||||
config := &node.Config{
|
|
||||||
Name: "geth",
|
|
||||||
Version: params.Version,
|
|
||||||
DataDir: datadir,
|
|
||||||
P2P: p2p.Config{
|
|
||||||
ListenAddr: "0.0.0.0:0",
|
|
||||||
NoDiscovery: true,
|
|
||||||
MaxPeers: 25,
|
|
||||||
},
|
|
||||||
UseLightweightKDF: true,
|
|
||||||
}
|
|
||||||
// Create the node and configure a full Ethereum node on it
|
|
||||||
stack, err := node.New(config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
ethBackend, err := eth.New(stack, ðconfig.Config{
|
|
||||||
Genesis: genesis,
|
|
||||||
NetworkId: genesis.Config.ChainID.Uint64(),
|
|
||||||
SyncMode: downloader.FullSync,
|
|
||||||
DatabaseCache: 256,
|
|
||||||
DatabaseHandles: 256,
|
|
||||||
TxPool: core.DefaultTxPoolConfig,
|
|
||||||
GPO: ethconfig.Defaults.GPO,
|
|
||||||
Ethash: ethconfig.Defaults.Ethash,
|
|
||||||
Miner: miner.Config{
|
|
||||||
Etherbase: crypto.PubkeyToAddress(privKey.PublicKey),
|
|
||||||
GasCeil: genesis.GasLimit * 11 / 10,
|
|
||||||
GasPrice: big.NewInt(1),
|
|
||||||
Recommit: time.Second,
|
|
||||||
},
|
|
||||||
WithoutHeimdall: true,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// register backend to account manager with keystore for signing
|
|
||||||
keydir := stack.KeyStoreDir()
|
|
||||||
|
|
||||||
n, p := keystore.StandardScryptN, keystore.StandardScryptP
|
|
||||||
kStore := keystore.NewKeyStore(keydir, n, p)
|
|
||||||
|
|
||||||
kStore.ImportECDSA(privKey, "")
|
|
||||||
acc := kStore.Accounts()[0]
|
|
||||||
kStore.Unlock(acc, "")
|
|
||||||
// proceed to authorize the local account manager in any case
|
|
||||||
ethBackend.AccountManager().AddBackend(kStore)
|
|
||||||
|
|
||||||
// ethBackend.AccountManager().AddBackend()
|
|
||||||
err = stack.Start()
|
|
||||||
return stack, ethBackend, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitGenesis(t *testing.T, faucets []*ecdsa.PrivateKey, fileLocation string) *core.Genesis {
|
|
||||||
|
|
||||||
// sprint size = 8 in genesis
|
|
||||||
genesisData, err := os.ReadFile(fileLocation)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
genesis := &core.Genesis{}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(genesisData, genesis); err != nil {
|
|
||||||
t.Fatalf("%s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
genesis.Config.ChainID = big.NewInt(15001)
|
|
||||||
genesis.Config.EIP150Hash = common.Hash{}
|
|
||||||
|
|
||||||
return genesis
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprint length change tests
|
// Sprint length change tests
|
||||||
func TestValidatorsBlockProduction(t *testing.T) {
|
func TestValidatorsBlockProduction(t *testing.T) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -20,7 +18,6 @@ import (
|
||||||
"golang.org/x/crypto/sha3"
|
"golang.org/x/crypto/sha3"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
||||||
"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/consensus/bor"
|
"github.com/ethereum/go-ethereum/consensus/bor"
|
||||||
|
|
@ -34,12 +31,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"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/ethconfig"
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
|
@ -54,84 +47,6 @@ var (
|
||||||
keys = []*ecdsa.PrivateKey{pkey1, pkey2}
|
keys = []*ecdsa.PrivateKey{pkey1, pkey2}
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitMiner(genesis *core.Genesis, privKey *ecdsa.PrivateKey) (*node.Node, *eth.Ethereum, error) {
|
|
||||||
// Define the basic configurations for the Ethereum node
|
|
||||||
datadir, _ := ioutil.TempDir("", "")
|
|
||||||
|
|
||||||
config := &node.Config{
|
|
||||||
Name: "geth",
|
|
||||||
Version: params.Version,
|
|
||||||
DataDir: datadir,
|
|
||||||
P2P: p2p.Config{
|
|
||||||
ListenAddr: "0.0.0.0:0",
|
|
||||||
NoDiscovery: true,
|
|
||||||
MaxPeers: 25,
|
|
||||||
},
|
|
||||||
UseLightweightKDF: true,
|
|
||||||
}
|
|
||||||
// Create the node and configure a full Ethereum node on it
|
|
||||||
stack, err := node.New(config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
ethBackend, err := eth.New(stack, ðconfig.Config{
|
|
||||||
Genesis: genesis,
|
|
||||||
NetworkId: genesis.Config.ChainID.Uint64(),
|
|
||||||
SyncMode: downloader.FullSync,
|
|
||||||
DatabaseCache: 256,
|
|
||||||
DatabaseHandles: 256,
|
|
||||||
TxPool: core.DefaultTxPoolConfig,
|
|
||||||
GPO: ethconfig.Defaults.GPO,
|
|
||||||
Ethash: ethconfig.Defaults.Ethash,
|
|
||||||
Miner: miner.Config{
|
|
||||||
Etherbase: crypto.PubkeyToAddress(privKey.PublicKey),
|
|
||||||
GasCeil: genesis.GasLimit * 11 / 10,
|
|
||||||
GasPrice: big.NewInt(1),
|
|
||||||
Recommit: time.Second,
|
|
||||||
},
|
|
||||||
WithoutHeimdall: true,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// register backend to account manager with keystore for signing
|
|
||||||
keydir := stack.KeyStoreDir()
|
|
||||||
|
|
||||||
n, p := keystore.StandardScryptN, keystore.StandardScryptP
|
|
||||||
kStore := keystore.NewKeyStore(keydir, n, p)
|
|
||||||
|
|
||||||
kStore.ImportECDSA(privKey, "")
|
|
||||||
acc := kStore.Accounts()[0]
|
|
||||||
kStore.Unlock(acc, "")
|
|
||||||
// proceed to authorize the local account manager in any case
|
|
||||||
ethBackend.AccountManager().AddBackend(kStore)
|
|
||||||
|
|
||||||
// ethBackend.AccountManager().AddBackend()
|
|
||||||
err = stack.Start()
|
|
||||||
return stack, ethBackend, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitGenesis(t *testing.T, faucets []*ecdsa.PrivateKey, fileLocation string) *core.Genesis {
|
|
||||||
|
|
||||||
// sprint size = 8 in genesis
|
|
||||||
genesisData, err := ioutil.ReadFile(fileLocation)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("%s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
genesis := &core.Genesis{}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(genesisData, genesis); err != nil {
|
|
||||||
t.Fatalf("%s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
genesis.Config.ChainID = big.NewInt(15001)
|
|
||||||
genesis.Config.EIP150Hash = common.Hash{}
|
|
||||||
|
|
||||||
return genesis
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidatorWentOffline(t *testing.T) {
|
func TestValidatorWentOffline(t *testing.T) {
|
||||||
|
|
||||||
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))))
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
package bor
|
package bor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ecdsa"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -15,6 +16,7 @@ import (
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
|
|
@ -31,7 +33,12 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||||
"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/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
|
"github.com/ethereum/go-ethereum/node"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/tests/bor/mocks"
|
"github.com/ethereum/go-ethereum/tests/bor/mocks"
|
||||||
)
|
)
|
||||||
|
|
@ -359,3 +366,81 @@ func IsSprintStart(number uint64) bool {
|
||||||
func IsSprintEnd(number uint64) bool {
|
func IsSprintEnd(number uint64) bool {
|
||||||
return (number+1)%sprintSize == 0
|
return (number+1)%sprintSize == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitMiner(genesis *core.Genesis, privKey *ecdsa.PrivateKey) (*node.Node, *eth.Ethereum, error) {
|
||||||
|
// Define the basic configurations for the Ethereum node
|
||||||
|
datadir, _ := ioutil.TempDir("", "")
|
||||||
|
|
||||||
|
config := &node.Config{
|
||||||
|
Name: "geth",
|
||||||
|
Version: params.Version,
|
||||||
|
DataDir: datadir,
|
||||||
|
P2P: p2p.Config{
|
||||||
|
ListenAddr: "0.0.0.0:0",
|
||||||
|
NoDiscovery: true,
|
||||||
|
MaxPeers: 25,
|
||||||
|
},
|
||||||
|
UseLightweightKDF: true,
|
||||||
|
}
|
||||||
|
// Create the node and configure a full Ethereum node on it
|
||||||
|
stack, err := node.New(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
ethBackend, err := eth.New(stack, ðconfig.Config{
|
||||||
|
Genesis: genesis,
|
||||||
|
NetworkId: genesis.Config.ChainID.Uint64(),
|
||||||
|
SyncMode: downloader.FullSync,
|
||||||
|
DatabaseCache: 256,
|
||||||
|
DatabaseHandles: 256,
|
||||||
|
TxPool: core.DefaultTxPoolConfig,
|
||||||
|
GPO: ethconfig.Defaults.GPO,
|
||||||
|
Ethash: ethconfig.Defaults.Ethash,
|
||||||
|
Miner: miner.Config{
|
||||||
|
Etherbase: crypto.PubkeyToAddress(privKey.PublicKey),
|
||||||
|
GasCeil: genesis.GasLimit * 11 / 10,
|
||||||
|
GasPrice: big.NewInt(1),
|
||||||
|
Recommit: time.Second,
|
||||||
|
},
|
||||||
|
WithoutHeimdall: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// register backend to account manager with keystore for signing
|
||||||
|
keydir := stack.KeyStoreDir()
|
||||||
|
|
||||||
|
n, p := keystore.StandardScryptN, keystore.StandardScryptP
|
||||||
|
kStore := keystore.NewKeyStore(keydir, n, p)
|
||||||
|
|
||||||
|
kStore.ImportECDSA(privKey, "")
|
||||||
|
acc := kStore.Accounts()[0]
|
||||||
|
kStore.Unlock(acc, "")
|
||||||
|
// proceed to authorize the local account manager in any case
|
||||||
|
ethBackend.AccountManager().AddBackend(kStore)
|
||||||
|
|
||||||
|
// ethBackend.AccountManager().AddBackend()
|
||||||
|
err = stack.Start()
|
||||||
|
return stack, ethBackend, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitGenesis(t *testing.T, faucets []*ecdsa.PrivateKey, fileLocation string) *core.Genesis {
|
||||||
|
|
||||||
|
// sprint size = 8 in genesis
|
||||||
|
genesisData, err := ioutil.ReadFile(fileLocation)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
genesis := &core.Genesis{}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(genesisData, genesis); err != nil {
|
||||||
|
t.Fatalf("%s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
genesis.Config.ChainID = big.NewInt(15001)
|
||||||
|
genesis.Config.EIP150Hash = common.Hash{}
|
||||||
|
|
||||||
|
return genesis
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue