Updated tests and fixed suicide

This commit is contained in:
obscuren 2015-03-09 11:28:35 +01:00
parent 93cdffca3a
commit 19efebe91e
4 changed files with 23 additions and 1 deletions

View File

@ -111,7 +111,7 @@ func NewStateObjectFromBytes(address, data []byte, db ethutil.Database) *StateOb
func (self *StateObject) MarkForDeletion() { func (self *StateObject) MarkForDeletion() {
self.remove = true self.remove = true
self.dirty = 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 { func (c *StateObject) getAddr(addr []byte) *ethutil.Value {

View File

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

View File

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

View File

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