From b774da5a925d54db8461e11746542daf6113b3b4 Mon Sep 17 00:00:00 2001 From: mj Date: Fri, 23 Aug 2024 22:15:25 +0330 Subject: [PATCH] test: add check address path in TestNewED25519AccountAddress --- wallet/vault/vault_test.go | 30 ++++++++++++++++-------------- wallet/wallet.go | 8 +++++++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/wallet/vault/vault_test.go b/wallet/vault/vault_test.go index 3780db21f..4a5c1ed89 100644 --- a/wallet/vault/vault_test.go +++ b/wallet/vault/vault_test.go @@ -234,22 +234,24 @@ func TestNewBLSAccountAddress(t *testing.T) { func TestNewED25519AccountAddress(t *testing.T) { td := setup(t) - t.Run("Ok", func(t *testing.T) { - addressInfo, err := td.vault.NewEd25519AccountAddress("addr-1", tPassword) - assert.NoError(t, err) - assert.NotEmpty(t, addressInfo.Address) - assert.NotEmpty(t, addressInfo.PublicKey) + addressInfo, err := td.vault.NewEd25519AccountAddress("addr-1", tPassword) + assert.NoError(t, err) + assert.NotEmpty(t, addressInfo.Address) + assert.NotEmpty(t, addressInfo.PublicKey) + assert.Equal(t, "m/44'/21888'/3'/0'", addressInfo.Path) - addressInfo, err = td.vault.NewEd25519AccountAddress("addr-2", tPassword) - assert.NoError(t, err) - assert.NotEmpty(t, addressInfo.Address) - assert.NotEmpty(t, addressInfo.PublicKey) + addressInfo, err = td.vault.NewEd25519AccountAddress("addr-2", tPassword) + assert.NoError(t, err) + assert.NotEmpty(t, addressInfo.Address) + assert.NotEmpty(t, addressInfo.PublicKey) + assert.Equal(t, "m/44'/21888'/3'/1'", addressInfo.Path) + + addressInfo, err = td.vault.NewEd25519AccountAddress("addr-3", tPassword) + assert.NoError(t, err) + assert.NotEmpty(t, addressInfo.Address) + assert.NotEmpty(t, addressInfo.PublicKey) + assert.Equal(t, "m/44'/21888'/3'/2'", addressInfo.Path) - addressInfo, err = td.vault.NewEd25519AccountAddress("addr-3", tPassword) - assert.NoError(t, err) - assert.NotEmpty(t, addressInfo.Address) - assert.NotEmpty(t, addressInfo.PublicKey) - }) } func TestNewValidatorAddress(t *testing.T) { diff --git a/wallet/wallet.go b/wallet/wallet.go index 45af95a52..79bf49a8c 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -24,6 +24,11 @@ const ( AddressTypeValidator string = "validator" ) +const ( + VERSION_1 = 1 // initial version + VERSION_2 = 2 // supporting Ed25519 = +) + type Wallet struct { store *store path string @@ -96,7 +101,7 @@ func Create(walletPath, mnemonic, password string, chain genesis.ChainType, opti } store := &store{ - Version: 2, // Supporting Ed25519 + Version: VERSION_2, UUID: uuid.New(), CreatedAt: time.Now().Round(time.Second).UTC(), Network: chain, @@ -405,6 +410,7 @@ func (w *Wallet) NewBLSAccountAddress(label string) (*vault.AddressInfo, error) // NewEd25519AccountAddress create a new Ed25519-based account address and // associates it with the given label. +// The password is required to access the master private key needed for address generation. func (w *Wallet) NewEd25519AccountAddress(label, password string) (*vault.AddressInfo, error) { return w.store.Vault.NewEd25519AccountAddress(label, password) }