forked from cruzbit/cruzbit
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathblock_storage_disk_test.go
More file actions
54 lines (44 loc) · 1.11 KB
/
Copy pathblock_storage_disk_test.go
File metadata and controls
54 lines (44 loc) · 1.11 KB
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
// Copyright 2019 cruzbit developers
// Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
package cruzbit
import (
"encoding/hex"
"testing"
"golang.org/x/crypto/ed25519"
)
func TestEncodeBlockHeader(t *testing.T) {
pubKey, _, err := ed25519.GenerateKey(nil)
if err != nil {
t.Fatal(err)
}
// create a coinbase
tx := NewTransaction(nil, pubKey, InitialCoinbaseReward, 0, 0, 0, 0, "hello")
// create a block
targetBytes, err := hex.DecodeString(InitialTarget)
if err != nil {
t.Fatal(err)
}
var target BlockID
copy(target[:], targetBytes)
block, err := NewBlock(BlockID{}, 0, target, BlockID{}, []*Transaction{tx})
if err != nil {
t.Fatal(err)
}
// encode the header
encodedHeader, err := encodeBlockHeader(block.Header, 12345)
if err != nil {
t.Fatal(err)
}
// decode the header
header, when, err := decodeBlockHeader(encodedHeader)
if err != nil {
t.Fatal(err)
}
// compare
if *header != *block.Header {
t.Fatal("Decoded header doesn't match original")
}
if when != 12345 {
t.Fatal("Decoded timestamp doesn't match original")
}
}