Skip to content

Commit

Permalink
chore_: replace geth logger with zap logger
Browse files Browse the repository at this point in the history
closes: #6002
  • Loading branch information
osmaczko committed Oct 28, 2024
1 parent d77d243 commit df082f6
Show file tree
Hide file tree
Showing 155 changed files with 2,315 additions and 1,629 deletions.
8 changes: 5 additions & 3 deletions account/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"time"

"github.com/google/uuid"
"go.uber.org/zap"

gethkeystore "github.com/ethereum/go-ethereum/accounts/keystore"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/account/generator"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/keystore"
Expand Down Expand Up @@ -100,6 +100,8 @@ type DefaultManager struct {
selectedChatAccount *SelectedExtKey // account that was processed during the last call to SelectAccount()
mainAccountAddress types.Address
watchAddresses []types.Address

logger *zap.Logger
}

// GetKeystore is only used in tests
Expand Down Expand Up @@ -642,13 +644,13 @@ func (m *DefaultManager) ReEncryptKeyStoreDir(keyDirPath, oldPass, newPass strin
err = os.RemoveAll(tempKeyDirPath)
if err != nil {
// the re-encryption is complete so we don't throw
log.Error("unable to delete tempKeyDirPath, manual cleanup required")
m.logger.Error("unable to delete tempKeyDirPath, manual cleanup required")

Check warning on line 647 in account/accounts.go

View check run for this annotation

Codecov / codecov/patch

account/accounts.go#L647

Added line #L647 was not covered by tests
}

err = os.RemoveAll(backupKeyDirPath)
if err != nil {
// the re-encryption is complete so we don't throw
log.Error("unable to delete backupKeyDirPath, manual cleanup required")
m.logger.Error("unable to delete backupKeyDirPath, manual cleanup required")

Check warning on line 653 in account/accounts.go

View check run for this annotation

Codecov / codecov/patch

account/accounts.go#L653

Added line #L653 was not covered by tests
}

return nil
Expand Down
9 changes: 7 additions & 2 deletions account/accounts_geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package account
import (
"time"

"go.uber.org/zap"

"github.com/ethereum/go-ethereum/accounts"

"github.com/status-im/status-go/account/generator"
Expand All @@ -17,9 +19,12 @@ type GethManager struct {
}

// NewGethManager returns new node account manager.
func NewGethManager() *GethManager {
func NewGethManager(logger *zap.Logger) *GethManager {
m := &GethManager{}
m.DefaultManager = &DefaultManager{accountsGenerator: generator.New(m)}
m.DefaultManager = &DefaultManager{
accountsGenerator: generator.New(m),
logger: logger,
}
return m
}

Expand Down
7 changes: 4 additions & 3 deletions account/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/keystore"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/t/utils"

"github.com/stretchr/testify/require"
Expand All @@ -21,7 +22,7 @@ const testPassword = "test-password"
const newTestPassword = "new-test-password"

func TestVerifyAccountPassword(t *testing.T) {
accManager := NewGethManager()
accManager := NewGethManager(tt.MustCreateTestLogger())
keyStoreDir := t.TempDir()
emptyKeyStoreDir := t.TempDir()

Expand Down Expand Up @@ -103,7 +104,7 @@ func TestVerifyAccountPasswordWithAccountBeforeEIP55(t *testing.T) {
err := utils.ImportTestAccount(keyStoreDir, "test-account3-before-eip55.pk")
require.NoError(t, err)

accManager := NewGethManager()
accManager := NewGethManager(tt.MustCreateTestLogger())

address := types.HexToAddress(utils.TestConfig.Account3.WalletAddress)
_, err = accManager.VerifyAccountPassword(keyStoreDir, address.Hex(), utils.TestConfig.Account3.Password)
Expand Down Expand Up @@ -133,7 +134,7 @@ type testAccount struct {
// SetupTest is used here for reinitializing the mock before every
// test function to avoid faulty execution.
func (s *ManagerTestSuite) SetupTest() {
s.accManager = NewGethManager()
s.accManager = NewGethManager(tt.MustCreateTestLogger())

keyStoreDir := s.T().TempDir()
s.Require().NoError(s.accManager.InitKeystore(keyStoreDir))
Expand Down
51 changes: 31 additions & 20 deletions api/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/status-im/status-go/node"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/typeddata"
"github.com/status-im/status-go/services/wallet"
Expand Down Expand Up @@ -95,7 +96,10 @@ func setupGethStatusBackend() (*GethStatusBackend, func() error, func() error, f
if err != nil {
return nil, nil, nil, nil, err
}
backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())
if err != nil {
return nil, nil, nil, nil, err
}
backend.StatusNode().SetAppDB(db)

ma, stop2, err := setupTestMultiDB()
Expand Down Expand Up @@ -292,7 +296,8 @@ func TestBackendGettersConcurrently(t *testing.T) {

func TestBackendConnectionChangesConcurrently(t *testing.T) {
connections := [...]string{connection.Wifi, connection.Cellular, connection.Unknown}
backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())

count := 3

var wg sync.WaitGroup
Expand All @@ -310,7 +315,8 @@ func TestBackendConnectionChangesConcurrently(t *testing.T) {
}

func TestBackendConnectionChangesToOffline(t *testing.T) {
b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())

b.ConnectionChange(connection.None, false)
assert.True(t, b.connectionState.Offline)

Expand Down Expand Up @@ -386,7 +392,7 @@ func TestBackendCallRPCConcurrently(t *testing.T) {
}

func TestAppStateChange(t *testing.T) {
backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())

var testCases = []struct {
name string
Expand Down Expand Up @@ -460,7 +466,7 @@ func TestBlockedRPCMethods(t *testing.T) {
}

func TestCallRPCWithStoppedNode(t *testing.T) {
backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())

resp, err := backend.CallRPC(
`{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}`,
Expand Down Expand Up @@ -699,7 +705,8 @@ func TestBackendGetVerifiedAccount(t *testing.T) {
func TestRuntimeLogLevelIsNotWrittenToDatabase(t *testing.T) {
utils.Init()

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())

chatKey, err := gethcrypto.GenerateKey()
require.NoError(t, err)
walletKey, err := gethcrypto.GenerateKey()
Expand Down Expand Up @@ -767,7 +774,8 @@ func TestRuntimeLogLevelIsNotWrittenToDatabase(t *testing.T) {
func TestLoginWithKey(t *testing.T) {
utils.Init()

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())

chatKey, err := gethcrypto.GenerateKey()
require.NoError(t, err)
walletKey, err := gethcrypto.GenerateKey()
Expand Down Expand Up @@ -825,7 +833,8 @@ func TestLoginAccount(t *testing.T) {
tmpdir := t.TempDir()
nameserver := "8.8.8.8"

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())

createAccountRequest := &requests.CreateAccount{
DisplayName: "some-display-name",
CustomizationColor: "#ffffff",
Expand Down Expand Up @@ -883,7 +892,8 @@ func TestLoginAccount(t *testing.T) {
func TestVerifyDatabasePassword(t *testing.T) {
utils.Init()

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())

chatKey, err := gethcrypto.GenerateKey()
require.NoError(t, err)
walletKey, err := gethcrypto.GenerateKey()
Expand Down Expand Up @@ -921,7 +931,7 @@ func TestVerifyDatabasePassword(t *testing.T) {
}

func TestDeleteMultiaccount(t *testing.T) {
backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())

rootDataDir := t.TempDir()

Expand Down Expand Up @@ -1280,7 +1290,7 @@ func loginDesktopUser(t *testing.T, conf *params.NodeConfig) {
username := "TestUser"
passwd := "0xC888C9CE9E098D5864D3DED6EBCC140A12142263BACE3A23A36F9905F12BD64A" // #nosec G101

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())

require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
b.UpdateRootDataDir(conf.DataDir)
Expand Down Expand Up @@ -1329,7 +1339,7 @@ func TestChangeDatabasePassword(t *testing.T) {
oldPassword := "password"
newPassword := "newPassword"

backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())
backend.UpdateRootDataDir(t.TempDir())

// Setup keystore to test decryption of it
Expand Down Expand Up @@ -1386,7 +1396,7 @@ func TestCreateWallet(t *testing.T) {
password := "some-password2" // nolint: goconst
tmpdir := t.TempDir()

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())
defer func() {
require.NoError(t, b.StopNode())
}()
Expand Down Expand Up @@ -1451,7 +1461,7 @@ func TestSetFleet(t *testing.T) {
password := "some-password2" // nolint: goconst
tmpdir := t.TempDir()

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())
createAccountRequest := &requests.CreateAccount{
DisplayName: "some-display-name",
CustomizationColor: "#ffffff",
Expand Down Expand Up @@ -1520,7 +1530,7 @@ func TestWalletConfigOnLoginAccount(t *testing.T) {
raribleMainnetAPIKey := "rarible-mainnet-api-key" // nolint: gosec
raribleTestnetAPIKey := "rarible-testnet-api-key" // nolint: gosec

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())
createAccountRequest := &requests.CreateAccount{
DisplayName: "some-display-name",
CustomizationColor: "#ffffff",
Expand Down Expand Up @@ -1585,7 +1595,7 @@ func TestTestnetEnabledSettingOnCreateAccount(t *testing.T) {
utils.Init()
tmpdir := t.TempDir()

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())

// Creating an account with test networks enabled
createAccountRequest1 := &requests.CreateAccount{
Expand Down Expand Up @@ -1631,7 +1641,7 @@ func TestRestoreAccountAndLogin(t *testing.T) {
utils.Init()
tmpdir := t.TempDir()

backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())

// Test case 1: Valid restore account request
restoreRequest := &requests.RestoreAccount{
Expand Down Expand Up @@ -1666,7 +1676,7 @@ func TestRestoreAccountAndLoginWithoutDisplayName(t *testing.T) {
utils.Init()
tmpdir := t.TempDir()

backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())

// Test case: Valid restore account request without DisplayName
restoreRequest := &requests.RestoreAccount{
Expand All @@ -1687,7 +1697,7 @@ func TestRestoreAccountAndLoginWithoutDisplayName(t *testing.T) {

func TestAcceptTerms(t *testing.T) {
tmpdir := t.TempDir()
b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())
conf, err := params.NewNodeConfig(tmpdir, 1777)
require.NoError(t, err)
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
Expand Down Expand Up @@ -1850,7 +1860,8 @@ func TestRestoreKeycardAccountAndLogin(t *testing.T) {
conf, err := params.NewNodeConfig(tmpdir, 1777)
require.NoError(t, err)

backend := NewGethStatusBackend()
backend := NewGethStatusBackend(tt.MustCreateTestLogger())
require.NoError(t, err)

require.NoError(t, backend.AccountManager().InitKeystore(conf.KeyStoreDir))
backend.UpdateRootDataDir(conf.DataDir)
Expand Down
3 changes: 2 additions & 1 deletion api/create_account_and_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/protocol/tt"
)

func TestCreateAccountAndLogin(t *testing.T) {
Expand Down Expand Up @@ -43,7 +44,7 @@ func TestCreateAccountAndLogin(t *testing.T) {
var request requests.CreateAccount
err := json.Unmarshal([]byte(requestJSON), &request)
require.NoError(t, err)
statusBackend := NewGethStatusBackend()
statusBackend := NewGethStatusBackend(tt.MustCreateTestLogger())
_, err = statusBackend.CreateAccountAndLogin(&request)
require.NoError(t, err)
t.Logf("TestCreateAccountAndLogin: create account user1 and login successfully")
Expand Down
Loading

0 comments on commit df082f6

Please sign in to comment.