mirror of https://github.com/ethereum/go-ethereum
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.9 KiB
75 lines
2.9 KiB
9 years ago
|
// Copyright 2016 The go-ethereum Authors
|
||
|
// This file is part of the go-ethereum library.
|
||
|
//
|
||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||
|
// the Free Software Foundation, either version 3 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// The go-ethereum library 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 Lesser General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU Lesser General Public License
|
||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
||
3 years ago
|
package logger
|
||
9 years ago
|
|
||
|
import (
|
||
|
"math/big"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/ethereum/go-ethereum/common"
|
||
6 years ago
|
"github.com/ethereum/go-ethereum/core/state"
|
||
3 years ago
|
"github.com/ethereum/go-ethereum/core/vm"
|
||
8 years ago
|
"github.com/ethereum/go-ethereum/params"
|
||
9 years ago
|
)
|
||
|
|
||
|
type dummyContractRef struct {
|
||
|
calledForEach bool
|
||
|
}
|
||
|
|
||
8 years ago
|
func (dummyContractRef) Address() common.Address { return common.Address{} }
|
||
|
func (dummyContractRef) Value() *big.Int { return new(big.Int) }
|
||
|
func (dummyContractRef) SetCode(common.Hash, []byte) {}
|
||
9 years ago
|
func (d *dummyContractRef) ForEachStorage(callback func(key, value common.Hash) bool) {
|
||
|
d.calledForEach = true
|
||
|
}
|
||
|
func (d *dummyContractRef) SubBalance(amount *big.Int) {}
|
||
|
func (d *dummyContractRef) AddBalance(amount *big.Int) {}
|
||
|
func (d *dummyContractRef) SetBalance(*big.Int) {}
|
||
|
func (d *dummyContractRef) SetNonce(uint64) {}
|
||
|
func (d *dummyContractRef) Balance() *big.Int { return new(big.Int) }
|
||
|
|
||
6 years ago
|
type dummyStatedb struct {
|
||
|
state.StateDB
|
||
|
}
|
||
|
|
||
3 years ago
|
func (*dummyStatedb) GetRefund() uint64 { return 1337 }
|
||
|
func (*dummyStatedb) GetState(_ common.Address, _ common.Hash) common.Hash { return common.Hash{} }
|
||
|
func (*dummyStatedb) SetState(_ common.Address, _ common.Hash, _ common.Hash) {}
|
||
6 years ago
|
|
||
9 years ago
|
func TestStoreCapture(t *testing.T) {
|
||
|
var (
|
||
8 years ago
|
logger = NewStructLogger(nil)
|
||
3 years ago
|
env = vm.NewEVM(vm.BlockContext{}, vm.TxContext{}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: logger})
|
||
|
contract = vm.NewContract(&dummyContractRef{}, &dummyContractRef{}, new(big.Int), 100000)
|
||
9 years ago
|
)
|
||
3 years ago
|
contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x0, byte(vm.SSTORE)}
|
||
9 years ago
|
var index common.Hash
|
||
3 years ago
|
logger.CaptureStart(env, common.Address{}, contract.Address(), false, nil, 0, nil)
|
||
3 years ago
|
_, err := env.Interpreter().Run(contract, []byte{}, false)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
4 years ago
|
if len(logger.storage[contract.Address()]) == 0 {
|
||
4 years ago
|
t.Fatalf("expected exactly 1 changed value on address %x, got %d", contract.Address(),
|
||
|
len(logger.storage[contract.Address()]))
|
||
9 years ago
|
}
|
||
|
exp := common.BigToHash(big.NewInt(1))
|
||
4 years ago
|
if logger.storage[contract.Address()][index] != exp {
|
||
|
t.Errorf("expected %x, got %x", exp, logger.storage[contract.Address()][index])
|
||
9 years ago
|
}
|
||
|
}
|