-
Notifications
You must be signed in to change notification settings - Fork 0
/
models_test.go
105 lines (94 loc) · 2.5 KB
/
models_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRpcTransfersToTxSuccess(t *testing.T) {
transfers := []RpcTx{
{
TXID: "dummy txid",
Height: 20,
Timestamp: 2000,
UnlockTime: 100,
Confirmations: 1,
Amount: 333333,
Address: "addr1",
Type: "in",
},
{
TXID: "dummy txid",
Height: 20,
Timestamp: 2000,
UnlockTime: 100,
Confirmations: 1,
Amount: 666666,
Address: "addr2",
Type: "pool",
},
{
TXID: "dummy txid",
Height: 20,
Timestamp: 2000,
UnlockTime: 100,
Confirmations: 1,
Amount: 99999,
Address: "addr2",
Type: "out",
},
}
tx, err := RpcTxToTx(transfers)
assert.Nil(t, err)
// The Transfer with type "out" was ignored
assert.Equal(t, 2, len(tx.Destinations))
for idx, _ := range tx.Destinations {
assert.Equal(t, transfers[idx].TXID, tx.TXID)
assert.Equal(t, transfers[idx].Height, tx.Height)
assert.Equal(t, transfers[idx].Timestamp, tx.Timestamp)
assert.Equal(t, transfers[idx].UnlockTime, tx.UnlockTime)
assert.Equal(t, transfers[idx].Confirmations, tx.Confirmations)
assert.Equal(t, transfers[idx].Address, tx.Destinations[idx].Address)
assert.Equal(t, transfers[idx].Amount, tx.Destinations[idx].Amount)
}
}
func TestRpcTransfersToTxFailure(t *testing.T) {
transfers := []RpcTx{
{
TXID: "dummy txid",
Height: 20,
Timestamp: 2000,
UnlockTime: 100,
Confirmations: 1,
Amount: 99999,
Address: "addr2",
Type: "out",
},
}
tx, err := RpcTxToTx(transfers)
// No TX was created, because the only Transfer
// has type "out"
assert.Error(t, err)
assert.Nil(t, tx)
}
func TestRpcBlockToBlock(t *testing.T) {
prevHashCases := []string{"hash of prev block", ""}
expectedPrevHashes := [][]string{{"hash of prev block"}, {}}
for i := 0; i < len(prevHashCases); i++ {
t.Run("", func(t *testing.T) {
rb := RpcBlock{
BlockHeader: RpcBlockHeader{
Hash: "some hash",
Height: 100,
Timestamp: 300,
PrevHash: prevHashCases[i],
},
TxHashes: []string{"hash1", "hash2"},
}
b := RpcBlockToBlock(rb)
assert.Equal(t, rb.BlockHeader.Hash, b.Hash)
assert.Equal(t, rb.BlockHeader.Height, b.Height)
assert.Equal(t, rb.BlockHeader.Timestamp, b.Timestamp)
assert.Equal(t, expectedPrevHashes[i], b.PrevHashes)
assert.Equal(t, rb.TxHashes, b.TxHashes)
})
}
}