@@ -4,10 +4,47 @@ import (
4
4
"context"
5
5
"fmt"
6
6
"github.com/algorandfoundation/hack-tui/api"
7
- "github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider"
7
+ "github.com/algorandfoundation/hack-tui/internal/test"
8
+ "github.com/algorandfoundation/hack-tui/internal/test/mock"
8
9
"testing"
9
10
)
10
11
12
+ func Test_ToLoraDeeplink (t * testing.T ) {
13
+ link , err := ToLoraDeepLink ("tuinet-v1" , true , true , api.ParticipationKey {
14
+ Address : "ABC" ,
15
+ EffectiveFirstValid : nil ,
16
+ EffectiveLastValid : nil ,
17
+ Id : "" ,
18
+ Key : api.AccountParticipation {},
19
+ LastBlockProposal : nil ,
20
+ LastStateProof : nil ,
21
+ LastVote : nil ,
22
+ })
23
+ if err != nil {
24
+ t .Error (err )
25
+ }
26
+ if link != "https://lora.algokit.io/localnet/transaction-wizard?type%5B0%5D=keyreg&sender%5B0%5D=ABC" {
27
+ t .Error ("Link should be a known deeplink" )
28
+ }
29
+
30
+ link , err = ToLoraDeepLink ("tuinet-v1" , false , true , mock .Keys [0 ])
31
+ if err != nil {
32
+ t .Error (err )
33
+ }
34
+ if link != "https://lora.algokit.io/localnet/transaction-wizard?type%5B0%5D=keyreg&sender%5B0%5D=ABC&selkey%5B0%5D=VEVTVEtFWQ&sprfkey%5B0%5D=VEVTVEtFWQ&votekey%5B0%5D=VEVTVEtFWQ&votefst%5B0%5D=0&votelst%5B0%5D=30000&votekd%5B0%5D=100&fee%5B0%5D=2000000" {
35
+ t .Error ("Link should be a known deeplink fee" )
36
+ }
37
+
38
+ link , err = ToLoraDeepLink ("tuinet-v1" , false , false , mock .Keys [0 ])
39
+ if err != nil {
40
+ t .Error (err )
41
+ }
42
+ if link != "https://lora.algokit.io/localnet/transaction-wizard?type%5B0%5D=keyreg&sender%5B0%5D=ABC&selkey%5B0%5D=VEVTVEtFWQ&sprfkey%5B0%5D=VEVTVEtFWQ&votekey%5B0%5D=VEVTVEtFWQ&votefst%5B0%5D=0&votelst%5B0%5D=30000&votekd%5B0%5D=100" {
43
+ t .Error ("Link should be a known deeplink fee" )
44
+ }
45
+
46
+ }
47
+
11
48
func Test_ListParticipationKeys (t * testing.T ) {
12
49
ctx := context .Background ()
13
50
client , err := api .NewClientWithResponses ("https://mainnet-api.4160.nodely.dev:443" )
@@ -23,16 +60,9 @@ func Test_ListParticipationKeys(t *testing.T) {
23
60
}
24
61
25
62
// Setup elevated client
26
- apiToken , err := securityprovider .NewSecurityProviderApiKey ("header" , "X-Algo-API-Token" , "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
27
- if err != nil {
28
- t .Fatal (err )
29
- }
30
- client , err = api .NewClientWithResponses ("http://localhost:8080" , api .WithRequestEditorFn (apiToken .Intercept ))
31
- if err != nil {
32
- t .Fatal (err )
33
- }
63
+ tClient := test .GetClient (false )
34
64
35
- keys , err := GetPartKeys (ctx , client )
65
+ keys , err := GetPartKeys (ctx , tClient )
36
66
if err != nil {
37
67
t .Fatal (err )
38
68
}
@@ -54,25 +84,17 @@ func Test_ReadParticipationKey(t *testing.T) {
54
84
t .Fatal (err )
55
85
}
56
86
57
- // Setup elevated client
58
- apiToken , err := securityprovider .NewSecurityProviderApiKey ("header" , "X-Algo-API-Token" , "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
59
- if err != nil {
60
- t .Fatal (err )
61
- }
62
- client , err = api .NewClientWithResponses ("http://localhost:8080" , api .WithRequestEditorFn (apiToken .Intercept ))
63
- if err != nil {
64
- t .Fatal (err )
65
- }
87
+ tClient := test .GetClient (false )
66
88
67
- keys , err := GetPartKeys (ctx , client )
89
+ keys , err := GetPartKeys (ctx , tClient )
68
90
if err != nil {
69
91
t .Fatal (err )
70
92
}
71
93
if keys == nil {
72
94
t .Fatal (err )
73
95
}
74
96
75
- _ , err = ReadPartKey (ctx , client , (* keys )[0 ].Id )
97
+ _ , err = ReadPartKey (ctx , tClient , (* keys )[0 ].Id )
76
98
77
99
if err != nil {
78
100
t .Fatal (err )
@@ -88,31 +110,23 @@ func Test_GenerateParticipationKey(t *testing.T) {
88
110
if err != nil {
89
111
t .Fatal (err )
90
112
}
91
-
92
113
// Generate error
93
114
_ , err = GenerateKeyPair (ctx , client , "" , nil )
94
115
if err == nil {
95
116
t .Fatal (err )
96
117
}
97
118
98
- // Setup elevated client
99
- apiToken , err := securityprovider .NewSecurityProviderApiKey ("header" , "X-Algo-API-Token" , "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
100
- if err != nil {
101
- t .Fatal (err )
102
- }
103
- client , err = api .NewClientWithResponses ("http://localhost:8080" , api .WithRequestEditorFn (apiToken .Intercept ))
104
- if err != nil {
105
- t .Fatal (err )
106
- }
119
+ // Setup test client
120
+ tClient := test .GetClient (false )
107
121
108
122
params := api.GenerateParticipationKeysParams {
109
123
Dilution : nil ,
110
124
First : 0 ,
111
- Last : 10000 ,
125
+ Last : 30 ,
112
126
}
113
127
114
128
// This returns nothing and sucks
115
- key , err := GenerateKeyPair (ctx , client , "QNZ7GONNHTNXFW56Y24CNJQEMYKZKKI566ASNSWPD24VSGKJWHGO6QOP7U " , & params )
129
+ key , err := GenerateKeyPair (ctx , tClient , "ABC " , & params )
116
130
if err != nil {
117
131
t .Fatal (err )
118
132
}
@@ -121,21 +135,14 @@ func Test_GenerateParticipationKey(t *testing.T) {
121
135
122
136
func Test_DeleteParticipationKey (t * testing.T ) {
123
137
ctx := context .Background ()
124
- // Setup elevated client
125
- apiToken , err := securityprovider .NewSecurityProviderApiKey ("header" , "X-Algo-API-Token" , "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" )
126
- if err != nil {
127
- t .Fatal (err )
128
- }
129
- client , err := api .NewClientWithResponses ("http://localhost:8080" , api .WithRequestEditorFn (apiToken .Intercept ))
130
- if err != nil {
131
- t .Fatal (err )
132
- }
138
+
139
+ client := test .GetClient (false )
133
140
params := api.GenerateParticipationKeysParams {
134
141
Dilution : nil ,
135
142
First : 0 ,
136
- Last : 10000 ,
143
+ Last : 30000 ,
137
144
}
138
- key , err := GenerateKeyPair (ctx , client , "QNZ7GONNHTNXFW56Y24CNJQEMYKZKKI566ASNSWPD24VSGKJWHGO6QOP7U " , & params )
145
+ key , err := GenerateKeyPair (ctx , client , "ABC " , & params )
139
146
if err != nil {
140
147
t .Fatal (err )
141
148
}
0 commit comments