From f20cee2ccfdf86fa8c2069905c30861ec29bca56 Mon Sep 17 00:00:00 2001 From: JukLee0ira Date: Thu, 16 Jan 2025 20:19:51 +0800 Subject: [PATCH] accounts/keystore: add test case for prefix bug fix --- accounts/keystore/keystore_plain_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/accounts/keystore/keystore_plain_test.go b/accounts/keystore/keystore_plain_test.go index 6c0aa82f75a1e..ecc380ce13bf6 100644 --- a/accounts/keystore/keystore_plain_test.go +++ b/accounts/keystore/keystore_plain_test.go @@ -253,6 +253,25 @@ func TestKeyForDirectICAP(t *testing.T) { } } +func TestNewKeyForDirectICAP(t *testing.T) { + addr0 := common.HexToAddress("0x00ffffffffffffffffffffffffffffffffffffff") + addr1 := common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff") + tests := []struct { + name string + result bool + }{ + {"addresses start with 0", addr0[0] == 0}, + {"addresses not start with 0", addr1[0] != 0}, + {"addr0 starts 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) + } + } +} + func TestV3_31_Byte_Key(t *testing.T) { t.Skip("This test does not ") t.Parallel()