Skip to content

Commit 4ca3c0d

Browse files
committed
add tst
1 parent 8b90b30 commit 4ca3c0d

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

node-registrar/tst/main.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package main
2+
3+
import (
4+
"encoding/hex"
5+
"net/url"
6+
"os"
7+
8+
"github.com/rs/zerolog"
9+
"github.com/rs/zerolog/log"
10+
"github.com/threefoldtech/tfgrid4-sdk-go/node-registrar/client"
11+
)
12+
13+
var localRegistrar = "http://192.168.68.85:8080"
14+
15+
func main() {
16+
// test flow:
17+
// - we need to create an account
18+
// - try to get the account by id and by pk
19+
// - try to update the account
20+
// - try to ensure account
21+
//
22+
// - then we create a farm with that twin
23+
// - try to get the farm
24+
// - try to update the farm
25+
//
26+
// - try to register a node
27+
// - try to update the node
28+
// - try to get the node
29+
// - try to send the node up time report
30+
// - try to the node by twin id
31+
32+
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
33+
34+
hexKey := "020b5f908e821446ad3b7efd3774605f55ee41aa017968e45bbb9c84c4ca18d2"
35+
36+
seed, err := hex.DecodeString(hexKey)
37+
if err != nil {
38+
log.Fatal().Err(err).Msg("failed to decode private key")
39+
}
40+
41+
baseURL, err := url.JoinPath(localRegistrar, "v1")
42+
if err != nil {
43+
log.Fatal().Err(err).Msg("failed to construct registrar url")
44+
}
45+
46+
c, err := client.NewRegistrarClient(baseURL, seed)
47+
if err != nil {
48+
log.Fatal().Err(err).Msg("failed to create new registrar client")
49+
}
50+
51+
// log.Info().Msg("test create account")
52+
// relays := []string{"relay1"}
53+
// rmbEncKey := "encKey"
54+
// account, err := c.CreateAccount(relays, rmbEncKey)
55+
// if err != nil {
56+
// log.Fatal().Err(err).Msg("failed to create new account on registrar")
57+
// }
58+
//
59+
// log.Info().Uint64("twinID", account.TwinID).Send()
60+
61+
// log.Info().Msg("test get account by public key")
62+
// privateKey := ed25519.NewKeyFromSeed(seed)
63+
// publicKey := privateKey.Public().(ed25519.PublicKey)
64+
// account, err := c.GetAccountByPK(publicKey)
65+
// if err != nil {
66+
// log.Fatal().Err(err).Msg("failed to get account from registrar")
67+
// }
68+
// log.Info().Any("account", account).Send()
69+
70+
// log.Info().Msg("test get account by twinID")
71+
// account, err = c.GetAccount(uint64(8))
72+
// if err != nil {
73+
// log.Fatal().Err(err).Msg("failed to get account from registrar")
74+
// }
75+
// log.Info().Any("account", account).Send()
76+
77+
relays := []string{"relay1"}
78+
rmbEncKey := "encKey"
79+
log.Info().Msg("test update account")
80+
err = c.UpdateAccount(client.UpdateAccountWithRelays(relays), client.UpdateAccountWithRMBEncKey(rmbEncKey))
81+
if err != nil {
82+
log.Fatal().Err(err).Msg("failed to get account from registrar")
83+
}
84+
log.Info().Msg("account updated successfully")
85+
}

0 commit comments

Comments
 (0)