2016-02-03 22:46:27 +00:00
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"testing"
|
|
|
|
|
2020-05-18 07:10:59 +00:00
|
|
|
"github.com/holiman/uint256"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/core/vm/stack"
|
|
|
|
"github.com/ledgerwatch/erigon/params"
|
2016-02-03 22:46:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoreCapture(t *testing.T) {
|
|
|
|
var (
|
2021-05-27 13:54:55 +00:00
|
|
|
env = NewEVM(BlockContext{
|
2021-08-10 02:48:56 +00:00
|
|
|
ContractHasTEVM: func(common.Hash) (bool, error) { return false, nil },
|
2021-05-27 13:54:55 +00:00
|
|
|
}, TxContext{}, &dummyStatedb{}, params.TestChainConfig, Config{})
|
2016-08-19 14:19:51 +00:00
|
|
|
logger = NewStructLogger(nil)
|
2016-02-03 22:46:27 +00:00
|
|
|
mem = NewMemory()
|
2020-06-05 14:45:56 +00:00
|
|
|
stack = stack.New()
|
2021-05-27 13:54:55 +00:00
|
|
|
contract = NewContract(&dummyContractRef{}, &dummyContractRef{}, new(uint256.Int), 0, false /* skipAnalysis */, false)
|
2016-02-03 22:46:27 +00:00
|
|
|
)
|
2021-06-04 16:25:28 +00:00
|
|
|
stack.Push(uint256.NewInt(1))
|
|
|
|
stack.Push(uint256.NewInt(0))
|
2016-02-03 22:46:27 +00:00
|
|
|
var index common.Hash
|
2021-12-15 13:19:58 +00:00
|
|
|
logger.CaptureState(env, 0, SSTORE, 0, 0, &ScopeContext{
|
|
|
|
Memory: mem,
|
|
|
|
Stack: stack,
|
|
|
|
Contract: contract,
|
|
|
|
}, nil, 0, nil)
|
|
|
|
|
2020-06-10 09:46:13 +00:00
|
|
|
if len(logger.storage[contract.Address()]) == 0 {
|
|
|
|
t.Fatalf("expected exactly 1 changed value on address %x, got %d", contract.Address(), len(logger.storage[contract.Address()]))
|
2016-02-03 22:46:27 +00:00
|
|
|
}
|
|
|
|
exp := common.BigToHash(big.NewInt(1))
|
2020-06-10 09:46:13 +00:00
|
|
|
if logger.storage[contract.Address()][index] != exp {
|
|
|
|
t.Errorf("expected %x, got %x", exp, logger.storage[contract.Address()][index])
|
2016-02-03 22:46:27 +00:00
|
|
|
}
|
|
|
|
}
|