managed_state_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package state
  2. import "testing"
  3. var addr = []byte("test")
  4. func create() (*ManagedState, *account) {
  5. ms := ManageState(nil)
  6. ms.accounts[string(addr)] = newAccount(&StateObject{nonce: 100})
  7. return ms, ms.accounts[string(addr)]
  8. }
  9. func TestNewNonce(t *testing.T) {
  10. ms, _ := create()
  11. nonce := ms.NewNonce(addr)
  12. if nonce != 100 {
  13. t.Error("expected nonce 101. got", nonce)
  14. }
  15. }
  16. func TestRemove(t *testing.T) {
  17. ms, account := create()
  18. nn := make([]bool, 10)
  19. for i, _ := range nn {
  20. nn[i] = true
  21. }
  22. account.nonces = append(account.nonces, nn...)
  23. i := uint64(5)
  24. ms.RemoveNonce(addr, account.nstart+i)
  25. if len(account.nonces) != 5 {
  26. t.Error("expected", i, "'th index to be false")
  27. }
  28. }
  29. func TestReuse(t *testing.T) {
  30. ms, account := create()
  31. nn := make([]bool, 10)
  32. for i, _ := range nn {
  33. nn[i] = true
  34. }
  35. account.nonces = append(account.nonces, nn...)
  36. i := uint64(5)
  37. ms.RemoveNonce(addr, account.nstart+i)
  38. nonce := ms.NewNonce(addr)
  39. if nonce != 105 {
  40. t.Error("expected nonce to be 105. got", nonce)
  41. }
  42. }