<commit_before>package state

import (
	. "gopkg.in/check.v1"
	"testing"

	"github.com/ethereum/go-ethereum/ethdb"
	"github.com/ethereum/go-ethereum/ethutil"
	"github.com/ethereum/go-ethereum/trie"
)

func Test(t *testing.T) { TestingT(t) }

type StateSuite struct {
	state *State
}

var _ = Suite(&StateSuite{})

const expectedasbytes = "Expected % x Got % x"

// var ZeroHash256 = make([]byte, 32)

func (s *StateSuite) SetUpTest(c *C) {
	db, _ := ethdb.NewMemDatabase()
	ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
	ethutil.Config.Db = db
	s.state = New(trie.New(db, ""))
}

func (s *StateSuite) TestSnapshot(c *C) {
	data1 := ethutil.NewValue(42)
	data2 := ethutil.NewValue(43)
	storageaddr := ethutil.Big("0")
	stateobjaddr := []byte("aa")

	stateObject := s.state.GetOrNewStateObject(stateobjaddr)
	stateObject.SetStorage(storageaddr, data1)
	snapshot := s.state.Copy()

	stateObject = s.state.GetStateObject(stateobjaddr)
	stateObject.SetStorage(storageaddr, data2)
	s.state.Set(snapshot)

	stateObject = s.state.GetStateObject(stateobjaddr)
	res := stateObject.GetStorage(storageaddr)

	c.Assert(data1, DeepEquals, res, Commentf(expectedasbytes, data1, res))
}<commit_msg>Add verbose comments to TestSnapshot<commit_after>package state

import (
	. "gopkg.in/check.v1"
	"testing"

	"github.com/ethereum/go-ethereum/ethdb"
	"github.com/ethereum/go-ethereum/ethutil"
	"github.com/ethereum/go-ethereum/trie"
)

func Test(t *testing.T) { TestingT(t) }

type StateSuite struct {
	state *State
}

var _ = Suite(&StateSuite{})

const expectedasbytes = "Expected % x Got % x"

// var ZeroHash256 = make([]byte, 32)

func (s *StateSuite) SetUpTest(c *C) {
	db, _ := ethdb.NewMemDatabase()
	ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
	ethutil.Config.Db = db
	s.state = New(trie.New(db, ""))
}

func (s *StateSuite) TestSnapshot(c *C) {
	stateobjaddr := []byte("aa")
	storageaddr := ethutil.Big("0")
	data1 := ethutil.NewValue(42)
	data2 := ethutil.NewValue(43)

	// get state object
	stateObject := s.state.GetOrNewStateObject(stateobjaddr)
	// set inital state object value
	stateObject.SetStorage(storageaddr, data1)
	// get snapshot of current state
	snapshot := s.state.Copy()

	// get state object. is this strictly necessary?
	stateObject = s.state.GetStateObject(stateobjaddr)
	// set new state object value
	stateObject.SetStorage(storageaddr, data2)
	// restore snapshot
	s.state.Set(snapshot)

	// get state object
	stateObject = s.state.GetStateObject(stateobjaddr)
	// get state storage value
	res := stateObject.GetStorage(storageaddr)

	c.Assert(data1, DeepEquals, res, Commentf(expectedasbytes, data1, res))
}
{'fraction_non_alphanumeric': 0.14865377322715206, 'fraction_numerical': 0.012893439514599925, 'mean_word_length': 4.785087719298246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6772663', 'n_tokens_mistral': 1002, 'n_tokens_neox': 979, 'n_words': 190}