Implemented managed state

* Reimplemented nonce management for known accounts.
This commit is contained in:
obscuren
2015-03-13 16:29:04 +01:00
parent cda88ce31a
commit f1fcda4f2f
4 changed files with 90 additions and 24 deletions

View File

@@ -0,0 +1,54 @@
package state
import "testing"
var addr = []byte("test")
func create() (*ManagedState, *account) {
ms := ManageState(nil)
ms.accounts[string(addr)] = newAccount(&StateObject{nonce: 100})
return ms, ms.accounts[string(addr)]
}
func TestNewNonce(t *testing.T) {
ms, _ := create()
nonce := ms.NewNonce(addr)
if nonce != 100 {
t.Error("expected nonce 101. got", nonce)
}
}
func TestRemove(t *testing.T) {
ms, account := create()
nn := make([]bool, 10)
for i, _ := range nn {
nn[i] = true
}
account.nonces = append(account.nonces, nn...)
i := uint64(5)
ms.RemoveNonce(addr, account.nstart+i)
if len(account.nonces) != 5 {
t.Error("expected", i, "'th index to be false")
}
}
func TestReuse(t *testing.T) {
ms, account := create()
nn := make([]bool, 10)
for i, _ := range nn {
nn[i] = true
}
account.nonces = append(account.nonces, nn...)
i := uint64(5)
ms.RemoveNonce(addr, account.nstart+i)
nonce := ms.NewNonce(addr)
if nonce != 105 {
t.Error("expected nonce to be 105. got", nonce)
}
}