aboutsummaryrefslogtreecommitdiffstats
path: root/state/managed_state_test.go
blob: ae374f728a1cfffdff1a4cd97c64b1441aa1038a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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)
    }
}