diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-26 06:09:38 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-26 06:09:38 +0800 |
commit | 3ebd7f1166f03f94117651d8e74b9603ee7d6966 (patch) | |
tree | 0b26904388619e1e36380a8a21d65476a9f0cc94 /ethchain/state_test.go | |
parent | 81ef40010f6f31bc94f654048b41fa3a9f9e07eb (diff) | |
download | go-tangerine-3ebd7f1166f03f94117651d8e74b9603ee7d6966.tar go-tangerine-3ebd7f1166f03f94117651d8e74b9603ee7d6966.tar.gz go-tangerine-3ebd7f1166f03f94117651d8e74b9603ee7d6966.tar.bz2 go-tangerine-3ebd7f1166f03f94117651d8e74b9603ee7d6966.tar.lz go-tangerine-3ebd7f1166f03f94117651d8e74b9603ee7d6966.tar.xz go-tangerine-3ebd7f1166f03f94117651d8e74b9603ee7d6966.tar.zst go-tangerine-3ebd7f1166f03f94117651d8e74b9603ee7d6966.zip |
State snapshotting
Diffstat (limited to 'ethchain/state_test.go')
-rw-r--r-- | ethchain/state_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ethchain/state_test.go b/ethchain/state_test.go new file mode 100644 index 000000000..4cc3fdf75 --- /dev/null +++ b/ethchain/state_test.go @@ -0,0 +1,31 @@ +package ethchain + +import ( + "fmt" + "github.com/ethereum/eth-go/ethdb" + "github.com/ethereum/eth-go/ethutil" + "testing" +) + +func TestSnapshot(t *testing.T) { + ethutil.ReadConfig("", ethutil.LogStd, "") + + db, _ := ethdb.NewMemDatabase() + state := NewState(ethutil.NewTrie(db, "")) + + stateObject := NewContract([]byte("aa"), ethutil.Big1, ZeroHash256) + state.UpdateStateObject(stateObject) + stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42)) + + snapshot := state.Snapshot() + + stateObject = state.GetStateObject([]byte("aa")) + stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43)) + + state.Revert(snapshot) + + stateObject = state.GetStateObject([]byte("aa")) + if !stateObject.GetStorage(ethutil.Big("0")).Cmp(ethutil.NewValue(42)) { + t.Error("Expected storage 0 to be 42") + } +} |