github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/core/bench_test.go (about) 1 package core 2 3 import ( 4 "crypto/ecdsa" 5 "math/big" 6 7 "github.com/neatlab/neatio/chain/core/types" 8 "github.com/neatlab/neatio/utilities/common" 9 "github.com/neatlab/neatio/utilities/common/math" 10 "github.com/neatlab/neatio/utilities/crypto" 11 ) 12 13 var ( 14 benchRootKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") 15 benchRootAddr = crypto.PubkeyToAddress(benchRootKey.PublicKey) 16 benchRootFunds = math.BigPow(2, 100) 17 ) 18 19 func genValueTx(nbytes int) func(int, *BlockGen) { 20 return func(i int, gen *BlockGen) { 21 toaddr := common.Address{} 22 data := make([]byte, nbytes) 23 gas, _ := IntrinsicGas(data, false, false) 24 tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data), types.HomesteadSigner{}, benchRootKey) 25 gen.AddTx(tx) 26 } 27 } 28 29 var ( 30 ringKeys = make([]*ecdsa.PrivateKey, 1000) 31 ringAddrs = make([]common.Address, len(ringKeys)) 32 ) 33 34 func init() { 35 ringKeys[0] = benchRootKey 36 ringAddrs[0] = benchRootAddr 37 for i := 1; i < len(ringKeys); i++ { 38 ringKeys[i], _ = crypto.GenerateKey() 39 ringAddrs[i] = crypto.PubkeyToAddress(ringKeys[i].PublicKey) 40 } 41 } 42 43 func genUncles(i int, gen *BlockGen) { 44 if i >= 6 { 45 b2 := gen.PrevBlock(i - 6).Header() 46 b2.Extra = []byte("foo") 47 gen.AddUncle(b2) 48 b3 := gen.PrevBlock(i - 6).Header() 49 b3.Extra = []byte("bar") 50 gen.AddUncle(b3) 51 } 52 }