Fixed unit test for block randomize.

This commit is contained in:
MestryOmkar 2018-11-05 11:45:14 +05:30
parent d81dc08a50
commit 20c5123739
16 changed files with 33 additions and 32 deletions

View file

@ -77,7 +77,7 @@ var daoProForkGenesis = `{
}
}`
var daoGenesisHash = common.HexToHash("5e1fc79cb4ffa4739177b5408045cd5d51c6cf766133f23f7cd72ee1f8d790e0")
var daoGenesisHash = common.HexToHash("f2ea0466bf5a07cb7407474d9fbaae6e275127f038ca57a673b833234204f4fd")
var daoGenesisForkBlock = big.NewInt(314)
// TestDAOForkBlockNewChain tests that the DAO hard-fork number and the nodes support/opposition is correctly
@ -127,10 +127,11 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
}
defer db.Close()
genesisHash := common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
genesisHash := common.HexToHash("2efa267fef46877ac2659209e2299f97b0afc2a797ee8672db21920a5151e0aa")
if genesis != "" {
genesisHash = daoGenesisHash
}
t.Log("genesisHash", genesisHash.String())
config, err := core.GetChainConfig(db, genesisHash)
if err != nil {
t.Errorf("test %d: failed to retrieve chain config: %v", test, err)

View file

@ -9,10 +9,10 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/contracts"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)
var (
@ -63,7 +63,7 @@ func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
transactOpts := bind.NewKeyedTransactor(acc1Key)
transactOpts.GasLimit = 4200000
epocNumber := uint64(99)
epocNumber := uint64(900)
randomizeAddr, randomizeContract, err := DeployRandomize(transactOpts, backend, new(big.Int).SetInt64(0))
if err != nil {
t.Fatalf("Can't deploy randomize SC: %v", err)
@ -127,7 +127,7 @@ func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
if err != nil {
t.Error("Can't decrypt secret and opening", err)
}
if len(randomizes) != 991 {
t.Error("Randomize length not match")
if len(randomizes) != 901 {
t.Error("Randomize length not match", "length", len(randomizes))
}
}

View file

@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
randomizeContract "github.com/ethereum/go-ethereum/contracts/randomize/contract"
@ -28,7 +29,6 @@ import (
"math/rand"
"strconv"
"time"
"github.com/ethereum/go-ethereum/common/hexutil"
)
const (
@ -297,7 +297,7 @@ func DecryptRandomizeFromSecretsAndOpening(secrets [][32]byte, opening [32]byte)
if err != nil {
log.Error("Can not convert string to integer", "error", err)
}
random[i] = int64(int64(intNumber))
random[i] = int64(intNumber)
}
}
}
@ -605,7 +605,7 @@ func GetMasternodesFromCheckpointHeader(checkpointHeader *types.Header) []common
}
// Get m2 list from checkpoint block.
func GetM2FromCheckpointBlock(checkpointBlock types.Block, ) ([]common.Address, error) {
func GetM2FromCheckpointBlock(checkpointBlock types.Block) ([]common.Address, error) {
if checkpointBlock.Number().Int64()%EpocBlockRandomize != 0 {
return nil, errors.New("This block is not checkpoint block epoc.")
}

View file

@ -218,8 +218,7 @@ func TestDecodeValidatorsHexData(t *testing.T) {
if err != nil {
t.Error("Fail to decode validator from hex string", err)
}
c:= []int64{1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0}
if !isArrayEqual([][]int64{b}, [][]int64{c}) {
c := []int64{1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0} if !isArrayEqual([][]int64{b}, [][]int64{c}) {
t.Errorf("Fail to get m2 result %v", b)
}
t.Log("b", b)

View file

@ -42,7 +42,7 @@ func TestDefaultGenesisBlock(t *testing.T) {
func TestSetupGenesis(t *testing.T) {
var (
customghash = common.HexToHash("0x89c99d90b79719238d2645c7642f2c9295246e80775b38cfd162b696817fbd50")
customghash = common.HexToHash("0xa1cd36b0c6db6940b1184a28cea11f4f74d823589c6a7e7f1398a5c176835598")
customg = Genesis{
Config: &params.ChainConfig{HomesteadBlock: big.NewInt(3)},
Alloc: GenesisAlloc{

View file

@ -17,19 +17,19 @@
package types
import (
"bytes"
"fmt"
"math/big"
"reflect"
"testing"
"github.com/ethereum/go-ethereum/common"
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"reflect"
)
// from bcValidBlockTest.json, "SimpleTx"
func TestBlockEncoding(t *testing.T) {
blockEnc := common.FromHex("f90260f901f9a083cafc574e1f51ba9dc0568fc617a08ea2429fb384059c972f13b19fa1c8dd55a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a05fe50b260da6308036625b850b5d6ced6d0a9f814c0688bc91ffb7b7a3a54b67a0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c4f861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba09bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094fa08a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b1c0")
blockEnc := common.FromHex("f90261f901faa00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a05fe50b260da6308036625b850b5d6ced6d0a9f814c0688bc91ffb7b7a3a54b67a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c480f861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba09bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094fa08a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b1c0")
var block Block
if err := rlp.DecodeBytes(blockEnc, &block); err != nil {
t.Fatal("decode error: ", err)
@ -46,7 +46,7 @@ func TestBlockEncoding(t *testing.T) {
check("Coinbase", block.Coinbase(), common.HexToAddress("8888f1f195afa192cfee860698584c030f4c9db1"))
check("MixDigest", block.MixDigest(), common.HexToHash("bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff498"))
check("Root", block.Root(), common.HexToHash("ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"))
check("Hash", block.Hash(), common.HexToHash("0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"))
check("Hash", block.Hash(), common.HexToHash("ed8e5b071b309a4c965a2b4aabd1f8f7818276627331ca37e753a3e97ec87081"))
check("Nonce", block.Nonce(), uint64(0xa13a5a8c8f2bb1c4))
check("Time", block.Time(), big.NewInt(1426516743))
check("Size", block.Size(), common.StorageSize(len(blockEnc)))
@ -64,6 +64,7 @@ func TestBlockEncoding(t *testing.T) {
if err != nil {
t.Fatal("encode error: ", err)
}
if !bytes.Equal(ourBlockEnc, blockEnc) {
t.Errorf("encoded block mismatch:\ngot: %x\nwant: %x", ourBlockEnc, blockEnc)
}

View file

@ -26,7 +26,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -89,7 +89,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -42,7 +42,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -34,7 +34,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -37,7 +37,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -28,7 +28,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -26,7 +26,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -37,7 +37,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -30,7 +30,7 @@
"chainId": 3,
"daoForkSupport": true,
"eip150Block": 0,
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
"eip155Block": 10,
"eip158Block": 10,
"ethash": {},

View file

@ -24,8 +24,8 @@ import (
)
var (
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") // Mainnet genesis hash to enforce below configs on
TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") // Testnet genesis hash to enforce below configs on
MainnetGenesisHash = common.HexToHash("2efa267fef46877ac2659209e2299f97b0afc2a797ee8672db21920a5151e0aa") // Mainnet genesis hash to enforce below configs on
TestnetGenesisHash = common.HexToHash("fc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a") // Testnet genesis hash to enforce below configs on
)
var (
@ -51,7 +51,7 @@ var (
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
EIP150Hash: common.HexToHash("0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a"),
EIP155Block: big.NewInt(10),
EIP158Block: big.NewInt(10),
ByzantiumBlock: big.NewInt(1700000),