Add unit-tests for deterministic devnet keys (#1032)
* Add unit-tests for deterministic devnet keys * Extend unit-tests to do full deterministic key checks
This commit is contained in:
parent
5355f87206
commit
a709d6f283
|
@ -0,0 +1,32 @@
|
||||||
|
package devnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDeterministicEcdsaKeyByIndex(t *testing.T) {
|
||||||
|
type test struct {
|
||||||
|
index uint64
|
||||||
|
privKeyHex string
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []test{
|
||||||
|
{index: 0, privKeyHex: "cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0"},
|
||||||
|
{index: 1, privKeyHex: "c3b2e45c422a1602333a64078aeb42637370b0f48fe385f9cfa6ad54a8e0c47e"},
|
||||||
|
{index: 2, privKeyHex: "9f790d3f08bc4b5cd910d4278f3deb406e57bb5e924906ccd52052bb078ccd47"},
|
||||||
|
{index: 3, privKeyHex: "b20cc49d6f2c82a5e6519015fc18aa3e562867f85f872c58f1277cfbd2a0c8e4"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(fmt.Sprint(tc.index), func(t *testing.T) {
|
||||||
|
privKey := DeterministicEcdsaKeyByIndex(crypto.S256(), tc.index)
|
||||||
|
got := crypto.FromECDSA(privKey)
|
||||||
|
assert.Equal(t, tc.privKeyHex, hex.EncodeToString(got))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package devnet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDeterministicP2PPrivKeyByIndex(t *testing.T) {
|
||||||
|
type test struct {
|
||||||
|
index int64
|
||||||
|
privKeyHex string
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []test{
|
||||||
|
{index: 0, privKeyHex: "0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d0b7597f3bd871315281e8b83edc7a9fd0541066154449070ccdb3cdd42cf69ccde88"},
|
||||||
|
{index: 1, privKeyHex: "52fdfc072182654f163f5f0f9a621d729566c74d10037c4d7bbb0407d1e2c6496f1581709bb7b1ef030d210db18e3b0ba1c776fba65d8cdaad05415142d189f8"},
|
||||||
|
{index: 2, privKeyHex: "2f8282cbe2f9696f3144c0aa4ced56dbd967dc2897806af3bed8a63aca16e18b8ed90420802c83b41e4a7fa94ce5f05792ea8bff3d7a63572e5c73454eaef51d"},
|
||||||
|
{index: 3, privKeyHex: "85fbe72b6064289004a531f967898df5319ee02992fdd84021fa5052434bf6ee11bba3ed1721948cefb4e50b0a0bb5cad8a6b52dc7b1a40f4f6652105c91e2c4"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(fmt.Sprint(tc.index), func(t *testing.T) {
|
||||||
|
privKey := DeterministicP2PPrivKeyByIndex(tc.index)
|
||||||
|
got, _ := privKey.Raw()
|
||||||
|
assert.Equal(t, tc.privKeyHex, hex.EncodeToString(got))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue