-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathclient_internal_test.go
More file actions
133 lines (116 loc) · 3.27 KB
/
client_internal_test.go
File metadata and controls
133 lines (116 loc) · 3.27 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package arksdk
import (
"testing"
clientTypes "github.com/arkade-os/arkd/pkg/client-lib/types"
"github.com/stretchr/testify/require"
)
func TestGroupSpentVtxosByTx(t *testing.T) {
t.Parallel()
t.Run("groups offchain and settled vtxos and ignores unknown outpoints", func(t *testing.T) {
t.Parallel()
outpoint1 := clientTypes.Outpoint{Txid: "tx1", VOut: 0}
outpoint2 := clientTypes.Outpoint{Txid: "tx2", VOut: 1}
outpoint3 := clientTypes.Outpoint{Txid: "tx3", VOut: 2}
missingOutpoint := clientTypes.Outpoint{Txid: "missing", VOut: 3}
oldSpendable := map[clientTypes.Outpoint]clientTypes.Vtxo{
outpoint1: {Outpoint: outpoint1},
outpoint2: {Outpoint: outpoint2},
outpoint3: {Outpoint: outpoint3},
}
spentVtxos := []clientTypes.Vtxo{
{
Outpoint: outpoint1,
ArkTxid: "arktx-checkpoint-1",
SpentBy: "checkpoint-txid-1",
},
{
Outpoint: outpoint2,
ArkTxid: "arktx-checkpoint-1",
SpentBy: "checkpoint-txid-2",
},
{
Outpoint: outpoint3,
SettledBy: "commitment-txid-1",
SpentBy: "forfeit",
},
{
Outpoint: missingOutpoint,
ArkTxid: "arktx-ignored",
SettledBy: "commitment-txid-ignored",
SpentBy: "forfeit",
},
}
vtxosToSpend, vtxosToSettle := groupSpentVtxosByTx(spentVtxos, oldSpendable)
require.Equal(t, map[string]map[clientTypes.Outpoint]string{
"arktx-checkpoint-1": {
outpoint1: "checkpoint-txid-1",
outpoint2: "checkpoint-txid-2",
},
}, vtxosToSpend)
require.Equal(t, map[string]map[clientTypes.Outpoint]string{
"commitment-txid-1": {
outpoint3: "forfeit",
},
}, vtxosToSettle)
})
t.Run("creates multiple groups and prioritizes settled entries", func(t *testing.T) {
t.Parallel()
outpoint1 := clientTypes.Outpoint{Txid: "tx10", VOut: 0}
outpoint2 := clientTypes.Outpoint{Txid: "tx11", VOut: 1}
outpoint3 := clientTypes.Outpoint{Txid: "tx12", VOut: 2}
outpoint4 := clientTypes.Outpoint{Txid: "tx13", VOut: 3}
missingOutpoint := clientTypes.Outpoint{Txid: "tx14", VOut: 1}
oldSpendable := map[clientTypes.Outpoint]clientTypes.Vtxo{
outpoint1: {Outpoint: outpoint1},
outpoint2: {Outpoint: outpoint2},
outpoint3: {Outpoint: outpoint3},
outpoint4: {Outpoint: outpoint4},
}
spentVtxos := []clientTypes.Vtxo{
{
Outpoint: outpoint1,
ArkTxid: "arktx-checkpoint-a",
SpentBy: "checkpoint-a-1",
},
{
Outpoint: outpoint2,
ArkTxid: "arktx-checkpoint-b",
SpentBy: "checkpoint-b-1",
},
{
Outpoint: outpoint3,
SettledBy: "commitment-a",
SpentBy: "forfeit",
},
{
Outpoint: outpoint4,
ArkTxid: "arktx-should-be-ignored",
SettledBy: "commitment-b",
SpentBy: "forfeit",
},
{
Outpoint: missingOutpoint,
ArkTxid: "arktx",
SettledBy: "commitment",
SpentBy: "forfeit",
},
}
vtxosToSpend, vtxosToSettle := groupSpentVtxosByTx(spentVtxos, oldSpendable)
require.Equal(t, map[string]map[clientTypes.Outpoint]string{
"arktx-checkpoint-a": {
outpoint1: "checkpoint-a-1",
},
"arktx-checkpoint-b": {
outpoint2: "checkpoint-b-1",
},
}, vtxosToSpend)
require.Equal(t, map[string]map[clientTypes.Outpoint]string{
"commitment-a": {
outpoint3: "forfeit",
},
"commitment-b": {
outpoint4: "forfeit",
},
}, vtxosToSettle)
})
}