debug tests

This commit is contained in:
Qvintvs 2018-06-01 12:23:38 +08:00
parent 622e98ad51
commit a67eccbcd8
26 changed files with 116 additions and 106 deletions

View File

@ -550,8 +550,10 @@ func TestInputFixedArrayAndVariableInputLength(t *testing.T) {
func TestDefaultFunctionParsing(t *testing.T) {
const definition = `[{ "name" : "balance" }]`
arg0, _ := NewType("uint256")
arg1, _ := NewType("address")
abi, err := JSON(strings.NewReader(definition))
if err != nil {
t.Fatal(err)
}
if _, ok := abi.Methods["balance"]; !ok {
t.Error("expected 'balance' to be present")

View File

@ -47,8 +47,9 @@ func BytesToHash(b []byte) Hash {
h.SetBytes(b)
return h
}
func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }
func StringToHash(s string) Hash { return BytesToHash([]byte(s)) } // dep: Istanbul
func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }
// Get the string representation of the underlying hash
func (h Hash) Str() string { return string(h[:]) }
@ -144,8 +145,9 @@ func BytesToAddress(b []byte) Address {
a.SetBytes(b)
return a
}
func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
func StringToAddress(s string) Address { return BytesToAddress([]byte(s)) } // dep: Istanbul
func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
// IsHexAddress verifies whether a string can represent a valid hex-encoded
// Ethereum address or not.

View File

@ -42,12 +42,12 @@ import (
// other fake events to process Istanbul.
func newBlockChain(n int) (*core.BlockChain, *backend) {
genesis, nodeKeys := getGenesisAndKeys(n)
memDB, _ := ethdb.NewMemDatabase()
memDB := ethdb.NewMemDatabase()
config := istanbul.DefaultConfig
// Use the first key as private key
b, _ := New(config, nodeKeys[0], memDB).(*backend)
genesis.MustCommit(memDB)
blockchain, err := core.NewBlockChain(memDB, genesis.Config, b, vm.Config{})
blockchain, err := core.NewBlockChain(memDB, nil, genesis.Config, b, vm.Config{})
if err != nil {
panic(err)
}
@ -121,7 +121,7 @@ func makeHeader(parent *types.Block, config *istanbul.Config) *types.Header {
ParentHash: parent.Hash(),
Number: parent.Number().Add(parent.Number(), common.Big1),
GasLimit: core.CalcGasLimit(parent),
GasUsed: new(big.Int),
GasUsed: 0,
Extra: parent.Extra(),
Time: new(big.Int).Add(parent.Time(), new(big.Int).SetUint64(config.BlockPeriod)),
Difficulty: defaultDifficulty,
@ -138,7 +138,7 @@ func makeBlock(chain *core.BlockChain, engine *backend, parent *types.Block) *ty
func makeBlockWithoutSeal(chain *core.BlockChain, engine *backend, parent *types.Block) *types.Block {
header := makeHeader(parent, engine.config)
engine.Prepare(chain, header)
state, _,_ := chain.StateAt(parent.Root())
state, _, _ := chain.StateAt(parent.Root())
block, _ := engine.Finalize(chain, header, state, nil, nil, nil)
return block
}

View File

@ -335,11 +335,11 @@ func TestVoting(t *testing.T) {
Difficulty: defaultDifficulty,
Mixhash: types.IstanbulDigest,
}
b, _ := genesis.ToBlock()
b := genesis.ToBlock(nil)
extra, _ := prepareExtra(b.Header(), validators)
genesis.ExtraData = extra
// Create a pristine blockchain with the genesis injected
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
genesis.Commit(db)
config := istanbul.DefaultConfig
@ -347,7 +347,7 @@ func TestVoting(t *testing.T) {
config.Epoch = tt.epoch
}
engine := New(config, accounts.accounts[tt.validators[0]], db).(*backend)
chain, err := core.NewBlockChain(db, genesis.Config, engine, vm.Config{})
chain, err := core.NewBlockChain(db, nil, genesis.Config, engine, vm.Config{})
// Assemble a chain of headers from the cast votes
headers := make([]*types.Header, len(tt.votes))
@ -427,7 +427,7 @@ func TestSaveAndLoad(t *testing.T) {
common.StringToAddress("1234567895"),
}, istanbul.RoundRobin),
}
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
err := snap.store(db)
if err != nil {
t.Errorf("store snapshot failed: %v", err)

View File

@ -31,8 +31,8 @@ func makeBlock(number int64) *types.Block {
header := &types.Header{
Difficulty: big.NewInt(0),
Number: big.NewInt(number),
GasLimit: big.NewInt(0),
GasUsed: big.NewInt(0),
GasLimit: 0,
GasUsed: 0,
Time: big.NewInt(0),
}
block := &types.Block{}

View File

@ -265,7 +265,7 @@ func (t *testSystem) stop(core bool) {
func (t *testSystem) NewBackend(id uint64) *testSystemBackend {
// assume always success
ethDB, _ := ethdb.NewMemDatabase()
ethDB := ethdb.NewMemDatabase()
backend := &testSystemBackend{
id: id,
sys: t,

View File

@ -123,7 +123,7 @@ func genTxRing(naccounts int) func(int, *BlockGen) {
gen.TxNonce(ringAddrs[from]),
ringAddrs[to],
benchRootFunds,
bigTxGas,
params.TxGas,
nil,
nil,
)

View File

@ -1484,6 +1484,11 @@ func (bc *BlockChain) BadBlocks() ([]BadBlockArgs, error) {
return headers, nil
}
// HasBadBlock returns whether the block with the hash is a bad block. dep: Istanbul
func (bc *BlockChain) HasBadBlock(hash common.Hash) bool {
return bc.badBlocks.Contains(hash)
}
// addBadBlock adds a bad block to the bad-block LRU cache
func (bc *BlockChain) addBadBlock(block *types.Block) {
bc.badBlocks.Add(block.Header().Hash(), block.Header())

View File

@ -1174,7 +1174,7 @@ func TestEIP161AccountRemoval(t *testing.T) {
if _, err := blockchain.InsertChain(types.Blocks{blocks[0]}); err != nil {
t.Fatal(err)
}
if st, _ := blockchain.State(); !st.Exist(theAddr) {
if st, _, _ := blockchain.State(); !st.Exist(theAddr) {
t.Error("expected account to exist")
}
@ -1182,7 +1182,7 @@ func TestEIP161AccountRemoval(t *testing.T) {
if _, err := blockchain.InsertChain(types.Blocks{blocks[1]}); err != nil {
t.Fatal(err)
}
if st, _ := blockchain.State(); st.Exist(theAddr) {
if st, _, _ := blockchain.State(); st.Exist(theAddr) {
t.Error("account should not exist")
}
@ -1190,7 +1190,7 @@ func TestEIP161AccountRemoval(t *testing.T) {
if _, err := blockchain.InsertChain(types.Blocks{blocks[2]}); err != nil {
t.Fatal(err)
}
if st, _ := blockchain.State(); st.Exist(theAddr) {
if st, _, _ := blockchain.State(); st.Exist(theAddr) {
t.Error("account should not exist")
}
}

View File

@ -30,7 +30,7 @@ import (
// Tests block header storage and retrieval operations.
func TestHeaderStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
// Create a test header to move around the database and make sure it's really new
header := &types.Header{Number: big.NewInt(42), Extra: []byte("test header")}
@ -65,7 +65,7 @@ func TestHeaderStorage(t *testing.T) {
// Tests block body storage and retrieval operations.
func TestBodyStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
// Create a test body to move around the database and make sure it's really new
body := &types.Body{Uncles: []*types.Header{{Extra: []byte("test header")}}}
@ -105,7 +105,7 @@ func TestBodyStorage(t *testing.T) {
// Tests block storage and retrieval operations.
func TestBlockStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
// Create a test block to move around the database and make sure it's really new
block := types.NewBlockWithHeader(&types.Header{
@ -157,7 +157,7 @@ func TestBlockStorage(t *testing.T) {
// Tests that partial block contents don't get reassembled into full blocks.
func TestPartialBlockStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
block := types.NewBlockWithHeader(&types.Header{
Extra: []byte("test block"),
UncleHash: types.EmptyUncleHash,
@ -198,7 +198,7 @@ func TestPartialBlockStorage(t *testing.T) {
// Tests block total difficulty storage and retrieval operations.
func TestTdStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
// Create a test TD to move around the database and make sure it's really new
hash, td := common.Hash{}, big.NewInt(314)
@ -223,7 +223,7 @@ func TestTdStorage(t *testing.T) {
// Tests that canonical numbers can be mapped to hashes and retrieved.
func TestCanonicalMappingStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
// Create a test canonical number and assinged hash to move around
hash, number := common.Hash{0: 0xff}, uint64(314)
@ -248,7 +248,7 @@ func TestCanonicalMappingStorage(t *testing.T) {
// Tests that head headers and head blocks can be assigned, individually.
func TestHeadStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
blockHead := types.NewBlockWithHeader(&types.Header{Extra: []byte("test block header")})
blockFull := types.NewBlockWithHeader(&types.Header{Extra: []byte("test block full")})
@ -288,11 +288,11 @@ func TestHeadStorage(t *testing.T) {
// Tests that positional lookup metadata can be stored and retrieved.
func TestLookupStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), big.NewInt(1111), big.NewInt(11111), []byte{0x11, 0x11, 0x11})
tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), big.NewInt(2222), big.NewInt(22222), []byte{0x22, 0x22, 0x22})
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), big.NewInt(3333), big.NewInt(33333), []byte{0x33, 0x33, 0x33})
tx1 := types.NewTransaction(1, common.BytesToAddress([]byte{0x11}), big.NewInt(111), 1111, big.NewInt(11111), []byte{0x11, 0x11, 0x11})
tx2 := types.NewTransaction(2, common.BytesToAddress([]byte{0x22}), big.NewInt(222), 2222, big.NewInt(22222), []byte{0x22, 0x22, 0x22})
tx3 := types.NewTransaction(3, common.BytesToAddress([]byte{0x33}), big.NewInt(333), 3333, big.NewInt(33333), []byte{0x33, 0x33, 0x33})
txs := []*types.Transaction{tx1, tx2, tx3}
block := types.NewBlock(&types.Header{Number: big.NewInt(314)}, txs, nil, nil)
@ -333,29 +333,29 @@ func TestLookupStorage(t *testing.T) {
// Tests that receipts associated with a single block can be stored and retrieved.
func TestBlockReceiptStorage(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
receipt1 := &types.Receipt{
Status: types.ReceiptStatusFailed,
CumulativeGasUsed: big.NewInt(1),
CumulativeGasUsed: 1,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x11})},
{Address: common.BytesToAddress([]byte{0x01, 0x11})},
},
TxHash: common.BytesToHash([]byte{0x11, 0x11}),
ContractAddress: common.BytesToAddress([]byte{0x01, 0x11, 0x11}),
GasUsed: big.NewInt(111111),
GasUsed: 111111,
}
receipt2 := &types.Receipt{
PostState: common.Hash{2}.Bytes(),
CumulativeGasUsed: big.NewInt(2),
CumulativeGasUsed: 2,
Logs: []*types.Log{
{Address: common.BytesToAddress([]byte{0x22})},
{Address: common.BytesToAddress([]byte{0x02, 0x22})},
},
TxHash: common.BytesToHash([]byte{0x22, 0x22}),
ContractAddress: common.BytesToAddress([]byte{0x02, 0x22, 0x22}),
GasUsed: big.NewInt(222222),
GasUsed: 222222,
}
receipts := []*types.Receipt{receipt1, receipt2}

View File

@ -16,7 +16,7 @@ var dualStateTestHeader = types.Header{
Number: new(big.Int),
Time: new(big.Int).SetUint64(43),
Difficulty: new(big.Int).SetUint64(1000488),
GasLimit: new(big.Int).SetUint64(4700000),
GasLimit: 4700000,
}
//[1] PUSH1 0x01 (out size)
@ -36,7 +36,7 @@ var dualStateTestHeader = types.Header{
func TestDualStatePrivateToPublicCall(t *testing.T) {
callAddr := common.Address{1}
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
publicState, _ := state.New(common.Hash{}, state.NewDatabase(db))
publicState.SetCode(common.Address{2}, common.Hex2Bytes("600a6000526001601ff300"))
@ -48,14 +48,14 @@ func TestDualStatePrivateToPublicCall(t *testing.T) {
addr: author,
to: &callAddr,
value: big.NewInt(1),
gas: big.NewInt(1000000),
gas: 1000000,
gasPrice: new(big.Int),
data: nil,
}
ctx := NewEVMContext(msg, &dualStateTestHeader, nil, &author)
env := vm.NewEVM(ctx, publicState, privateState, &params.ChainConfig{}, vm.Config{})
env.Call(vm.AccountRef(author), callAddr, msg.data, msg.gas.Uint64(), new(big.Int))
env.Call(vm.AccountRef(author), callAddr, msg.data, msg.gas, new(big.Int))
if value := privateState.GetState(callAddr, common.Hash{}); value != (common.Hash{10}) {
t.Errorf("expected 10 got %x", value)
@ -65,7 +65,7 @@ func TestDualStatePrivateToPublicCall(t *testing.T) {
func TestDualStatePublicToPrivateCall(t *testing.T) {
callAddr := common.Address{1}
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
privateState, _ := state.New(common.Hash{}, state.NewDatabase(db))
privateState.SetCode(common.Address{2}, common.Hex2Bytes("600a6000526001601ff300"))
@ -77,14 +77,14 @@ func TestDualStatePublicToPrivateCall(t *testing.T) {
addr: author,
to: &callAddr,
value: big.NewInt(1),
gas: big.NewInt(1000000),
gas: 1000000,
gasPrice: new(big.Int),
data: nil,
}
ctx := NewEVMContext(msg, &dualStateTestHeader, nil, &author)
env := vm.NewEVM(ctx, publicState, publicState, &params.ChainConfig{}, vm.Config{})
env.Call(vm.AccountRef(author), callAddr, msg.data, msg.gas.Uint64(), new(big.Int))
env.Call(vm.AccountRef(author), callAddr, msg.data, msg.gas, new(big.Int))
if value := publicState.GetState(callAddr, common.Hash{}); value != (common.Hash{}) {
t.Errorf("expected 0 got %x", value)
@ -94,7 +94,7 @@ func TestDualStatePublicToPrivateCall(t *testing.T) {
func TestDualStateReadOnly(t *testing.T) {
callAddr := common.Address{1}
db, _ := ethdb.NewMemDatabase()
db := ethdb.NewMemDatabase()
publicState, _ := state.New(common.Hash{}, state.NewDatabase(db))
publicState.SetCode(common.Address{2}, common.Hex2Bytes("600a60005500"))
@ -106,14 +106,14 @@ func TestDualStateReadOnly(t *testing.T) {
addr: author,
to: &callAddr,
value: big.NewInt(1),
gas: big.NewInt(1000000),
gas: 1000000,
gasPrice: new(big.Int),
data: nil,
}
ctx := NewEVMContext(msg, &dualStateTestHeader, nil, &author)
env := vm.NewEVM(ctx, publicState, privateState, &params.ChainConfig{}, vm.Config{})
env.Call(vm.AccountRef(author), callAddr, msg.data, msg.gas.Uint64(), new(big.Int))
env.Call(vm.AccountRef(author), callAddr, msg.data, msg.gas, new(big.Int))
if value := publicState.GetState(common.Address{2}, common.Hash{}); value != (common.Hash{0}) {
t.Errorf("expected 0 got %x", value)

View File

@ -20,11 +20,12 @@ import (
// callmsg is the message type used for call transactions in the private state test
type callmsg struct {
addr common.Address
to *common.Address
gas, gasPrice *big.Int
value *big.Int
data []byte
addr common.Address
to *common.Address
gas uint64
gasPrice *big.Int
value *big.Int
data []byte
}
// accessor boilerplate to implement core.Message
@ -33,7 +34,7 @@ func (m callmsg) FromFrontier() common.Address { return m.addr }
func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) To() *common.Address { return m.to }
func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
func (m callmsg) Gas() *big.Int { return m.gas }
func (m callmsg) Gas() uint64 { return m.gas }
func (m callmsg) Value() *big.Int { return m.value }
func (m callmsg) Data() []byte { return m.data }
func (m callmsg) CheckNonce() bool { return true }

View File

@ -27,7 +27,7 @@ import (
// Tests that the node iterator indeed walks over the entire database contents.
func TestNodeIteratorCoverage(t *testing.T) {
// Create some arbitrary test state to iterate
db, mem, root, _ := makeTestState()
db, root, _ := makeTestState()
state, err := New(root, db)
if err != nil {

View File

@ -63,7 +63,7 @@ func makeTestState() (Database, common.Hash, []*testAccount) {
root, _ := state.Commit(false)
// Return the generated state
return db, mem, root, accounts
return db, root, accounts
}
// checkStateAccounts cross references a reconstructed state with an expected
@ -136,7 +136,7 @@ func TestIterativeStateSyncBatched(t *testing.T) { testIterativeStateSync(t,
func testIterativeStateSync(t *testing.T, batch int) {
// Create a random state to copy
_, srcMem, srcRoot, srcAccounts := makeTestState()
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
dstDb := ethdb.NewMemDatabase()
@ -168,7 +168,7 @@ func testIterativeStateSync(t *testing.T, batch int) {
// partial results are returned, and the others sent only later.
func TestIterativeDelayedStateSync(t *testing.T) {
// Create a random state to copy
_, srcMem, srcRoot, srcAccounts := makeTestState()
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
dstDb := ethdb.NewMemDatabase()
@ -205,7 +205,7 @@ func TestIterativeRandomStateSyncBatched(t *testing.T) { testIterativeRandomS
func testIterativeRandomStateSync(t *testing.T, batch int) {
// Create a random state to copy
_, srcMem, srcRoot, srcAccounts := makeTestState()
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
dstDb := ethdb.NewMemDatabase()
@ -245,7 +245,7 @@ func testIterativeRandomStateSync(t *testing.T, batch int) {
// partial results are returned (Even those randomly), others sent only later.
func TestIterativeRandomDelayedStateSync(t *testing.T) {
// Create a random state to copy
_, srcMem, srcRoot, srcAccounts := makeTestState()
srcDb, srcRoot, srcAccounts := makeTestState()
// Create a destination state and sync with the scheduler
dstDb := ethdb.NewMemDatabase()
@ -290,9 +290,7 @@ func TestIterativeRandomDelayedStateSync(t *testing.T) {
// the database.
func TestIncompleteStateSync(t *testing.T) {
// Create a random state to copy
_, srcMem, srcRoot, srcAccounts := makeTestState()
checkTrieConsistency(srcMem, srcRoot)
srcDb, srcRoot, srcAccounts := makeTestState()
checkTrieConsistency(srcDb.TrieDB().DiskDB().(ethdb.Database), srcRoot)

View File

@ -45,9 +45,10 @@ func init() {
}
type testBlockChain struct {
statedb *state.StateDB
gasLimit uint64
chainHeadFeed *event.Feed
statedb *state.StateDB
privateStateDb *state.StateDB
gasLimit uint64
chainHeadFeed *event.Feed
}
func (bc *testBlockChain) CurrentBlock() *types.Block {
@ -60,8 +61,8 @@ func (bc *testBlockChain) GetBlock(hash common.Hash, number uint64) *types.Block
return bc.CurrentBlock()
}
func (bc *testBlockChain) StateAt(common.Hash) (*state.StateDB, error) {
return bc.statedb, nil
func (bc *testBlockChain) StateAt(common.Hash) (*state.StateDB, *state.StateDB, error) {
return bc.statedb, bc.privateStateDb, nil
}
func (bc *testBlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Subscription {
@ -79,7 +80,7 @@ func pricedTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ec
func setupTxPool() (*TxPool, *ecdsa.PrivateKey) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
key, _ := crypto.GenerateKey()
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
@ -151,7 +152,7 @@ type testChain struct {
// testChain.State() is used multiple times to reset the pending state.
// when simulate is true it will create a state that indicates
// that tx0 and tx1 are included in the chain.
func (c *testChain) State() (*state.StateDB, error) {
func (c *testChain) State() (*state.StateDB, *state.StateDB, error) {
// delay "state change" by one. The tx pool fetches the
// state multiple times and by delaying it a bit we simulate
// a state change between those fetches.
@ -163,7 +164,7 @@ func (c *testChain) State() (*state.StateDB, error) {
c.statedb.SetBalance(c.address, new(big.Int).SetUint64(params.Ether))
*c.trigger = false
}
return stdb, nil
return stdb, stdb, nil
}
// This test simulates a scenario where a new block is imported during a
@ -181,7 +182,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
// setup pool with 2 transaction in it
statedb.SetBalance(address, new(big.Int).SetUint64(params.Ether))
blockchain := &testChain{&testBlockChain{statedb, 1000000000, new(event.Feed)}, address, &trigger}
blockchain := &testChain{&testBlockChain{statedb, statedb, 1000000000, new(event.Feed)}, address, &trigger}
tx0 := transaction(0, 100000, key)
tx1 := transaction(1, 100000, key)
@ -332,7 +333,7 @@ func TestTransactionChainFork(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
statedb.AddBalance(addr, big.NewInt(100000000000000))
pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
pool.chain = &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool.lockedReset(nil, nil)
}
resetState()
@ -361,7 +362,7 @@ func TestTransactionDoubleNonce(t *testing.T) {
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
statedb.AddBalance(addr, big.NewInt(100000000000000))
pool.chain = &testBlockChain{statedb, 1000000, new(event.Feed)}
pool.chain = &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool.lockedReset(nil, nil)
}
resetState()
@ -549,7 +550,7 @@ func TestTransactionPostponing(t *testing.T) {
// Create the pool to test the postponing with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
@ -764,7 +765,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.NoLocals = nolocals
@ -852,7 +853,7 @@ func testTransactionQueueTimeLimiting(t *testing.T, nolocals bool) {
// Create the pool to test the non-expiration enforcement
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.Lifetime = time.Second
@ -1006,7 +1007,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.GlobalSlots = config.AccountSlots * 10
@ -1052,7 +1053,7 @@ func TestTransactionCapClearsFromAll(t *testing.T) {
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.AccountSlots = 2
@ -1086,7 +1087,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
// Create the pool to test the limit enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.GlobalSlots = 0
@ -1134,7 +1135,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
@ -1255,7 +1256,7 @@ func TestTransactionPoolRepricingKeepsLocals(t *testing.T) {
// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
@ -1317,7 +1318,7 @@ func TestTransactionPoolUnderpricing(t *testing.T) {
// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.GlobalSlots = 2
@ -1423,7 +1424,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.GlobalSlots = 128
@ -1489,7 +1490,7 @@ func TestTransactionReplacement(t *testing.T) {
// Create the pool to test the pricing enforcement with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()
@ -1583,7 +1584,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
// Create the original pool to inject transaction into the journal
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
config := testTxPoolConfig
config.NoLocals = nolocals
@ -1625,7 +1626,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
// Terminate the old pool, bump the local nonce, create a new pool and ensure relevant transaction survive
pool.Stop()
statedb.SetNonce(crypto.PubkeyToAddress(local.PublicKey), 1)
blockchain = &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain = &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool = NewTxPool(config, params.TestChainConfig, blockchain)
@ -1652,7 +1653,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
pool.Stop()
statedb.SetNonce(crypto.PubkeyToAddress(local.PublicKey), 1)
blockchain = &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain = &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool = NewTxPool(config, params.TestChainConfig, blockchain)
pending, queued = pool.Stats()
@ -1681,7 +1682,7 @@ func TestTransactionStatusCheck(t *testing.T) {
// Create the pool to test the status retrievals with
statedb, _ := state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)}
blockchain := &testBlockChain{statedb, statedb, 1000000, new(event.Feed)}
pool := NewTxPool(testTxPoolConfig, params.TestChainConfig, blockchain)
defer pool.Stop()

View File

@ -83,8 +83,8 @@ func TestBlockEncoding2(t *testing.T) {
}
}
check("Difficulty", block.Difficulty(), big.NewInt(131072))
check("GasLimit", block.GasLimit(), big.NewInt(3141592))
check("GasUsed", block.GasUsed(), big.NewInt(21000))
check("GasLimit", block.GasLimit(), uint64(3141592))
check("GasUsed", block.GasUsed(), uint64(21000))
check("Coinbase", block.Coinbase(), common.HexToAddress("8888f1f195afa192cfee860698584c030f4c9db1"))
check("MixDigest", block.MixDigest(), common.HexToHash("bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff498"))
check("Root", block.Root(), common.HexToHash("ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"))
@ -93,7 +93,7 @@ func TestBlockEncoding2(t *testing.T) {
check("Time", block.Time(), big.NewInt(1426516743))
check("Size", block.Size(), common.StorageSize(len(blockEnc)))
tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), big.NewInt(50000), big.NewInt(0), nil)
tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(0), nil)
tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100"))
fmt.Println(block.Transactions()[0].Hash())

View File

@ -54,7 +54,7 @@ var (
3,
common.HexToAddress("b94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
big.NewInt(10),
big.NewInt(2000),
2000,
big.NewInt(0),
common.FromHex("5544"),
).WithSignature(

View File

@ -32,7 +32,7 @@ type twoOperandTest struct {
func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) {
var (
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
env = NewEVM(Context{}, nil, nil, params.TestChainConfig, Config{})
stack = newstack()
pc = uint64(0)
)
@ -68,7 +68,7 @@ func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64
func TestByteOp(t *testing.T) {
var (
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
env = NewEVM(Context{}, nil, nil, params.TestChainConfig, Config{})
stack = newstack()
)
tests := []struct {
@ -198,7 +198,7 @@ func TestSLT(t *testing.T) {
func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) {
var (
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
env = NewEVM(Context{}, nil, nil, params.TestChainConfig, Config{})
stack = newstack()
)
// convert args

View File

@ -48,7 +48,7 @@ type dummyStateDB struct {
func TestStoreCapture(t *testing.T) {
var (
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
env = NewEVM(Context{}, nil, nil, params.TestChainConfig, Config{})
logger = NewStructLogger(nil)
mem = NewMemory()
stack = newstack()

View File

@ -24,6 +24,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
@ -476,7 +477,7 @@ func testDAOChallenge(t *testing.T, localForked, remoteForked bool, timeout bool
genesis = gspec.MustCommit(db)
blockchain, _ = core.NewBlockChain(db, nil, config, pow, vm.Config{})
)
pm, err := NewProtocolManager(config, downloader.FullSync, DefaultConfig.NetworkId, evmux, new(testTxPool), pow, blockchain, db)
pm, err := NewProtocolManager(config, downloader.FullSync, DefaultConfig.NetworkId, evmux, new(testTxPool), pow, blockchain, db, false)
if err != nil {
t.Fatalf("failed to start test protocol manager: %v", err)
}

View File

@ -66,7 +66,7 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func
panic(err)
}
pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db)
pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db, false)
if err != nil {
return nil, nil, err
}

View File

@ -44,7 +44,7 @@ func (account) SetCode(common.Hash, []byte) {}
func (account) ForEachStorage(cb func(key, value common.Hash) bool) {}
func runTrace(tracer *Tracer) (json.RawMessage, error) {
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
contract := vm.NewContract(account{}, account{}, big.NewInt(0), 10000)
contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x1, 0x0}
@ -126,7 +126,7 @@ func TestHaltBetweenSteps(t *testing.T) {
t.Fatal(err)
}
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), 0)
tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil)

View File

@ -166,7 +166,7 @@ func TestCallTracer(t *testing.T) {
if err != nil {
t.Fatalf("failed to create call tracer: %v", err)
}
evm := vm.NewEVM(context, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
evm := vm.NewEVM(context, statedb, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
msg, err := tx.AsMessage(signer)
if err != nil {

View File

@ -85,7 +85,7 @@ func TestAccountManagement(t *testing.T) {
if err := ks.Unlock(signer, "Signer password"); err != nil {
t.Fatalf("Failed to unlock account: %v", err)
}
if _, err := ks.SignTx(signer, tx, chain); err != nil {
if _, err := ks.SignTx(signer, tx, chain, false); err != nil {
t.Fatalf("Failed to sign with unlocked account: %v", err)
}
if err := ks.Lock(signer.Address); err != nil {
@ -95,7 +95,7 @@ func TestAccountManagement(t *testing.T) {
if err := ks.TimedUnlock(signer, "Signer password", time.Second); err != nil {
t.Fatalf("Failed to time unlock account: %v", err)
}
if _, err := ks.SignTx(signer, tx, chain); err != nil {
if _, err := ks.SignTx(signer, tx, chain, false); err != nil {
t.Fatalf("Failed to sign with time unlocked account: %v", err)
}
}

View File

@ -136,7 +136,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)}
context := core.NewEVMContext(msg, header, bc, nil)
vmenv := vm.NewEVM(context, statedb, config, vm.Config{})
vmenv := vm.NewEVM(context, statedb, statedb, config, vm.Config{})
//vmenv := core.NewEnv(statedb, config, bc, msg, header, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64)
@ -149,7 +149,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
state.SetBalance(testBankAddress, math.MaxBig256)
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)}
context := core.NewEVMContext(msg, header, lc, nil)
vmenv := vm.NewEVM(context, state, config, vm.Config{})
vmenv := vm.NewEVM(context, state, state, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64)
ret, _, _, _ := core.ApplyMessage(vmenv, msg, gp)
if state.Error() == nil {

View File

@ -191,7 +191,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
st.SetBalance(testBankAddress, math.MaxBig256)
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false)}
context := core.NewEVMContext(msg, header, chain, nil)
vmenv := vm.NewEVM(context, st, config, vm.Config{})
vmenv := vm.NewEVM(context, st, st, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64)
ret, _, _, _ := core.ApplyMessage(vmenv, msg, gp)
res = append(res, ret...)