Skip to content

Commit

Permalink
account is now simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
Thykof committed Oct 12, 2023
1 parent 45a57fd commit d8d0bb2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/walletmanager/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (w *Wallet) Load(filePath string) (*account.Account, error) {
return nil, fmt.Errorf("reading wallet from '%s': %w", filePath, err)
}

acc := account.NewEmpty()
acc := account.Account{}
err = acc.Unmarshal(data)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrUnmarshalAccount, err)
Expand All @@ -95,8 +95,8 @@ func (w *Wallet) Load(filePath string) (*account.Account, error) {
}

// Address in the file is optional, if it's not set, we use the public key
if acc.Address.Object.Data == nil {
acc.Address = *types.NewAddressFromPublicKey(&acc.PublicKey)
if acc.Address == nil || acc.Address.Object == nil || acc.Address.Object.Data == nil {
acc.Address = types.NewAddressFromPublicKey(acc.PublicKey)
}

return &acc, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/walletmanager/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (w *Wallet) NicknameIsUnique(nickname string) error {
return nil
}

func (w *Wallet) AddressIsUnique(address types.Address) error {
func (w *Wallet) AddressIsUnique(address *types.Address) error {
for _, account := range w.accounts {
if bytes.Equal(account.Address.Data, address.Data) {
return ErrAddressNotUnique
Expand Down
8 changes: 4 additions & 4 deletions pkg/walletmanager/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestWallet(t *testing.T) {
sampleNonce := [12]byte{113, 122, 168, 123, 48, 187, 178, 12, 209, 91, 243, 63}
sampleNickname := "bonjour2"
sampleAccount, err := account.New(
&[]uint8{account.AccountLastVersion}[0],
uint8(account.AccountLastVersion),
sampleNickname,
&types.Address{
Object: &object.Object{
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestWallet(t *testing.T) {

t.Run("Add Account: address not unique", func(t *testing.T) {
sampleAccount, err := account.New(
&[]uint8{account.AccountLastVersion}[0],
uint8(account.AccountLastVersion),
"bonjour3",
&types.Address{
Object: &object.Object{
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestWallet(t *testing.T) {
acc, err := w.GetAccount(sampleNickname)
assert.NoError(t, err)
assert.NotNil(t, acc)
assert.Equal(t, uint8(1), *acc.Version)
assert.Equal(t, uint8(1), acc.Version)
assert.Equal(t, sampleNickname, acc.Nickname)
assert.Equal(t, sampleSalt, acc.Salt)
assert.Equal(t, sampleNonce, acc.Nonce)
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestWallet(t *testing.T) {
copy(t, "../../tests/wallet_unit-test.yaml", accountPath)

acc := assertAccountIsPresent(t, w, nickname)
assert.Equal(t, uint8(1), *acc.Version)
assert.Equal(t, uint8(1), acc.Version)
assert.Equal(t, 2, w.GetAccountCount())
})

Expand Down

0 comments on commit d8d0bb2

Please sign in to comment.