From 20c5123739025cf3275e0c6a9b5842b23c64677f Mon Sep 17 00:00:00 2001 From: MestryOmkar Date: Mon, 5 Nov 2018 11:45:14 +0530 Subject: [PATCH] Fixed unit test for block randomize. --- cmd/XDC/dao_test.go | 5 +++-- contracts/randomize/randomize_test.go | 12 ++++++------ contracts/utils.go | 6 +++--- contracts/utils_test.go | 3 +-- core/genesis_test.go | 2 +- core/types/block_test.go | 13 +++++++------ eth/tracers/testdata/call_tracer_create.json | 2 +- eth/tracers/testdata/call_tracer_deep_calls.json | 2 +- eth/tracers/testdata/call_tracer_delegatecall.json | 2 +- .../call_tracer_inner_create_oog_outer_throw.json | 2 +- .../call_tracer_inner_throw_outer_revert.json | 2 +- eth/tracers/testdata/call_tracer_oog.json | 2 +- eth/tracers/testdata/call_tracer_revert.json | 2 +- eth/tracers/testdata/call_tracer_simple.json | 2 +- eth/tracers/testdata/call_tracer_throw.json | 2 +- params/config.go | 6 +++--- 16 files changed, 33 insertions(+), 32 deletions(-) diff --git a/cmd/XDC/dao_test.go b/cmd/XDC/dao_test.go index b22746262c..443ff7d72d 100644 --- a/cmd/XDC/dao_test.go +++ b/cmd/XDC/dao_test.go @@ -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) diff --git a/contracts/randomize/randomize_test.go b/contracts/randomize/randomize_test.go index 871a26f872..e800afc8cf 100644 --- a/contracts/randomize/randomize_test.go +++ b/contracts/randomize/randomize_test.go @@ -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)) } } \ No newline at end of file diff --git a/contracts/utils.go b/contracts/utils.go index 8cdbfc7d78..262db29596 100644 --- a/contracts/utils.go +++ b/contracts/utils.go @@ -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.") } diff --git a/contracts/utils_test.go b/contracts/utils_test.go index bb6a8b242c..cb8764c543 100644 --- a/contracts/utils_test.go +++ b/contracts/utils_test.go @@ -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) diff --git a/core/genesis_test.go b/core/genesis_test.go index 052ded6991..a67b042ded 100644 --- a/core/genesis_test.go +++ b/core/genesis_test.go @@ -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: ¶ms.ChainConfig{HomesteadBlock: big.NewInt(3)}, Alloc: GenesisAlloc{ diff --git a/core/types/block_test.go b/core/types/block_test.go index a35fbc25b1..fe9347c1b9 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -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) } diff --git a/eth/tracers/testdata/call_tracer_create.json b/eth/tracers/testdata/call_tracer_create.json index 8699bf3e7e..984d0bce11 100644 --- a/eth/tracers/testdata/call_tracer_create.json +++ b/eth/tracers/testdata/call_tracer_create.json @@ -26,7 +26,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_deep_calls.json b/eth/tracers/testdata/call_tracer_deep_calls.json index 0353d4cfa9..cfeb5e79e3 100644 --- a/eth/tracers/testdata/call_tracer_deep_calls.json +++ b/eth/tracers/testdata/call_tracer_deep_calls.json @@ -89,7 +89,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_delegatecall.json b/eth/tracers/testdata/call_tracer_delegatecall.json index f7ad6df5f5..416c866d1d 100644 --- a/eth/tracers/testdata/call_tracer_delegatecall.json +++ b/eth/tracers/testdata/call_tracer_delegatecall.json @@ -42,7 +42,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_inner_create_oog_outer_throw.json b/eth/tracers/testdata/call_tracer_inner_create_oog_outer_throw.json index b8a4cdd233..20142d0e1d 100644 --- a/eth/tracers/testdata/call_tracer_inner_create_oog_outer_throw.json +++ b/eth/tracers/testdata/call_tracer_inner_create_oog_outer_throw.json @@ -34,7 +34,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_inner_throw_outer_revert.json b/eth/tracers/testdata/call_tracer_inner_throw_outer_revert.json index edd80e5b84..d10edcc65a 100644 --- a/eth/tracers/testdata/call_tracer_inner_throw_outer_revert.json +++ b/eth/tracers/testdata/call_tracer_inner_throw_outer_revert.json @@ -37,7 +37,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_oog.json b/eth/tracers/testdata/call_tracer_oog.json index de4fed6ab1..b765ee9064 100644 --- a/eth/tracers/testdata/call_tracer_oog.json +++ b/eth/tracers/testdata/call_tracer_oog.json @@ -28,7 +28,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_revert.json b/eth/tracers/testdata/call_tracer_revert.json index 059040a1c8..26e00d031d 100644 --- a/eth/tracers/testdata/call_tracer_revert.json +++ b/eth/tracers/testdata/call_tracer_revert.json @@ -26,7 +26,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_simple.json b/eth/tracers/testdata/call_tracer_simple.json index b46432122d..5ae54756ab 100644 --- a/eth/tracers/testdata/call_tracer_simple.json +++ b/eth/tracers/testdata/call_tracer_simple.json @@ -37,7 +37,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/eth/tracers/testdata/call_tracer_throw.json b/eth/tracers/testdata/call_tracer_throw.json index 60d4d1071d..46cd3e3b47 100644 --- a/eth/tracers/testdata/call_tracer_throw.json +++ b/eth/tracers/testdata/call_tracer_throw.json @@ -30,7 +30,7 @@ "chainId": 3, "daoForkSupport": true, "eip150Block": 0, - "eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d", + "eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a", "eip155Block": 10, "eip158Block": 10, "ethash": {}, diff --git a/params/config.go b/params/config.go index 7ae7beaeac..2599a8cb56 100644 --- a/params/config.go +++ b/params/config.go @@ -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),