mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-07 13:34:27 +00:00
Merge pull request #814 from JukLee0ira/fix-perfix
accounts/keystore: fix xdc-prefix address bug
This commit is contained in:
commit
ff923bdca6
2 changed files with 22 additions and 4 deletions
|
|
@ -25,7 +25,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/accounts"
|
"github.com/XinFinOrg/XDPoSChain/accounts"
|
||||||
|
|
@ -151,7 +150,7 @@ func NewKeyForDirectICAP(rand io.Reader) *Key {
|
||||||
panic("key generation: ecdsa.GenerateKey failed: " + err.Error())
|
panic("key generation: ecdsa.GenerateKey failed: " + err.Error())
|
||||||
}
|
}
|
||||||
key := newKeyFromECDSA(privateKeyECDSA)
|
key := newKeyFromECDSA(privateKeyECDSA)
|
||||||
if !strings.HasPrefix(key.Address.Hex(), "0x00") {
|
if key.Address[0] != 0 {
|
||||||
return NewKeyForDirectICAP(rand)
|
return NewKeyForDirectICAP(rand)
|
||||||
}
|
}
|
||||||
return key
|
return key
|
||||||
|
|
|
||||||
|
|
@ -248,8 +248,27 @@ func TestKeyForDirectICAP(t *testing.T) {
|
||||||
t.Skip("NewKeyForDirectICAP in this test is invalid, will fall into a infinite loop ")
|
t.Skip("NewKeyForDirectICAP in this test is invalid, will fall into a infinite loop ")
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
key := NewKeyForDirectICAP(rand.Reader)
|
key := NewKeyForDirectICAP(rand.Reader)
|
||||||
if !strings.HasPrefix(key.Address.Hex(), "0x00") {
|
if key.Address[0] != 0 {
|
||||||
t.Errorf("Expected first address byte to be zero, have: %s", key.Address.Hex())
|
t.Errorf("Expected first address byte to be zero, have: %x", key.Address[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewKeyForDirectICAP(t *testing.T) {
|
||||||
|
addr0 := common.HexToAddress("0x00ffffffffffffffffffffffffffffffffffffff")
|
||||||
|
addr1 := common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff")
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
result bool
|
||||||
|
}{
|
||||||
|
{"addr0 start with 0", addr0[0] == 0},
|
||||||
|
{"addr1 not start with 0", addr1[0] != 0},
|
||||||
|
{"addr0 start with 0x00 or xdc00", strings.HasPrefix(addr0.Hex(), "0x00") || strings.HasPrefix(addr0.Hex(), "xdc00")},
|
||||||
|
{"addr1 not start with 0x00 nor xdc00", !strings.HasPrefix(addr1.Hex(), "0x00") && !strings.HasPrefix(addr1.Hex(), "xdc00")},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
if !tt.result {
|
||||||
|
t.Errorf("test %q failed\n", tt.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue