-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathaccount.go
42 lines (34 loc) · 1 KB
/
account.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
33
34
35
36
37
38
39
40
41
42
package mocks
import (
"github.com/Flaque/filet"
"github.com/brianvoe/gofakeit/v6"
"github.com/chzyer/test"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
// see: https://git.io/JGsC1
// taken from geth, used to speed up tests.
const (
veryLightScryptN = 2
veryLightScryptP = 1
)
// MockAccount mocks a new account.
func MockAccount(tb testing.TB) *keystore.Key {
tb.Helper()
kstr := keystore.NewKeyStore(filet.TmpDir(tb, ""), veryLightScryptN, veryLightScryptP)
password := gofakeit.Password(true, true, true, false, false, 10)
acct, err := kstr.NewAccount(password)
assert.Nil(tb, err)
data, err := os.ReadFile(acct.URL.Path)
assert.Nil(tb, err)
key, err := keystore.DecryptKey(data, password)
assert.Nil(tb, err)
return key
}
// MockAddress generates a random ethereum address for testing.
func MockAddress() common.Address {
return common.BytesToAddress(test.RandBytes(common.HashLength))
}