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 fdba6cb
Show file tree
Hide file tree
Showing 155 changed files with 2,335 additions and 1,631 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")
}

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")
}

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
73 changes: 51 additions & 22 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,9 @@ func TestBackendGettersConcurrently(t *testing.T) {

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

count := 3

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

rootDataDir := t.TempDir()

keyStoreDir := filepath.Join(rootDataDir, "keystore")

backend.rootDataDir = rootDataDir

err := backend.AccountManager().InitKeystore(keyStoreDir)
err = backend.AccountManager().InitKeystore(keyStoreDir)
require.NoError(t, err)

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

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

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

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

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

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

b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())
require.NoError(t, err)
createAccountRequest := &requests.CreateAccount{
DisplayName: "some-display-name",
CustomizationColor: "#ffffff",
Expand Down Expand Up @@ -1520,7 +1543,8 @@ 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())
require.NoError(t, err)
createAccountRequest := &requests.CreateAccount{
DisplayName: "some-display-name",
CustomizationColor: "#ffffff",
Expand Down Expand Up @@ -1585,7 +1609,8 @@ func TestTestnetEnabledSettingOnCreateAccount(t *testing.T) {
utils.Init()
tmpdir := t.TempDir()

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

// Creating an account with test networks enabled
createAccountRequest1 := &requests.CreateAccount{
Expand All @@ -1596,7 +1621,7 @@ func TestTestnetEnabledSettingOnCreateAccount(t *testing.T) {
LogFilePath: tmpdir + "/log",
TestNetworksEnabled: true,
}
_, err := b.CreateAccountAndLogin(createAccountRequest1)
_, err = b.CreateAccountAndLogin(createAccountRequest1)
require.NoError(t, err)
statusNode := b.statusNode
require.NotNil(t, statusNode)
Expand Down Expand Up @@ -1631,7 +1656,8 @@ func TestRestoreAccountAndLogin(t *testing.T) {
utils.Init()
tmpdir := t.TempDir()

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

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

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

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

func TestAcceptTerms(t *testing.T) {
tmpdir := t.TempDir()
b := NewGethStatusBackend()
b := NewGethStatusBackend(tt.MustCreateTestLogger())
require.NoError(t, err)
conf, err := params.NewNodeConfig(tmpdir, 1777)
require.NoError(t, err)
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
Expand Down Expand Up @@ -1850,7 +1878,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 fdba6cb

Please sign in to comment.