forked from onflow/flow-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto_test.go
76 lines (61 loc) · 1.81 KB
/
crypto_test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package cmd
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/onflow/flow-go/model/bootstrap"
)
const nodeID string = "0000000000000000000000000000000000000000000000000000000000000001"
func TestEndToEnd(t *testing.T) {
// Create a temp directory to work as "bootstrap"
bootdir, err := ioutil.TempDir("", "bootstrap.*")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(bootdir)
t.Logf("Created dir %s", bootdir)
// Create test files
//bootcmd.WriteText(filepath.Join(bootdir, bootstrap.PathNodeId), []byte(nodeID)
randomBeaconPath := filepath.Join(bootdir, fmt.Sprintf(bootstrap.PathRandomBeaconPriv, nodeID))
err = os.MkdirAll(filepath.Dir(randomBeaconPath), 0755)
if err != nil {
t.Fatalf("Failed to write dir for random beacon file: %s", err)
}
err = ioutil.WriteFile(randomBeaconPath, []byte("test data"), 0644)
if err != nil {
t.Fatalf("Failed to write random beacon file: %s", err)
}
// Client:
// create the transit keys
err = generateKeys(bootdir, nodeID)
if err != nil {
t.Fatalf("Error generating keys: %s", err)
}
// Dapper:
// Wrap a file with transit keys
err = wrapFile(bootdir, nodeID)
if err != nil {
t.Fatalf("Error wrapping files: %s", err)
}
// Client:
// Unwrap files
err = unWrapFile(bootdir, nodeID)
if err != nil {
t.Fatalf("Error unwrapping response: %s", err)
}
}
func TestSha256(t *testing.T) {
tmpFile, err := ioutil.TempFile(os.TempDir(), "prefix-")
assert.NoError(t, err)
defer os.Remove(tmpFile.Name())
text := []byte("write some text to file")
_, err = tmpFile.Write(text)
assert.NoError(t, err)
assert.NoError(t, tmpFile.Close())
hash, err := getFileSHA256(tmpFile.Name())
assert.NoError(t, err)
assert.Equal(t, "876a3eab5fe740cb864a3d62869b0eefd6fbc34ec331c3064a6ffac0f9485a88", hash)
}