Skip to content

Commit

Permalink
test: add check address path in TestNewED25519AccountAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
mj committed Aug 23, 2024
1 parent 8b12e56 commit b774da5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
30 changes: 16 additions & 14 deletions wallet/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,24 @@ func TestNewBLSAccountAddress(t *testing.T) {
func TestNewED25519AccountAddress(t *testing.T) {

Check failure on line 234 in wallet/vault/vault_test.go

View workflow job for this annotation

GitHub Actions / build-linux

empty-lines: extra empty line at the end of a block (revive)

Check failure on line 234 in wallet/vault/vault_test.go

View workflow job for this annotation

GitHub Actions / linting

empty-lines: extra empty line at the end of a block (revive)
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)
})
}

Check failure on line 255 in wallet/vault/vault_test.go

View workflow job for this annotation

GitHub Actions / build-linux

unnecessary trailing newline (whitespace)

Check failure on line 255 in wallet/vault/vault_test.go

View workflow job for this annotation

GitHub Actions / linting

unnecessary trailing newline (whitespace)

func TestNewValidatorAddress(t *testing.T) {
Expand Down
8 changes: 7 additions & 1 deletion wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const (
AddressTypeValidator string = "validator"
)

const (
VERSION_1 = 1 // initial version

Check failure on line 28 in wallet/wallet.go

View workflow job for this annotation

GitHub Actions / build-linux

var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive)

Check failure on line 28 in wallet/wallet.go

View workflow job for this annotation

GitHub Actions / linting

var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive)
VERSION_2 = 2 // supporting Ed25519 =

Check failure on line 29 in wallet/wallet.go

View workflow job for this annotation

GitHub Actions / build-linux

var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive)

Check failure on line 29 in wallet/wallet.go

View workflow job for this annotation

GitHub Actions / linting

var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive)
)

type Wallet struct {
store *store
path string
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b774da5

Please sign in to comment.