pubkey_type_test.gno
1.43 Kb · 41 lines
1package valopers
2
3import (
4 "testing"
5
6 "gno.land/p/nt/uassert/v0"
7)
8
9const (
10 testEd25519PubKey = "gpub1pggj7ard9eg82cjtv4u52epjx56nzwgjyg9zqkn3nln2k8glpf9kpqtz4h63n7cd0jvxkq6rpk4dxzp4sq527mhqwv40hr"
11 testSecp256k1PubKey = "gpub1pgfj7ard9eg82cjtv4u4xetrwqer2dntxyfzxz3pq0skzdkmzu0r9h6gny6eg8c9dc303xrrudee6z4he4y7cs5rnjwmyf40yaj"
12)
13
14func TestPubKeyTypeURL(t *testing.T) {
15 got, err := pubKeyTypeURL(testEd25519PubKey)
16 uassert.NoError(t, err)
17 uassert.Equal(t, "/tm.PubKeyEd25519", got)
18
19 got, err = pubKeyTypeURL(testSecp256k1PubKey)
20 uassert.NoError(t, err)
21 uassert.Equal(t, "/tm.PubKeySecp256k1", got)
22
23 _, err = pubKeyTypeURL("not-a-valid-bech32-pubkey")
24 uassert.Error(t, err)
25}
26
27func TestAssertPubKeyTypeAllowed(t *testing.T) {
28 // Empty allow-list accepts any well-formed type.
29 testing.SetSysParamStrings("node", "valset", "pubkey_types", []string{})
30 uassert.NotPanics(t, cur, func() { assertPubKeyTypeAllowed(testSecp256k1PubKey) })
31
32 // ed25519-only allow-list: ed25519 accepted, secp256k1 rejected.
33 testing.SetSysParamStrings("node", "valset", "pubkey_types", []string{"/tm.PubKeyEd25519"})
34 uassert.NotPanics(t, cur, func() { assertPubKeyTypeAllowed(testEd25519PubKey) })
35 uassert.PanicsWithMessage(t, cur, ErrDisallowedPubKeyType.Error(), func() {
36 assertPubKeyTypeAllowed(testSecp256k1PubKey)
37 })
38
39 // Reset so the non-empty allow-list doesn't leak into other tests.
40 testing.SetSysParamStrings("node", "valset", "pubkey_types", []string{})
41}