Skip to content

Commit

Permalink
accounts/keystore: add test case for prefix bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Jan 22, 2025
1 parent 13276e0 commit e3b62a9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions accounts/keystore/keystore_plain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package keystore

import (
"bytes"
"crypto/ecdsa"
"crypto/rand"
"encoding/hex"
"fmt"
Expand Down Expand Up @@ -253,6 +255,40 @@ func TestKeyForDirectICAP(t *testing.T) {
}
}

func TestNewKeyForDirectICAP(t *testing.T) {
randBytes := make([]byte, 64)
_, err := rand.Read(randBytes)
if err != nil {
panic("key generation: could not read from random source: " + err.Error())
}
reader := bytes.NewReader(randBytes)
privateKeyECDSA, err := ecdsa.GenerateKey(crypto.S256(), reader)
if err != nil {
panic("key generation: ecdsa.GenerateKey failed: " + err.Error())
}
key := newKeyFromECDSA(privateKeyECDSA)

tests := []struct {
setFirstByte byte
isRecursion bool
expectedError string
}{
{1, true, "failed to enter recursion: should recursively call NewKeyForDirectICAP until address meets Direct ICAP spec"},
{0, false, "address starts with 0 but in recursion mode"},
}
for _, tt := range tests {
key.Address[0] = tt.setFirstByte
isRecursion := false

if key.Address[0] != 0 { // xdc prefix can also be used for this comparison
isRecursion = true
}
if key.Address[0] == tt.setFirstByte && isRecursion != tt.isRecursion {
t.Errorf("%s", tt.expectedError)
}
}
}

func TestV3_31_Byte_Key(t *testing.T) {
t.Skip("This test does not ")
t.Parallel()
Expand Down

0 comments on commit e3b62a9

Please sign in to comment.