ソースを参照

Updated tests and fixed suicide

obscuren 10 年 前
コミット
19efebe91e
4 ファイル変更23 行追加1 行削除
  1. 1 1
      state/state_object.go
  2. 9 0
      state/statedb.go
  3. 8 0
      tests/vm/gh_test.go
  4. 5 0
      vm/vm.go

+ 1 - 1
state/state_object.go

@@ -111,7 +111,7 @@ func NewStateObjectFromBytes(address, data []byte, db ethutil.Database) *StateOb
 func (self *StateObject) MarkForDeletion() {
 	self.remove = true
 	self.dirty = true
-	statelogger.DebugDetailf("%x: #%d %v (deletion)\n", self.Address(), self.nonce, self.balance)
+	statelogger.Debugf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance)
 }
 
 func (c *StateObject) getAddr(addr []byte) *ethutil.Value {

+ 9 - 0
state/statedb.go

@@ -121,6 +121,7 @@ func (self *StateDB) Delete(addr []byte) bool {
 	stateObject := self.GetOrNewStateObject(addr)
 	if stateObject != nil {
 		stateObject.MarkForDeletion()
+		stateObject.balance = new(big.Int)
 
 		return true
 	}
@@ -128,6 +129,14 @@ func (self *StateDB) Delete(addr []byte) bool {
 	return false
 }
 
+func (self *StateDB) IsDeleted(addr []byte) bool {
+	stateObject := self.GetStateObject(addr)
+	if stateObject != nil {
+		return stateObject.remove
+	}
+	return false
+}
+
 //
 // Setting, updating & deleting state object methods
 //

+ 8 - 0
tests/vm/gh_test.go

@@ -75,10 +75,18 @@ type VmTest struct {
 }
 
 func RunVmTest(p string, t *testing.T) {
+
 	tests := make(map[string]VmTest)
 	helper.CreateFileTests(t, p, &tests)
 
 	for name, test := range tests {
+		/*
+			vm.Debug = true
+			helper.Logger.SetLogLevel(4)
+			if name != "refund_CallToSuicideTwice" {
+				continue
+			}
+		*/
 		db, _ := ethdb.NewMemDatabase()
 		statedb := state.New(nil, db)
 		for addr, account := range test.Pre {

+ 5 - 0
vm/vm.go

@@ -736,6 +736,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
 			self.Printf(" => (%x) %v", receiver.Address()[:4], balance)
 
 			receiver.AddBalance(balance)
+
 			statedb.Delete(context.Address())
 
 			fallthrough
@@ -905,6 +906,10 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo
 			g = GasStorageMod
 		}
 		gas.Set(g)
+	case SUICIDE:
+		if !statedb.IsDeleted(context.Address()) {
+			statedb.Refund(self.env.Origin(), RefundSuicide)
+		}
 	case MLOAD:
 		newMemSize = calcMemSize(stack.Peek(), u256(32))
 	case MSTORE8: