MCPcopy
hub / github.com/canopy-network/canopy / TestEthSECP256K1Bytes

Function TestEthSECP256K1Bytes

lib/crypto/eth_secp256k1_test.go:11–39  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestEthSECP256K1Bytes(t *testing.T) {
12 // private key testing
13 privateKey, err := NewETHSECP256K1PrivateKey()
14 if err != nil {
15 t.Fatal(err)
16 }
17 privKeyBz := privateKey.Bytes()
18 privateKey2, err := BytesToSECP256K1Private(privKeyBz)
19 require.NoError(t, err)
20 if !privateKey.Equals(privateKey2) {
21 t.Fatalf("wanted %s, got %s", privateKey, privateKey2)
22 }
23 // public key testing
24 pubKey := privateKey.PublicKey()
25 pubKeyBz := pubKey.Bytes()
26 fmt.Println(len(pubKeyBz), hex.EncodeToString(pubKeyBz))
27 pubKey2, err := BytesToEthSECP256K1Public(pubKeyBz)
28 require.NoError(t, err)
29 if !pubKey.Equals(pubKey2) {
30 t.Fatalf("wanted %s got %s", pubKey, pubKey2)
31 }
32 // address testing
33 address := pubKey.Address()
34 addressBz := address.Bytes()
35 address2 := NewAddressFromBytes(addressBz)
36 if !address.Equals(address2) {
37 t.Fatalf("wanted %s got %s", address, address2)
38 }
39}
40
41func TestEthSECP256K1SignAndVerify(t *testing.T) {
42 // create the private key

Callers

nothing calls this directly

Calls 10

PublicKeyMethod · 0.95
BytesToSECP256K1PrivateFunction · 0.85
NewAddressFromBytesFunction · 0.85
FatalMethod · 0.65
BytesMethod · 0.65
EqualsMethod · 0.65
FatalfMethod · 0.65
AddressMethod · 0.65

Tested by

no test coverage detected