Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding address field for AccountInfo #703

Merged
merged 4 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion state/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type Facade interface {
BlockHash(height uint32) hash.Hash
BlockHeight(hash hash.Hash) uint32
AccountByAddress(addr crypto.Address) *account.Account
AccountByNumber(number int32) *account.Account
ValidatorByAddress(addr crypto.Address) *validator.Validator
ValidatorByNumber(number int32) *validator.Validator
ValidatorAddresses() []crypto.Address
Expand Down
8 changes: 0 additions & 8 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,6 @@ func (st *state) AccountByAddress(addr crypto.Address) *account.Account {
return acc
}

func (st *state) AccountByNumber(number int32) *account.Account {
acc, err := st.store.AccountByNumber(number)
if err != nil {
st.logger.Trace("error on retrieving account", "error", err)
}
return acc
}

func (st *state) ValidatorAddresses() []crypto.Address {
return st.store.ValidatorAddresses()
}
Expand Down
9 changes: 0 additions & 9 deletions store/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ func (as *accountStore) account(addr crypto.Address) (*account.Account, error) {
return nil, ErrNotFound
}

func (as *accountStore) accountByNumber(number int32) (*account.Account, error) {
acc, ok := as.numberMap[number]
kehiy marked this conversation as resolved.
Show resolved Hide resolved
if ok {
return acc.Clone(), nil
}

return nil, ErrNotFound
}

func (as *accountStore) iterateAccounts(consumer func(crypto.Address, *account.Account) (stop bool)) {
for addr, acc := range as.addressMap {
stopped := consumer(addr, acc.Clone())
Expand Down
60 changes: 2 additions & 58 deletions store/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ func TestAccountCounter(t *testing.T) {
acc1, err := td.store.Account(signer.Address())
assert.NoError(t, err)

acc2, err := td.store.AccountByNumber(num)
assert.NoError(t, err)

assert.Equal(t, acc1.Hash(), acc2.Hash())
assert.Equal(t, acc1.Hash(), acc.Hash())
assert.Equal(t, td.store.TotalAccounts(), int32(1))
assert.True(t, td.store.HasAccount(signer.Address()))
})
Expand All @@ -65,55 +62,6 @@ func TestAccountBatchSaving(t *testing.T) {
})
}

func TestAccountByNumber(t *testing.T) {
td := setup(t)

total := td.RandInt32NonZero(100)
t.Run("Add some accounts", func(t *testing.T) {
for i := int32(0); i < total; i++ {
acc, signer := td.GenerateTestAccount(i)
td.store.UpdateAccount(signer.Address(), acc)
}
assert.NoError(t, td.store.WriteBatch())
assert.Equal(t, td.store.TotalAccounts(), total)
})

t.Run("Get a random account", func(t *testing.T) {
num := td.RandInt32(total)
acc, err := td.store.AccountByNumber(num)
assert.NoError(t, err)
require.NotNil(t, acc)
assert.Equal(t, acc.Number(), num)
})

t.Run("negative number", func(t *testing.T) {
acc, err := td.store.AccountByNumber(-1)
assert.Error(t, err)
assert.Nil(t, acc)
})

t.Run("Non existing account", func(t *testing.T) {
acc, err := td.store.AccountByNumber(total + 1)
assert.Error(t, err)
assert.Nil(t, acc)
})

t.Run("Reopen the store", func(t *testing.T) {
td.store.Close()
store, _ := NewStore(td.store.config, 21)

num := td.RandInt32(total)
acc, err := store.AccountByNumber(num)
assert.NoError(t, err)
require.NotNil(t, acc)
assert.Equal(t, acc.Number(), num)

acc, err = td.store.AccountByNumber(total + 1)
assert.Error(t, err)
assert.Nil(t, acc)
})
}

func TestAccountByAddress(t *testing.T) {
td := setup(t)

Expand Down Expand Up @@ -190,11 +138,7 @@ func TestAccountDeepCopy(t *testing.T) {
acc1, signer := td.GenerateTestAccount(num)
td.store.UpdateAccount(signer.Address(), acc1)

acc2, _ := td.store.AccountByNumber(num)
acc2, _ := td.store.Account(signer.Address())
acc2.AddToBalance(1)
assert.NotEqual(t, td.store.accountStore.numberMap[num].Hash(), acc2.Hash())

acc3, _ := td.store.Account(signer.Address())
acc3.AddToBalance(1)
assert.NotEqual(t, td.store.accountStore.numberMap[num].Hash(), acc3.Hash())
}
1 change: 0 additions & 1 deletion store/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type Reader interface {
PublicKey(addr crypto.Address) (*bls.PublicKey, error)
HasAccount(crypto.Address) bool
Account(addr crypto.Address) (*account.Account, error)
AccountByNumber(number int32) (*account.Account, error)
TotalAccounts() int32
HasValidator(addr crypto.Address) bool
ValidatorAddresses() []crypto.Address
Expand Down
7 changes: 0 additions & 7 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,6 @@ func (s *store) Account(addr crypto.Address) (*account.Account, error) {
return s.accountStore.account(addr)
}

func (s *store) AccountByNumber(number int32) (*account.Account, error) {
s.lk.RLock()
defer s.lk.RUnlock()

return s.accountStore.accountByNumber(number)
}

func (s *store) TotalAccounts() int32 {
s.lk.Lock()
defer s.lk.Unlock()
Expand Down
Loading