File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ package blockchain
2+
3+ import (
4+ "encoding/json"
5+ "testing"
6+
7+ "github.com/mr-tron/base58"
8+ )
9+
10+ // TestDefaultSolanaKeypairConsistency verifies that the exported DefaultSolanaPrivateKey
11+ // and DefaultSolanaPublicKey constants stay in sync with the idJSONRaw keypair bytes
12+ // written to the test validator's identity file.
13+ // Uses mr-tron/base58 (transitive dep via solana-go) to avoid vendoring base58 encoding.
14+ func TestDefaultSolanaKeypairConsistency (t * testing.T ) {
15+ // Parse idJSONRaw into byte slice
16+ var raw []byte
17+ if err := json .Unmarshal ([]byte (idJSONRaw ), & raw ); err != nil {
18+ t .Fatalf ("failed to parse idJSONRaw: %v" , err )
19+ }
20+ if len (raw ) != 64 {
21+ t .Fatalf ("expected 64-byte keypair, got %d bytes" , len (raw ))
22+ }
23+
24+ // Full keypair (64 bytes) base58-encoded should match DefaultSolanaPrivateKey
25+ if got := base58 .Encode (raw ); got != DefaultSolanaPrivateKey {
26+ t .Errorf ("DefaultSolanaPrivateKey mismatch\n got: %s\n want: %s" , got , DefaultSolanaPrivateKey )
27+ }
28+
29+ // Last 32 bytes (public key) base58-encoded should match DefaultSolanaPublicKey
30+ if got := base58 .Encode (raw [32 :]); got != DefaultSolanaPublicKey {
31+ t .Errorf ("DefaultSolanaPublicKey mismatch\n got: %s\n want: %s" , got , DefaultSolanaPublicKey )
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ require (
2727 github.com/google/uuid v1.6.0
2828 github.com/hashicorp/consul/sdk v0.16.2
2929 github.com/minio/minio-go/v7 v7.0.86
30+ github.com/mr-tron/base58 v1.2.0
3031 github.com/pelletier/go-toml v1.9.5
3132 github.com/pelletier/go-toml/v2 v2.2.3
3233 github.com/pkg/errors v0.9.1
Original file line number Diff line number Diff line change @@ -618,6 +618,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
618618github.com/modern-go/reflect2 v1.0.2 /go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk =
619619github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A =
620620github.com/morikuni/aec v1.0.0 /go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc =
621+ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o =
622+ github.com/mr-tron/base58 v1.2.0 /go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc =
621623github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA =
622624github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 /go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ =
623625github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223 /go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U =
You can’t perform that action at this time.
0 commit comments