mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Merge branch 'master' of https://github.com/tomochain/tomochain
This commit is contained in:
commit
f9f7b549ce
7 changed files with 16 additions and 147 deletions
|
|
@ -1,110 +0,0 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
|
||||||
// This file is part of go-ethereum.
|
|
||||||
//
|
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var customGenesisTests = []struct {
|
|
||||||
genesis string
|
|
||||||
query string
|
|
||||||
result string
|
|
||||||
}{
|
|
||||||
// Plain genesis file without anything extra
|
|
||||||
{
|
|
||||||
genesis: `{
|
|
||||||
"alloc" : {},
|
|
||||||
"coinbase" : "0x0000000000000000000000000000000000000000",
|
|
||||||
"difficulty" : "0x20000",
|
|
||||||
"extraData" : "",
|
|
||||||
"gasLimit" : "0x2fefd8",
|
|
||||||
"nonce" : "0x0000000000000042",
|
|
||||||
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
||||||
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
||||||
"timestamp" : "0x00"
|
|
||||||
}`,
|
|
||||||
query: "eth.getBlock(0).nonce",
|
|
||||||
result: "0x0000000000000042",
|
|
||||||
},
|
|
||||||
// Genesis file with an empty chain configuration (ensure missing fields work)
|
|
||||||
{
|
|
||||||
genesis: `{
|
|
||||||
"alloc" : {},
|
|
||||||
"coinbase" : "0x0000000000000000000000000000000000000000",
|
|
||||||
"difficulty" : "0x20000",
|
|
||||||
"extraData" : "",
|
|
||||||
"gasLimit" : "0x2fefd8",
|
|
||||||
"nonce" : "0x0000000000000042",
|
|
||||||
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
||||||
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
||||||
"timestamp" : "0x00",
|
|
||||||
"config" : {}
|
|
||||||
}`,
|
|
||||||
query: "eth.getBlock(0).nonce",
|
|
||||||
result: "0x0000000000000042",
|
|
||||||
},
|
|
||||||
// Genesis file with specific chain configurations
|
|
||||||
{
|
|
||||||
genesis: `{
|
|
||||||
"alloc" : {},
|
|
||||||
"coinbase" : "0x0000000000000000000000000000000000000000",
|
|
||||||
"difficulty" : "0x20000",
|
|
||||||
"extraData" : "",
|
|
||||||
"gasLimit" : "0x2fefd8",
|
|
||||||
"nonce" : "0x0000000000000042",
|
|
||||||
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
||||||
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
||||||
"timestamp" : "0x00",
|
|
||||||
"config" : {
|
|
||||||
"homesteadBlock" : 314,
|
|
||||||
"daoForkBlock" : 141,
|
|
||||||
"daoForkSupport" : true
|
|
||||||
},
|
|
||||||
}`,
|
|
||||||
query: "eth.getBlock(0).nonce",
|
|
||||||
result: "0x0000000000000042",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that initializing tomo with a custom genesis block and chain definitions
|
|
||||||
// work properly.
|
|
||||||
func TestCustomGenesis(t *testing.T) {
|
|
||||||
for i, tt := range customGenesisTests {
|
|
||||||
// Create a temporary data directory to use and inspect later
|
|
||||||
datadir := tmpdir(t)
|
|
||||||
defer os.RemoveAll(datadir)
|
|
||||||
|
|
||||||
// Initialize the data directory with the custom genesis block
|
|
||||||
json := filepath.Join(datadir, "genesis.json")
|
|
||||||
if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil {
|
|
||||||
t.Fatalf("test %d: failed to write genesis file: %v", i, err)
|
|
||||||
}
|
|
||||||
runTomo(t, "--datadir", datadir, "init", json).WaitExit()
|
|
||||||
|
|
||||||
// Query the custom genesis block
|
|
||||||
tomo := runTomo(t,
|
|
||||||
"--datadir", datadir, "--maxpeers", "0", "--port", "0",
|
|
||||||
"--nodiscover", "--nat", "none", "--ipcdisable",
|
|
||||||
"--exec", tt.query, "console")
|
|
||||||
tomo.ExpectRegexp(tt.result)
|
|
||||||
tomo.ExpectExit()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -19,7 +19,6 @@ package console
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -155,33 +154,6 @@ func (env *tester) Close(t *testing.T) {
|
||||||
os.RemoveAll(env.workspace)
|
os.RemoveAll(env.workspace)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the node lists the correct welcome message, notably that it contains
|
|
||||||
// the instance name, coinbase account, block number, data directory and supported
|
|
||||||
// console modules.
|
|
||||||
func TestWelcome(t *testing.T) {
|
|
||||||
tester := newTester(t, nil)
|
|
||||||
defer tester.Close(t)
|
|
||||||
|
|
||||||
tester.console.Welcome()
|
|
||||||
|
|
||||||
output := tester.output.String()
|
|
||||||
if want := "Welcome"; !strings.Contains(output, want) {
|
|
||||||
t.Fatalf("console output missing welcome message: have\n%s\nwant also %s", output, want)
|
|
||||||
}
|
|
||||||
if want := fmt.Sprintf("instance: %s", testInstance); !strings.Contains(output, want) {
|
|
||||||
t.Fatalf("console output missing instance: have\n%s\nwant also %s", output, want)
|
|
||||||
}
|
|
||||||
if want := fmt.Sprintf("coinbase: %s", testAddress); !strings.Contains(output, want) {
|
|
||||||
t.Fatalf("console output missing coinbase: have\n%s\nwant also %s", output, want)
|
|
||||||
}
|
|
||||||
if want := "at block: 0"; !strings.Contains(output, want) {
|
|
||||||
t.Fatalf("console output missing sync status: have\n%s\nwant also %s", output, want)
|
|
||||||
}
|
|
||||||
if want := fmt.Sprintf("datadir: %s", tester.workspace); !strings.Contains(output, want) {
|
|
||||||
t.Fatalf("console output missing coinbase: have\n%s\nwant also %s", output, want)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that JavaScript statement evaluation works as intended.
|
// Tests that JavaScript statement evaluation works as intended.
|
||||||
func TestEvaluate(t *testing.T) {
|
func TestEvaluate(t *testing.T) {
|
||||||
tester := newTester(t, nil)
|
tester := newTester(t, nil)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,8 @@ var (
|
||||||
ErrZeroGasPrice = errors.New("zero gas price")
|
ErrZeroGasPrice = errors.New("zero gas price")
|
||||||
|
|
||||||
ErrDuplicateSpecialTransaction = errors.New("duplicate a special transaction")
|
ErrDuplicateSpecialTransaction = errors.New("duplicate a special transaction")
|
||||||
|
|
||||||
|
ErrMinDeploySMC = errors.New("smart contract creation cost is under allowance")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -587,7 +589,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
}
|
}
|
||||||
// Drop non-local transactions under our own minimal accepted gas price
|
// Drop non-local transactions under our own minimal accepted gas price
|
||||||
local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network
|
local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network
|
||||||
if !local && tx.To() != nil && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
|
if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 {
|
||||||
if !tx.IsSpecialTransaction() || (pool.IsMasterNode != nil && !pool.IsMasterNode(from)) {
|
if !tx.IsSpecialTransaction() || (pool.IsMasterNode != nil && !pool.IsMasterNode(from)) {
|
||||||
return ErrUnderpriced
|
return ErrUnderpriced
|
||||||
}
|
}
|
||||||
|
|
@ -621,6 +623,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
minGasDeploySMC := new(big.Int).Mul(new(big.Int).SetUint64(10), new(big.Int).SetUint64(params.Ether))
|
||||||
|
if tx.To() == nil && (tx.Cost().Cmp(minGasDeploySMC) < 0 || tx.GasPrice().Cmp(new(big.Int).SetUint64(10000*params.Shannon)) < 0) {
|
||||||
|
return ErrMinDeploySMC
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue