-
Notifications
You must be signed in to change notification settings - Fork 210
/
state.go
32 lines (28 loc) · 874 Bytes
/
state.go
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
package testutil
import (
"testing"
"github.com/ovrclk/akash/state"
"github.com/ovrclk/akash/types"
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
)
// NewState used only for testing
func NewState(t *testing.T, gen *types.Genesis) (state.CommitState, state.CacheState) {
db := state.NewMemDB()
commitState, cacheState, err := state.LoadState(db, gen)
require.NoError(t, err)
// prime commit state so root is not nil
cacheState.Set([]byte("test"), []byte("Test"))
err = cacheState.Write()
require.NoError(t, err)
return commitState, cacheState
}
func CreateAccount(t *testing.T, state state.State) (*types.Account, crypto.PrivKey) {
key := PrivateKey(t)
account := &types.Account{
Address: key.PubKey().Address().Bytes(),
Balance: 1000000000,
}
require.NoError(t, state.Account().Save(account))
return account, key
}