Start abstracting geth Keystore
This commit is contained in:
parent
ef87c330ce
commit
dd894ece15
|
@ -13,10 +13,10 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/pborman/uuid"
|
||||
|
||||
"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/types"
|
||||
"github.com/status-im/status-go/extkeys"
|
||||
)
|
||||
|
@ -32,7 +32,7 @@ var (
|
|||
ErrAccountKeyStoreMissing = errors.New("account key store is not set")
|
||||
)
|
||||
|
||||
var zeroAddress = common.Address{}
|
||||
var zeroAddress = types.Address{}
|
||||
|
||||
// Manager represents account manager interface.
|
||||
type Manager struct {
|
||||
|
@ -44,8 +44,8 @@ type Manager struct {
|
|||
onboarding *Onboarding
|
||||
|
||||
selectedChatAccount *SelectedExtKey // account that was processed during the last call to SelectAccount()
|
||||
mainAccountAddress common.Address
|
||||
watchAddresses []common.Address
|
||||
mainAccountAddress types.Address
|
||||
watchAddresses []types.Address
|
||||
}
|
||||
|
||||
// NewManager returns new node account manager.
|
||||
|
@ -157,7 +157,7 @@ func (m *Manager) VerifyAccountPassword(keyStoreDir, address, password string) (
|
|||
var err error
|
||||
var foundKeyFile []byte
|
||||
|
||||
addressObj := common.BytesToAddress(common.FromHex(address))
|
||||
addressObj := types.BytesToAddress(types.FromHex(address))
|
||||
checkAccountKey := func(path string, fileInfo os.FileInfo) error {
|
||||
if len(foundKeyFile) > 0 || fileInfo.IsDir() {
|
||||
return nil
|
||||
|
@ -175,7 +175,7 @@ func (m *Manager) VerifyAccountPassword(keyStoreDir, address, password string) (
|
|||
return fmt.Errorf("failed to read key file: %s", e)
|
||||
}
|
||||
|
||||
if common.HexToAddress("0x"+accountKey.Address).Hex() == addressObj.Hex() {
|
||||
if types.HexToAddress("0x"+accountKey.Address).Hex() == addressObj.Hex() {
|
||||
foundKeyFile = rawKeyFile
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ func (m *Manager) VerifyAccountPassword(keyStoreDir, address, password string) (
|
|||
}
|
||||
|
||||
// avoid swap attack
|
||||
if key.Address != addressObj {
|
||||
if types.Address(key.Address) != addressObj {
|
||||
return nil, fmt.Errorf("account mismatch: have %s, want %s", key.Address.Hex(), addressObj.Hex())
|
||||
}
|
||||
|
||||
|
@ -227,8 +227,8 @@ func (m *Manager) SelectAccount(loginParams LoginParams) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) SetAccountAddresses(main common.Address, secondary ...common.Address) {
|
||||
m.watchAddresses = []common.Address{main}
|
||||
func (m *Manager) SetAccountAddresses(main types.Address, secondary ...types.Address) {
|
||||
m.watchAddresses = []types.Address{main}
|
||||
m.watchAddresses = append(m.watchAddresses, secondary...)
|
||||
m.mainAccountAddress = main
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ func (m *Manager) SetChatAccount(privKey *ecdsa.PrivateKey) {
|
|||
id := uuid.NewRandom()
|
||||
key := &keystore.Key{
|
||||
Id: id,
|
||||
Address: address,
|
||||
Address: common.Address(address),
|
||||
PrivateKey: privKey,
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ func (m *Manager) SetChatAccount(privKey *ecdsa.PrivateKey) {
|
|||
}
|
||||
|
||||
// MainAccountAddress returns currently selected watch addresses.
|
||||
func (m *Manager) MainAccountAddress() (common.Address, error) {
|
||||
func (m *Manager) MainAccountAddress() (types.Address, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
|
@ -265,7 +265,7 @@ func (m *Manager) MainAccountAddress() (common.Address, error) {
|
|||
}
|
||||
|
||||
// WatchAddresses returns currently selected watch addresses.
|
||||
func (m *Manager) WatchAddresses() []common.Address {
|
||||
func (m *Manager) WatchAddresses() []types.Address {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
|
@ -295,14 +295,14 @@ func (m *Manager) Logout() {
|
|||
}
|
||||
|
||||
// ImportAccount imports the account specified with privateKey.
|
||||
func (m *Manager) ImportAccount(privateKey *ecdsa.PrivateKey, password string) (common.Address, error) {
|
||||
func (m *Manager) ImportAccount(privateKey *ecdsa.PrivateKey, password string) (types.Address, error) {
|
||||
if m.keystore == nil {
|
||||
return common.Address{}, ErrAccountKeyStoreMissing
|
||||
return types.Address{}, ErrAccountKeyStoreMissing
|
||||
}
|
||||
|
||||
account, err := m.keystore.ImportECDSA(privateKey, password)
|
||||
|
||||
return account.Address, err
|
||||
return types.Address(account.Address), err
|
||||
}
|
||||
|
||||
func (m *Manager) ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, password string) (address, pubKey string, err error) {
|
||||
|
@ -355,10 +355,10 @@ func (m *Manager) importExtendedKey(keyPurpose extkeys.KeyPurpose, extKey *extke
|
|||
|
||||
// Accounts returns list of addresses for selected account, including
|
||||
// subaccounts.
|
||||
func (m *Manager) Accounts() ([]common.Address, error) {
|
||||
func (m *Manager) Accounts() ([]types.Address, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
addresses := make([]common.Address, 0)
|
||||
addresses := make([]types.Address, 0)
|
||||
if m.mainAccountAddress != zeroAddress {
|
||||
addresses = append(addresses, m.mainAccountAddress)
|
||||
}
|
||||
|
@ -444,7 +444,7 @@ func (m *Manager) unlockExtendedKey(address, password string) (*SelectedExtKey,
|
|||
}
|
||||
|
||||
selectedExtendedKey := &SelectedExtKey{
|
||||
Address: account.Address,
|
||||
Address: types.Address(account.Address),
|
||||
AccountKey: accountKey,
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
@ -32,7 +32,7 @@ func TestVerifyAccountPassword(t *testing.T) {
|
|||
require.NoError(t, utils.ImportTestAccount(keyStoreDir, utils.GetAccount1PKFile()))
|
||||
require.NoError(t, utils.ImportTestAccount(keyStoreDir, utils.GetAccount2PKFile()))
|
||||
|
||||
account1Address := common.BytesToAddress(common.FromHex(utils.TestConfig.Account1.WalletAddress))
|
||||
account1Address := types.BytesToAddress(types.FromHex(utils.TestConfig.Account1.WalletAddress))
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
@ -86,8 +86,8 @@ func TestVerifyAccountPassword(t *testing.T) {
|
|||
if accountKey == nil {
|
||||
require.Fail(t, "no error reported, but account key is missing")
|
||||
}
|
||||
accountAddress := common.BytesToAddress(common.FromHex(testCase.address))
|
||||
if accountKey.Address != accountAddress {
|
||||
accountAddress := types.BytesToAddress(types.FromHex(testCase.address))
|
||||
if types.Address(accountKey.Address) != accountAddress {
|
||||
require.Fail(t, "account mismatch: have %s, want %s", accountKey.Address.Hex(), accountAddress.Hex())
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func TestVerifyAccountPasswordWithAccountBeforeEIP55(t *testing.T) {
|
|||
|
||||
accManager := NewManager()
|
||||
|
||||
address := common.HexToAddress(utils.TestConfig.Account3.WalletAddress)
|
||||
address := types.HexToAddress(utils.TestConfig.Account3.WalletAddress)
|
||||
_, err = accManager.VerifyAccountPassword(keyStoreDir, address.Hex(), utils.TestConfig.Account3.Password)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
@ -220,18 +220,18 @@ func (s *ManagerTestSuite) TestOnboarding() {
|
|||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestSelectAccountSuccess() {
|
||||
s.testSelectAccount(common.HexToAddress(s.testAccount.chatAddress), common.HexToAddress(s.testAccount.walletAddress), s.testAccount.password, nil)
|
||||
s.testSelectAccount(types.HexToAddress(s.testAccount.chatAddress), types.HexToAddress(s.testAccount.walletAddress), s.testAccount.password, nil)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestSelectAccountWrongAddress() {
|
||||
s.testSelectAccount(common.HexToAddress("0x0000000000000000000000000000000000000001"), common.HexToAddress(s.testAccount.walletAddress), s.testAccount.password, errors.New("cannot retrieve a valid key for a given account: no key for given address or file"))
|
||||
s.testSelectAccount(types.HexToAddress("0x0000000000000000000000000000000000000001"), types.HexToAddress(s.testAccount.walletAddress), s.testAccount.password, errors.New("cannot retrieve a valid key for a given account: no key for given address or file"))
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestSelectAccountWrongPassword() {
|
||||
s.testSelectAccount(common.HexToAddress(s.testAccount.chatAddress), common.HexToAddress(s.testAccount.walletAddress), "wrong", errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given password"))
|
||||
s.testSelectAccount(types.HexToAddress(s.testAccount.chatAddress), types.HexToAddress(s.testAccount.walletAddress), "wrong", errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given password"))
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) testSelectAccount(chat, wallet common.Address, password string, expErr error) {
|
||||
func (s *ManagerTestSuite) testSelectAccount(chat, wallet types.Address, password string, expErr error) {
|
||||
loginParams := LoginParams{
|
||||
ChatAddress: chat,
|
||||
MainAccount: wallet,
|
||||
|
@ -249,7 +249,7 @@ func (s *ManagerTestSuite) testSelectAccount(chat, wallet common.Address, passwo
|
|||
s.Equal(wallet, selectedMainAccountAddress)
|
||||
s.Equal(chat, crypto.PubkeyToAddress(selectedChatAccount.AccountKey.PrivateKey.PublicKey))
|
||||
} else {
|
||||
s.Equal(common.Address{}, selectedMainAccountAddress)
|
||||
s.Equal(types.Address{}, selectedMainAccountAddress)
|
||||
s.Nil(selectedChatAccount)
|
||||
s.Equal(walletErr, ErrNoAccountSelected)
|
||||
s.Equal(chatErr, ErrNoAccountSelected)
|
||||
|
@ -275,12 +275,12 @@ func (s *ManagerTestSuite) TestSetChatAccount() {
|
|||
|
||||
selectedMainAccountAddress, err := s.accManager.MainAccountAddress()
|
||||
s.Error(err)
|
||||
s.Equal(common.Address{}, selectedMainAccountAddress)
|
||||
s.Equal(types.Address{}, selectedMainAccountAddress)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestLogout() {
|
||||
s.accManager.Logout()
|
||||
s.Equal(common.Address{}, s.accManager.mainAccountAddress)
|
||||
s.Equal(types.Address{}, s.accManager.mainAccountAddress)
|
||||
s.Nil(s.accManager.selectedChatAccount)
|
||||
s.Len(s.accManager.watchAddresses, 0)
|
||||
}
|
||||
|
@ -289,8 +289,8 @@ func (s *ManagerTestSuite) TestLogout() {
|
|||
func (s *ManagerTestSuite) TestAccounts() {
|
||||
// Select the test account
|
||||
loginParams := LoginParams{
|
||||
MainAccount: common.HexToAddress(s.walletAddress),
|
||||
ChatAddress: common.HexToAddress(s.chatAddress),
|
||||
MainAccount: types.HexToAddress(s.walletAddress),
|
||||
ChatAddress: types.HexToAddress(s.chatAddress),
|
||||
Password: s.password,
|
||||
}
|
||||
err := s.accManager.SelectAccount(loginParams)
|
||||
|
@ -301,7 +301,7 @@ func (s *ManagerTestSuite) TestAccounts() {
|
|||
s.NoError(err)
|
||||
s.NotNil(accs)
|
||||
// Selected main account address is zero address but doesn't fail
|
||||
s.accManager.mainAccountAddress = common.Address{}
|
||||
s.accManager.mainAccountAddress = types.Address{}
|
||||
accs, err = s.accManager.Accounts()
|
||||
s.NoError(err)
|
||||
s.NotNil(accs)
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/pborman/uuid"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/extkeys"
|
||||
)
|
||||
|
||||
|
@ -27,7 +27,7 @@ var (
|
|||
type AccountManager interface {
|
||||
AddressToDecryptedAccount(address, password string) (accounts.Account, *keystore.Key, error)
|
||||
ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, password string) (address, pubKey string, err error)
|
||||
ImportAccount(privateKey *ecdsa.PrivateKey, password string) (common.Address, error)
|
||||
ImportAccount(privateKey *ecdsa.PrivateKey, password string) (types.Address, error)
|
||||
}
|
||||
|
||||
type Generator struct {
|
||||
|
|
|
@ -8,6 +8,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
)
|
||||
|
||||
// errors
|
||||
|
@ -17,10 +19,10 @@ var (
|
|||
)
|
||||
|
||||
type LoginParams struct {
|
||||
ChatAddress common.Address `json:"chatAddress"`
|
||||
Password string `json:"password"`
|
||||
MainAccount common.Address `json:"mainAccount"`
|
||||
WatchAddresses []common.Address `json:"watchAddresses"`
|
||||
ChatAddress types.Address `json:"chatAddress"`
|
||||
Password string `json:"password"`
|
||||
MainAccount types.Address `json:"mainAccount"`
|
||||
WatchAddresses []types.Address `json:"watchAddresses"`
|
||||
}
|
||||
|
||||
type ErrZeroAddress struct {
|
||||
|
@ -40,7 +42,7 @@ func newErrZeroAddress(field string) *ErrZeroAddress {
|
|||
func ParseLoginParams(paramsJSON string) (LoginParams, error) {
|
||||
var (
|
||||
params LoginParams
|
||||
zeroAddress common.Address
|
||||
zeroAddress types.Address
|
||||
)
|
||||
if err := json.Unmarshal([]byte(paramsJSON), ¶ms); err != nil {
|
||||
return params, err
|
||||
|
@ -72,7 +74,7 @@ type Info struct {
|
|||
|
||||
// SelectedExtKey is a container for the selected (logged in) external account.
|
||||
type SelectedExtKey struct {
|
||||
Address common.Address
|
||||
Address types.Address
|
||||
AccountKey *keystore.Key
|
||||
SubAccounts []accounts.Account
|
||||
}
|
||||
|
@ -89,16 +91,16 @@ func (k *SelectedExtKey) Hex() string {
|
|||
// ParseAccountString parses hex encoded string and returns is as accounts.Account.
|
||||
func ParseAccountString(account string) (accounts.Account, error) {
|
||||
// valid address, convert to account
|
||||
if common.IsHexAddress(account) {
|
||||
if types.IsHexAddress(account) {
|
||||
return accounts.Account{Address: common.HexToAddress(account)}, nil
|
||||
}
|
||||
|
||||
return accounts.Account{}, ErrInvalidAccountAddressOrKey
|
||||
}
|
||||
|
||||
// FromAddress converts account address from string to common.Address.
|
||||
// GethFromAddress converts account address from string to common.Address.
|
||||
// The function is useful to format "From" field of send transaction struct.
|
||||
func FromAddress(accountAddress string) common.Address {
|
||||
func GethFromAddress(accountAddress string) common.Address {
|
||||
from, err := ParseAccountString(accountAddress)
|
||||
if err != nil {
|
||||
return common.Address{}
|
||||
|
@ -107,9 +109,20 @@ func FromAddress(accountAddress string) common.Address {
|
|||
return from.Address
|
||||
}
|
||||
|
||||
// ToAddress converts account address from string to *common.Address.
|
||||
// FromAddress converts account address from string to types.Address.
|
||||
// The function is useful to format "From" field of send transaction struct.
|
||||
func FromAddress(accountAddress string) types.Address {
|
||||
from, err := ParseAccountString(accountAddress)
|
||||
if err != nil {
|
||||
return types.Address{}
|
||||
}
|
||||
|
||||
return types.Address(from.Address)
|
||||
}
|
||||
|
||||
// GethToAddress converts account address from string to *common.Address.
|
||||
// The function is useful to format "To" field of send transaction struct.
|
||||
func ToAddress(accountAddress string) *common.Address {
|
||||
func GethToAddress(accountAddress string) *common.Address {
|
||||
to, err := ParseAccountString(accountAddress)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
|
|
@ -21,13 +21,13 @@ func (suite *AccountUtilsTestSuite) SetupTest() {
|
|||
suite.validKey = "0xF35E0325dad87e2661c4eF951d58727e6d583d5c"
|
||||
}
|
||||
|
||||
func (suite *AccountUtilsTestSuite) TestToAddress() {
|
||||
addr := ToAddress(suite.validKey)
|
||||
func (suite *AccountUtilsTestSuite) TestGethToAddress() {
|
||||
addr := GethToAddress(suite.validKey)
|
||||
suite.Equal(suite.validKey, addr.String())
|
||||
}
|
||||
|
||||
func (suite *AccountUtilsTestSuite) TestToAddressInvalidAddress() {
|
||||
addr := ToAddress("foobar")
|
||||
func (suite *AccountUtilsTestSuite) TestGethToAddressInvalidAddress() {
|
||||
addr := GethToAddress("foobar")
|
||||
suite.Nil(addr)
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,21 @@ func (suite *AccountUtilsTestSuite) TestFromAddress() {
|
|||
}
|
||||
}
|
||||
|
||||
func (suite *AccountUtilsTestSuite) TestGethFromAddress() {
|
||||
var flagtests = []struct {
|
||||
in string
|
||||
out string
|
||||
}{
|
||||
{suite.validKey, suite.validKey},
|
||||
{"foobar", "0x0000000000000000000000000000000000000000"},
|
||||
}
|
||||
|
||||
for _, tt := range flagtests {
|
||||
addr := GethFromAddress(tt.in)
|
||||
suite.Equal(tt.out, addr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *AccountUtilsTestSuite) TestHex() {
|
||||
var addr *SelectedExtKey
|
||||
cr, _ := crypto.GenerateKey()
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/node"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/signal"
|
||||
|
@ -245,8 +245,8 @@ func initNodeAndLogin(t *testing.T, backend *GethStatusBackend) (string, string)
|
|||
require.NoError(t, err)
|
||||
|
||||
loginParams := account.LoginParams{
|
||||
MainAccount: common.HexToAddress(info.WalletAddress),
|
||||
ChatAddress: common.HexToAddress(info.ChatAddress),
|
||||
MainAccount: types.HexToAddress(info.WalletAddress),
|
||||
ChatAddress: types.HexToAddress(info.ChatAddress),
|
||||
Password: password,
|
||||
}
|
||||
require.NoError(t, backend.AccountManager().SelectAccount(loginParams))
|
||||
|
|
|
@ -12,9 +12,9 @@ import (
|
|||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
gethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
|
@ -183,8 +183,8 @@ func TestBackendAccountsConcurrently(t *testing.T) {
|
|||
wg.Add(1)
|
||||
go func(tuple [3]string) {
|
||||
loginParams := account.LoginParams{
|
||||
MainAccount: common.HexToAddress(tuple[0]),
|
||||
ChatAddress: common.HexToAddress(tuple[1]),
|
||||
MainAccount: types.HexToAddress(tuple[0]),
|
||||
ChatAddress: types.HexToAddress(tuple[1]),
|
||||
Password: tuple[2],
|
||||
}
|
||||
assert.NoError(t, backend.SelectAccount(loginParams))
|
||||
|
@ -220,14 +220,14 @@ func TestBackendInjectChatAccount(t *testing.T) {
|
|||
require.NoError(t, backend.StopNode())
|
||||
}()
|
||||
|
||||
chatPrivKey, err := crypto.GenerateKey()
|
||||
chatPrivKey, err := gethcrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
encryptionPrivKey, err := crypto.GenerateKey()
|
||||
encryptionPrivKey, err := gethcrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
chatPrivKeyHex := hex.EncodeToString(crypto.FromECDSA(chatPrivKey))
|
||||
chatPubKeyHex := types.EncodeHex(crypto.FromECDSAPub(&chatPrivKey.PublicKey))
|
||||
encryptionPrivKeyHex := hex.EncodeToString(crypto.FromECDSA(encryptionPrivKey))
|
||||
chatPrivKeyHex := hex.EncodeToString(gethcrypto.FromECDSA(chatPrivKey))
|
||||
chatPubKeyHex := types.EncodeHex(gethcrypto.FromECDSAPub(&chatPrivKey.PublicKey))
|
||||
encryptionPrivKeyHex := hex.EncodeToString(gethcrypto.FromECDSA(encryptionPrivKey))
|
||||
|
||||
whisperService, err := backend.StatusNode().WhisperService()
|
||||
require.NoError(t, err)
|
||||
|
@ -243,7 +243,7 @@ func TestBackendInjectChatAccount(t *testing.T) {
|
|||
|
||||
// wallet account should not be selected
|
||||
mainAccountAddress, err := backend.AccountManager().MainAccountAddress()
|
||||
require.Equal(t, common.Address{}, mainAccountAddress)
|
||||
require.Equal(t, types.Address{}, mainAccountAddress)
|
||||
require.Equal(t, account.ErrNoAccountSelected, err)
|
||||
|
||||
// selected chat account should have the key injected previously
|
||||
|
@ -526,9 +526,9 @@ func TestBackendGetVerifiedAccount(t *testing.T) {
|
|||
}()
|
||||
|
||||
t.Run("AccountDoesntExist", func(t *testing.T) {
|
||||
pkey, err := crypto.GenerateKey()
|
||||
pkey, err := gethcrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
address := crypto.PubkeyToAddress(pkey.PublicKey)
|
||||
address := gethcrypto.PubkeyToAddress(pkey.PublicKey)
|
||||
key, err := backend.getVerifiedWalletAccount(address.String(), password)
|
||||
require.EqualError(t, err, transactions.ErrAccountDoesntExist.Error())
|
||||
require.Nil(t, key)
|
||||
|
@ -565,11 +565,11 @@ func TestLoginWithKey(t *testing.T) {
|
|||
utils.Init()
|
||||
|
||||
b := NewGethStatusBackend()
|
||||
chatKey, err := crypto.GenerateKey()
|
||||
chatKey, err := gethcrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
walletKey, err := crypto.GenerateKey()
|
||||
walletKey, err := gethcrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
keyUIDHex := sha256.Sum256(crypto.FromECDSAPub(&chatKey.PublicKey))
|
||||
keyUIDHex := sha256.Sum256(gethcrypto.FromECDSAPub(&chatKey.PublicKey))
|
||||
keyUID := types.EncodeHex(keyUIDHex[:])
|
||||
main := multiaccounts.Account{
|
||||
KeyUID: keyUID,
|
||||
|
@ -579,7 +579,7 @@ func TestLoginWithKey(t *testing.T) {
|
|||
defer os.Remove(tmpdir)
|
||||
conf, err := params.NewNodeConfig(tmpdir, 1777)
|
||||
require.NoError(t, err)
|
||||
keyhex := hex.EncodeToString(crypto.FromECDSA(chatKey))
|
||||
keyhex := hex.EncodeToString(gethcrypto.FromECDSA(chatKey))
|
||||
|
||||
require.NoError(t, b.AccountManager().InitKeystore(conf.KeyStoreDir))
|
||||
b.UpdateRootDataDir(conf.DataDir)
|
||||
|
|
|
@ -655,7 +655,7 @@ func (b *GethStatusBackend) getVerifiedWalletAccount(address, password string) (
|
|||
config := b.StatusNode().Config()
|
||||
|
||||
db := accounts.NewDB(b.appDB)
|
||||
exists, err := db.AddressExists(common.HexToAddress(address))
|
||||
exists, err := db.AddressExists(types.HexToAddress(address))
|
||||
if err != nil {
|
||||
b.log.Error("failed to query db for a given address", "address", address, "error", err)
|
||||
return nil, err
|
||||
|
@ -673,7 +673,7 @@ func (b *GethStatusBackend) getVerifiedWalletAccount(address, password string) (
|
|||
}
|
||||
|
||||
return &account.SelectedExtKey{
|
||||
Address: key.Address,
|
||||
Address: types.Address(key.Address),
|
||||
AccountKey: key,
|
||||
}, nil
|
||||
}
|
||||
|
@ -900,8 +900,10 @@ func (b *GethStatusBackend) startWallet() error {
|
|||
}
|
||||
|
||||
allAddresses := make([]common.Address, len(watchAddresses)+1)
|
||||
allAddresses[0] = mainAccountAddress
|
||||
copy(allAddresses[1:], watchAddresses)
|
||||
allAddresses[0] = common.Address(mainAccountAddress)
|
||||
for i, addr := range watchAddresses {
|
||||
allAddresses[1+i] = common.Address(addr)
|
||||
}
|
||||
return wallet.StartReactor(
|
||||
b.statusNode.RPCClient().Ethclient(),
|
||||
allAddresses,
|
||||
|
|
|
@ -43,7 +43,6 @@ const initJS = `
|
|||
};`
|
||||
|
||||
var (
|
||||
zeroHash = common.Hash{}
|
||||
testChainDir string
|
||||
keystoreDir string
|
||||
nodeConfigJSON string
|
||||
|
@ -61,7 +60,7 @@ func buildSubAccountData(chatAddress string) *C.char {
|
|||
{
|
||||
Wallet: true,
|
||||
Chat: true,
|
||||
Address: common.HexToAddress(chatAddress),
|
||||
Address: types.HexToAddress(chatAddress),
|
||||
},
|
||||
}
|
||||
data, _ := json.Marshal(accs)
|
||||
|
@ -70,9 +69,9 @@ func buildSubAccountData(chatAddress string) *C.char {
|
|||
|
||||
func buildLoginParams(mainAccountAddress, chatAddress, password string) account.LoginParams {
|
||||
return account.LoginParams{
|
||||
ChatAddress: common.HexToAddress(chatAddress),
|
||||
ChatAddress: types.HexToAddress(chatAddress),
|
||||
Password: password,
|
||||
MainAccount: common.HexToAddress(mainAccountAddress),
|
||||
MainAccount: types.HexToAddress(mainAccountAddress),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -536,8 +535,8 @@ func testSendTransactionWithLogin(t *testing.T, feed *event.Feed) bool {
|
|||
EnsureNodeSync(statusBackend.StatusNode().EnsureSync)
|
||||
|
||||
args, err := json.Marshal(transactions.SendTxArgs{
|
||||
From: account.FromAddress(TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(TestConfig.Account2.WalletAddress),
|
||||
Value: (*hexutil.Big)(big.NewInt(1000000000000)),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -555,8 +554,8 @@ func testSendTransactionWithLogin(t *testing.T, feed *event.Feed) bool {
|
|||
t.Errorf("failed to send transaction: %v", result.Error)
|
||||
return false
|
||||
}
|
||||
hash := common.BytesToHash(result.Result)
|
||||
if reflect.DeepEqual(hash, common.Hash{}) {
|
||||
hash := types.BytesToHash(result.Result)
|
||||
if reflect.DeepEqual(hash, types.Hash{}) {
|
||||
t.Errorf("response hash empty: %s", hash.Hex())
|
||||
return false
|
||||
}
|
||||
|
@ -570,7 +569,7 @@ func testSendTransactionInvalidPassword(t *testing.T, feed *event.Feed) bool {
|
|||
|
||||
args, err := json.Marshal(transactions.SendTxArgs{
|
||||
From: common.HexToAddress(acc.WalletAddress),
|
||||
To: account.ToAddress(TestConfig.Account2.WalletAddress),
|
||||
To: account.GethToAddress(TestConfig.Account2.WalletAddress),
|
||||
Value: (*hexutil.Big)(big.NewInt(1000000000000)),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -597,8 +596,8 @@ func testFailedTransaction(t *testing.T, feed *event.Feed) bool {
|
|||
EnsureNodeSync(statusBackend.StatusNode().EnsureSync)
|
||||
|
||||
args, err := json.Marshal(transactions.SendTxArgs{
|
||||
From: *account.ToAddress(TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(TestConfig.Account2.WalletAddress),
|
||||
From: *account.GethToAddress(TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(TestConfig.Account2.WalletAddress),
|
||||
Value: (*hexutil.Big)(big.NewInt(1000000000000)),
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -7,8 +7,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
)
|
||||
|
||||
|
@ -25,13 +24,13 @@ var (
|
|||
)
|
||||
|
||||
type Account struct {
|
||||
Address common.Address `json:"address"`
|
||||
Address types.Address `json:"address"`
|
||||
Wallet bool `json:"wallet"`
|
||||
Chat bool `json:"chat"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Storage string `json:"storage,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
PublicKey hexutil.Bytes `json:"public-key,omitempty"`
|
||||
PublicKey types.HexBytes `json:"public-key,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
}
|
||||
|
@ -106,7 +105,7 @@ func (db *Database) GetAccounts() ([]Account, error) {
|
|||
return nil, err
|
||||
}
|
||||
if lth := len(pubkey); lth > 0 {
|
||||
acc.PublicKey = make(hexutil.Bytes, lth)
|
||||
acc.PublicKey = make(types.HexBytes, lth)
|
||||
copy(acc.PublicKey, pubkey)
|
||||
}
|
||||
accounts = append(accounts, acc)
|
||||
|
@ -161,28 +160,28 @@ func (db *Database) SaveAccounts(accounts []Account) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (db *Database) DeleteAccount(address common.Address) error {
|
||||
func (db *Database) DeleteAccount(address types.Address) error {
|
||||
_, err := db.db.Exec("DELETE FROM accounts WHERE address = ?", address)
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *Database) GetWalletAddress() (rst common.Address, err error) {
|
||||
func (db *Database) GetWalletAddress() (rst types.Address, err error) {
|
||||
err = db.db.QueryRow("SELECT address FROM accounts WHERE wallet = 1").Scan(&rst)
|
||||
return
|
||||
}
|
||||
|
||||
func (db *Database) GetChatAddress() (rst common.Address, err error) {
|
||||
func (db *Database) GetChatAddress() (rst types.Address, err error) {
|
||||
err = db.db.QueryRow("SELECT address FROM accounts WHERE chat = 1").Scan(&rst)
|
||||
return
|
||||
}
|
||||
|
||||
func (db *Database) GetAddresses() (rst []common.Address, err error) {
|
||||
func (db *Database) GetAddresses() (rst []types.Address, err error) {
|
||||
rows, err := db.db.Query("SELECT address FROM accounts ORDER BY created_at")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for rows.Next() {
|
||||
addr := common.Address{}
|
||||
addr := types.Address{}
|
||||
err = rows.Scan(&addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -193,7 +192,7 @@ func (db *Database) GetAddresses() (rst []common.Address, err error) {
|
|||
}
|
||||
|
||||
// AddressExists returns true if given address is stored in database.
|
||||
func (db *Database) AddressExists(address common.Address) (exists bool, err error) {
|
||||
func (db *Database) AddressExists(address types.Address) (exists bool, err error) {
|
||||
err = db.db.QueryRow("SELECT EXISTS (SELECT 1 FROM accounts WHERE address = ?)", address).Scan(&exists)
|
||||
return exists, err
|
||||
}
|
||||
|
|
|
@ -7,9 +7,8 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/status-im/status-go/appdatabase"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -80,23 +79,23 @@ func TestSaveAccounts(t *testing.T) {
|
|||
{
|
||||
description: "NoError",
|
||||
accounts: []Account{
|
||||
{Address: common.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: common.Address{0x02}},
|
||||
{Address: types.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: types.Address{0x02}},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "UniqueChat",
|
||||
accounts: []Account{
|
||||
{Address: common.Address{0x01}, Chat: true},
|
||||
{Address: common.Address{0x02}, Chat: true},
|
||||
{Address: types.Address{0x01}, Chat: true},
|
||||
{Address: types.Address{0x02}, Chat: true},
|
||||
},
|
||||
err: ErrChatNotUnique,
|
||||
},
|
||||
{
|
||||
description: "UniqueWallet",
|
||||
accounts: []Account{
|
||||
{Address: common.Address{0x01}, Wallet: true},
|
||||
{Address: common.Address{0x02}, Wallet: true},
|
||||
{Address: types.Address{0x01}, Wallet: true},
|
||||
{Address: types.Address{0x02}, Wallet: true},
|
||||
},
|
||||
err: ErrWalletNotUnique,
|
||||
},
|
||||
|
@ -113,8 +112,8 @@ func TestUpdateAccounts(t *testing.T) {
|
|||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
accounts := []Account{
|
||||
{Address: common.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: common.Address{0x02}},
|
||||
{Address: types.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: types.Address{0x02}},
|
||||
}
|
||||
require.NoError(t, db.SaveAccounts(accounts))
|
||||
accounts[0].Chat = false
|
||||
|
@ -129,13 +128,13 @@ func TestDeleteAccount(t *testing.T) {
|
|||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
accounts := []Account{
|
||||
{Address: common.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: types.Address{0x01}, Chat: true, Wallet: true},
|
||||
}
|
||||
require.NoError(t, db.SaveAccounts(accounts))
|
||||
rst, err := db.GetAccounts()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(rst))
|
||||
require.NoError(t, db.DeleteAccount(common.Address{0x01}))
|
||||
require.NoError(t, db.DeleteAccount(types.Address{0x01}))
|
||||
rst2, err := db.GetAccounts()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 0, len(rst2))
|
||||
|
@ -145,19 +144,19 @@ func TestGetAddresses(t *testing.T) {
|
|||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
accounts := []Account{
|
||||
{Address: common.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: common.Address{0x02}},
|
||||
{Address: types.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: types.Address{0x02}},
|
||||
}
|
||||
require.NoError(t, db.SaveAccounts(accounts))
|
||||
addresses, err := db.GetAddresses()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []common.Address{{0x01}, {0x02}}, addresses)
|
||||
require.Equal(t, []types.Address{{0x01}, {0x02}}, addresses)
|
||||
}
|
||||
|
||||
func TestGetWalletAddress(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
address := common.Address{0x01}
|
||||
address := types.Address{0x01}
|
||||
_, err := db.GetWalletAddress()
|
||||
require.Equal(t, err, sql.ErrNoRows)
|
||||
require.NoError(t, db.SaveAccounts([]Account{{Address: address, Wallet: true}}))
|
||||
|
@ -169,7 +168,7 @@ func TestGetWalletAddress(t *testing.T) {
|
|||
func TestGetChatAddress(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
address := common.Address{0x01}
|
||||
address := types.Address{0x01}
|
||||
_, err := db.GetChatAddress()
|
||||
require.Equal(t, err, sql.ErrNoRows)
|
||||
require.NoError(t, db.SaveAccounts([]Account{{Address: address, Chat: true}}))
|
||||
|
@ -182,9 +181,9 @@ func TestGetAccounts(t *testing.T) {
|
|||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
accounts := []Account{
|
||||
{Address: common.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: common.Address{0x02}, PublicKey: hexutil.Bytes{0x01, 0x02}},
|
||||
{Address: common.Address{0x03}, PublicKey: hexutil.Bytes{0x02, 0x03}},
|
||||
{Address: types.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: types.Address{0x02}, PublicKey: types.HexBytes{0x01, 0x02}},
|
||||
{Address: types.Address{0x03}, PublicKey: types.HexBytes{0x02, 0x03}},
|
||||
}
|
||||
require.NoError(t, db.SaveAccounts(accounts))
|
||||
rst, err := db.GetAccounts()
|
||||
|
@ -197,7 +196,7 @@ func TestAddressExists(t *testing.T) {
|
|||
defer stop()
|
||||
|
||||
accounts := []Account{
|
||||
{Address: common.Address{0x01}, Chat: true, Wallet: true},
|
||||
{Address: types.Address{0x01}, Chat: true, Wallet: true},
|
||||
}
|
||||
require.NoError(t, db.SaveAccounts(accounts))
|
||||
|
||||
|
@ -209,7 +208,7 @@ func TestAddressExists(t *testing.T) {
|
|||
func TestAddressDoesntExist(t *testing.T) {
|
||||
db, stop := setupTestDB(t)
|
||||
defer stop()
|
||||
exists, err := db.AddressExists(common.Address{1, 1, 1})
|
||||
exists, err := db.AddressExists(types.Address{1, 1, 1})
|
||||
require.NoError(t, err)
|
||||
require.False(t, exists)
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ package accounts
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
)
|
||||
|
||||
|
@ -31,6 +31,6 @@ func (api *API) GetAccounts(ctx context.Context) ([]accounts.Account, error) {
|
|||
return api.db.GetAccounts()
|
||||
}
|
||||
|
||||
func (api *API) DeleteAccount(ctx context.Context, address common.Address) error {
|
||||
func (api *API) DeleteAccount(ctx context.Context, address types.Address) error {
|
||||
return api.db.DeleteAccount(address)
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/status-im/status-go/account"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
)
|
||||
|
||||
// PublicAPI represents a set of APIs from the `web3.status` namespace.
|
||||
|
@ -42,9 +43,9 @@ func (api *PublicAPI) Login(context context.Context, req LoginRequest) (res Logi
|
|||
}
|
||||
|
||||
loginParams := account.LoginParams{
|
||||
ChatAddress: common.HexToAddress(req.Addr),
|
||||
ChatAddress: types.HexToAddress(req.Addr),
|
||||
Password: req.Password,
|
||||
MainAccount: common.HexToAddress(req.Addr),
|
||||
MainAccount: types.HexToAddress(req.Addr),
|
||||
}
|
||||
if err = api.s.am.SelectAccount(loginParams); err != nil {
|
||||
return
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
|
@ -53,8 +53,8 @@ var logintests = []struct {
|
|||
s.w.EXPECT().AddKeyPair(key.PrivateKey).Return("addressKey", nil)
|
||||
|
||||
loginParams := account.LoginParams{
|
||||
MainAccount: common.HexToAddress("0x01"),
|
||||
ChatAddress: common.HexToAddress("0x01"),
|
||||
MainAccount: types.HexToAddress("0x01"),
|
||||
ChatAddress: types.HexToAddress("0x01"),
|
||||
Password: "password",
|
||||
}
|
||||
s.am.EXPECT().SelectAccount(loginParams).Return(nil)
|
||||
|
@ -95,8 +95,8 @@ var logintests = []struct {
|
|||
s.w.EXPECT().AddKeyPair(key.PrivateKey).Return("", nil)
|
||||
|
||||
loginParams := account.LoginParams{
|
||||
MainAccount: common.HexToAddress("0x01"),
|
||||
ChatAddress: common.HexToAddress("0x01"),
|
||||
MainAccount: types.HexToAddress("0x01"),
|
||||
ChatAddress: types.HexToAddress("0x01"),
|
||||
Password: "password",
|
||||
}
|
||||
s.am.EXPECT().SelectAccount(loginParams).Return(errors.New("foo"))
|
||||
|
|
|
@ -121,9 +121,9 @@ func WatchAccountsChanges(ctx context.Context, feed *event.Feed, initial []commo
|
|||
log.Debug("wallet received updated list of accounts", "accounts", n)
|
||||
restart := false
|
||||
for _, acc := range n {
|
||||
_, exist := listen[acc.Address]
|
||||
_, exist := listen[common.Address(acc.Address)]
|
||||
if !exist {
|
||||
listen[acc.Address] = struct{}{}
|
||||
listen[common.Address(acc.Address)] = struct{}{}
|
||||
restart = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,15 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
gethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/t/devtests/testchain"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
)
|
||||
|
||||
func TestReactorChanges(t *testing.T) {
|
||||
|
@ -34,9 +36,9 @@ type ReactorChangesSuite struct {
|
|||
first, second common.Address
|
||||
}
|
||||
|
||||
func (s *ReactorChangesSuite) txToAddress(nonce uint64, address common.Address) *types.Transaction {
|
||||
tx := types.NewTransaction(nonce, address, big.NewInt(1e17), 21000, big.NewInt(1), nil)
|
||||
tx, err := types.SignTx(tx, s.backend.Signer, s.backend.Faucet)
|
||||
func (s *ReactorChangesSuite) txToAddress(nonce uint64, address common.Address) *gethtypes.Transaction {
|
||||
tx := gethtypes.NewTransaction(nonce, address, big.NewInt(1e17), 21000, big.NewInt(1), nil)
|
||||
tx, err := gethtypes.SignTx(tx, s.backend.Signer, s.backend.Faucet)
|
||||
s.Require().NoError(err)
|
||||
return tx
|
||||
}
|
||||
|
@ -92,7 +94,7 @@ func (s *ReactorChangesSuite) TestWatchNewAccounts() {
|
|||
}
|
||||
return nil
|
||||
}, 5*time.Second, 500*time.Millisecond))
|
||||
s.feed.Send([]accounts.Account{{Address: s.first}, {Address: s.second}})
|
||||
s.feed.Send([]accounts.Account{{Address: types.Address(s.first)}, {Address: types.Address(s.second)}})
|
||||
s.Require().NoError(utils.Eventually(func() error {
|
||||
transfers, err := s.db.GetTransfersByAddress(s.second, big.NewInt(0), nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/status-im/status-go/api"
|
||||
"github.com/status-im/status-go/eth-node/crypto"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
|
@ -29,7 +29,7 @@ type DevNodeSuite struct {
|
|||
Eth *ethclient.Client
|
||||
Local *statusrpc.Client
|
||||
DevAccount *ecdsa.PrivateKey
|
||||
DevAccountAddress common.Address
|
||||
DevAccountAddress types.Address
|
||||
|
||||
dir string
|
||||
backend *api.GethStatusBackend
|
||||
|
@ -42,7 +42,7 @@ func (s *DevNodeSuite) SetupTest() {
|
|||
s.Require().NoError(err)
|
||||
s.DevAccount = account
|
||||
s.DevAccountAddress = crypto.PubkeyToAddress(account.PublicKey)
|
||||
s.miner, err = miner.NewDevNode(s.DevAccountAddress)
|
||||
s.miner, err = miner.NewDevNode(common.Address(s.DevAccountAddress))
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(miner.StartWithMiner(s.miner))
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
gethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/services/wallet"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
@ -28,10 +29,10 @@ func (s *TransfersSuite) getAllTranfers() (rst []wallet.TransferView, err error)
|
|||
return rst, s.Local.Call(&rst, "wallet_getTransfersByAddress", s.DevAccountAddress, (*hexutil.Big)(big.NewInt(0)))
|
||||
}
|
||||
|
||||
func (s *TransfersSuite) sendTx(nonce uint64, to common.Address) {
|
||||
tx := types.NewTransaction(nonce, to, big.NewInt(1e18), 1e6, big.NewInt(10), nil)
|
||||
func (s *TransfersSuite) sendTx(nonce uint64, to types.Address) {
|
||||
tx := gethtypes.NewTransaction(nonce, common.Address(to), big.NewInt(1e18), 1e6, big.NewInt(10), nil)
|
||||
// TODO move signer to DevNodeSuite
|
||||
tx, err := types.SignTx(tx, types.NewEIP155Signer(big.NewInt(1337)), s.DevAccount)
|
||||
tx, err := gethtypes.SignTx(tx, gethtypes.NewEIP155Signer(big.NewInt(1337)), s.DevAccount)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.Eth.SendTransaction(context.Background(), tx))
|
||||
timeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
|
|
|
@ -6,20 +6,20 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/extkeys"
|
||||
"github.com/status-im/status-go/t/e2e"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
func buildLoginParams(mainAccountAddress, chatAddress, password string, watchAddresses []common.Address) account.LoginParams {
|
||||
func buildLoginParams(mainAccountAddress, chatAddress, password string, watchAddresses []types.Address) account.LoginParams {
|
||||
return account.LoginParams{
|
||||
ChatAddress: common.HexToAddress(chatAddress),
|
||||
ChatAddress: types.HexToAddress(chatAddress),
|
||||
Password: password,
|
||||
MainAccount: common.HexToAddress(mainAccountAddress),
|
||||
MainAccount: types.HexToAddress(mainAccountAddress),
|
||||
WatchAddresses: watchAddresses,
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ func (s *AccountsTestSuite) TestSelectedAccountOnRestart() {
|
|||
// make sure that no account is selected by default
|
||||
selectedWalletAccount, err := s.Backend.AccountManager().MainAccountAddress()
|
||||
s.EqualError(account.ErrNoAccountSelected, err.Error(), "account selected, but should not be")
|
||||
s.Equal(common.Address{}, selectedWalletAccount)
|
||||
s.Equal(types.Address{}, selectedWalletAccount)
|
||||
selectedChatAccount, err := s.Backend.AccountManager().SelectedChatAccount()
|
||||
s.EqualError(account.ErrNoAccountSelected, err.Error(), "account selected, but should not be")
|
||||
s.Nil(selectedChatAccount)
|
||||
|
@ -234,9 +234,9 @@ func (s *AccountsTestSuite) TestSelectedAccountOnRestart() {
|
|||
expectedErr := errors.New("cannot retrieve a valid key for a given account: could not decrypt key with given password")
|
||||
s.EqualError(expectedErr, err.Error())
|
||||
|
||||
watchAddresses := []common.Address{
|
||||
common.HexToAddress("0x00000000000000000000000000000000000001"),
|
||||
common.HexToAddress("0x00000000000000000000000000000000000002"),
|
||||
watchAddresses := []types.Address{
|
||||
types.HexToAddress("0x00000000000000000000000000000000000001"),
|
||||
types.HexToAddress("0x00000000000000000000000000000000000002"),
|
||||
}
|
||||
s.NoError(s.Backend.SelectAccount(buildLoginParams(accountInfo2.WalletAddress, accountInfo2.ChatAddress, utils.TestConfig.Account1.Password, watchAddresses)))
|
||||
|
||||
|
@ -281,7 +281,7 @@ func (s *AccountsTestSuite) TestSelectedAccountOnRestart() {
|
|||
|
||||
selectedWalletAccount, err = s.Backend.AccountManager().MainAccountAddress()
|
||||
s.EqualError(account.ErrNoAccountSelected, err.Error())
|
||||
s.Equal(common.Address{}, selectedWalletAccount)
|
||||
s.Equal(types.Address{}, selectedWalletAccount)
|
||||
selectedChatAccount, err = s.Backend.AccountManager().SelectedChatAccount()
|
||||
s.EqualError(account.ErrNoAccountSelected, err.Error())
|
||||
s.Nil(selectedChatAccount)
|
||||
|
|
|
@ -7,10 +7,9 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/multiaccounts"
|
||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||
"github.com/status-im/status-go/params"
|
||||
|
@ -24,9 +23,9 @@ type initFunc func([]byte, *transactions.SendTxArgs)
|
|||
|
||||
func buildLoginParams(mainAccountAddress, chatAddress, password string) account.LoginParams {
|
||||
return account.LoginParams{
|
||||
ChatAddress: common.HexToAddress(chatAddress),
|
||||
ChatAddress: types.HexToAddress(chatAddress),
|
||||
Password: password,
|
||||
MainAccount: common.HexToAddress(mainAccountAddress),
|
||||
MainAccount: types.HexToAddress(mainAccountAddress),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +111,7 @@ func (s *TransactionsTestSuite) TestEmptyToFieldPreserved() {
|
|||
s.Require().NoError(err)
|
||||
defer os.Remove(tmpdir)
|
||||
|
||||
wallet := common.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
wallet := types.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
s.StartTestBackendWithAccount(multiaccounts.Account{KeyUID: utils.TestConfig.Account1.WalletAddress}, utils.TestConfig.Account1.Password,
|
||||
[]accounts.Account{{Address: wallet, Wallet: true, Chat: true}},
|
||||
e2e.WithDataDir(tmpdir),
|
||||
|
@ -122,7 +121,7 @@ func (s *TransactionsTestSuite) TestEmptyToFieldPreserved() {
|
|||
utils.EnsureNodeSync(s.Backend.StatusNode().EnsureSync)
|
||||
|
||||
args := transactions.SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
}
|
||||
|
||||
hash, err := s.Backend.SendTransaction(args, utils.TestConfig.Account1.Password)
|
||||
|
@ -185,7 +184,7 @@ func (s *TransactionsTestSuite) testSendContractTx(setInputAndDataValue initFunc
|
|||
s.Require().NoError(err)
|
||||
defer os.Remove(tmpdir)
|
||||
|
||||
wallet := common.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
wallet := types.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
s.StartTestBackendWithAccount(multiaccounts.Account{KeyUID: utils.TestConfig.Account1.WalletAddress}, utils.TestConfig.Account1.Password,
|
||||
[]accounts.Account{{Address: wallet, Wallet: true, Chat: true}},
|
||||
e2e.WithDataDir(tmpdir),
|
||||
|
@ -195,14 +194,14 @@ func (s *TransactionsTestSuite) testSendContractTx(setInputAndDataValue initFunc
|
|||
utils.EnsureNodeSync(s.Backend.StatusNode().EnsureSync)
|
||||
|
||||
// this call blocks, up until Complete Transaction is called
|
||||
byteCode, err := hexutil.Decode(`0x6060604052341561000c57fe5b5b60a58061001b6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680636ffa1caa14603a575bfe5b3415604157fe5b60556004808035906020019091905050606b565b6040518082815260200191505060405180910390f35b60008160020290505b9190505600a165627a7a72305820ccdadd737e4ac7039963b54cee5e5afb25fa859a275252bdcf06f653155228210029`)
|
||||
byteCode, err := types.DecodeHex(`0x6060604052341561000c57fe5b5b60a58061001b6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680636ffa1caa14603a575bfe5b3415604157fe5b60556004808035906020019091905050606b565b6040518082815260200191505060405180910390f35b60008160020290505b9190505600a165627a7a72305820ccdadd737e4ac7039963b54cee5e5afb25fa859a275252bdcf06f653155228210029`)
|
||||
s.NoError(err)
|
||||
|
||||
gas := uint64(params.DefaultGas)
|
||||
args := transactions.SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: nil, // marker, contract creation is expected
|
||||
//Value: (*hexutil.Big)(new(big.Int).Mul(big.NewInt(1), gethcommon.Ether)),
|
||||
//Value: (*hexutil.Big)(new(big.Int).Mul(big.NewInt(1), common.Ether)),
|
||||
Gas: (*hexutil.Uint64)(&gas),
|
||||
}
|
||||
|
||||
|
@ -213,7 +212,7 @@ func (s *TransactionsTestSuite) testSendContractTx(setInputAndDataValue initFunc
|
|||
return
|
||||
}
|
||||
s.NoError(err)
|
||||
s.False(reflect.DeepEqual(hash, gethcommon.Hash{}))
|
||||
s.False(reflect.DeepEqual(hash, types.Hash{}))
|
||||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestSendEther() {
|
||||
|
@ -222,7 +221,7 @@ func (s *TransactionsTestSuite) TestSendEther() {
|
|||
s.Require().NoError(err)
|
||||
defer os.Remove(tmpdir)
|
||||
|
||||
wallet := common.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
wallet := types.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
s.StartTestBackendWithAccount(multiaccounts.Account{KeyUID: utils.TestConfig.Account1.WalletAddress}, utils.TestConfig.Account1.Password,
|
||||
[]accounts.Account{{Address: wallet, Wallet: true, Chat: true}},
|
||||
e2e.WithDataDir(tmpdir),
|
||||
|
@ -232,12 +231,12 @@ func (s *TransactionsTestSuite) TestSendEther() {
|
|||
utils.EnsureNodeSync(s.Backend.StatusNode().EnsureSync)
|
||||
|
||||
hash, err := s.Backend.SendTransaction(transactions.SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
Value: (*hexutil.Big)(big.NewInt(1000000000000)),
|
||||
}, utils.TestConfig.Account1.Password)
|
||||
s.NoError(err)
|
||||
s.False(reflect.DeepEqual(hash, gethcommon.Hash{}))
|
||||
s.False(reflect.DeepEqual(hash, types.Hash{}))
|
||||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
|
||||
|
@ -249,7 +248,7 @@ func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
|
|||
addr, err := utils.GetRemoteURL()
|
||||
s.NoError(err)
|
||||
|
||||
wallet := common.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
wallet := types.HexToAddress(utils.TestConfig.Account1.WalletAddress)
|
||||
s.StartTestBackendWithAccount(multiaccounts.Account{KeyUID: utils.TestConfig.Account1.WalletAddress}, utils.TestConfig.Account1.Password,
|
||||
[]accounts.Account{{Address: wallet, Wallet: true, Chat: true}},
|
||||
e2e.WithUpstream(addr),
|
||||
|
@ -258,11 +257,11 @@ func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
|
|||
defer s.LogoutAndStop()
|
||||
|
||||
hash, err := s.Backend.SendTransaction(transactions.SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
GasPrice: (*hexutil.Big)(big.NewInt(28000000000)),
|
||||
Value: (*hexutil.Big)(big.NewInt(1000000000000)),
|
||||
}, utils.TestConfig.Account1.Password)
|
||||
s.NoError(err)
|
||||
s.False(reflect.DeepEqual(hash, gethcommon.Hash{}))
|
||||
s.False(reflect.DeepEqual(hash, types.Hash{}))
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@ import (
|
|||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
e2e "github.com/status-im/status-go/t/e2e"
|
||||
. "github.com/status-im/status-go/t/utils"
|
||||
"github.com/status-im/status-go/whisper/v6"
|
||||
|
@ -25,9 +24,9 @@ type WhisperTestSuite struct {
|
|||
|
||||
func buildLoginParams(mainAccountAddress, chatAddress, password string) account.LoginParams {
|
||||
return account.LoginParams{
|
||||
ChatAddress: common.HexToAddress(chatAddress),
|
||||
ChatAddress: types.HexToAddress(chatAddress),
|
||||
Password: password,
|
||||
MainAccount: common.HexToAddress(mainAccountAddress),
|
||||
MainAccount: types.HexToAddress(mainAccountAddress),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +169,7 @@ func (s *WhisperTestSuite) TestSelectedAccountOnRestart() {
|
|||
// make sure that no wallet account is selected by default
|
||||
selectedWalletAccount, err := s.Backend.AccountManager().MainAccountAddress()
|
||||
s.EqualError(account.ErrNoAccountSelected, err.Error(), "account selected, but should not be")
|
||||
s.Equal(common.Address{}, selectedWalletAccount)
|
||||
s.Equal(types.Address{}, selectedWalletAccount)
|
||||
|
||||
// make sure that no chat account is selected by default
|
||||
selectedChatAccount, err := s.Backend.AccountManager().SelectedChatAccount()
|
||||
|
@ -186,7 +185,7 @@ func (s *WhisperTestSuite) TestSelectedAccountOnRestart() {
|
|||
s.NoError(s.Backend.SelectAccount(buildLoginParams(accountInfo1.WalletAddress, accountInfo1.ChatAddress, TestConfig.Account1.Password)))
|
||||
selectedChatAccount1, err := s.Backend.AccountManager().SelectedChatAccount()
|
||||
s.NoError(err)
|
||||
selectedChatPubKey1 := hexutil.Encode(crypto.FromECDSAPub(&selectedChatAccount1.AccountKey.PrivateKey.PublicKey))
|
||||
selectedChatPubKey1 := types.EncodeHex(crypto.FromECDSAPub(&selectedChatAccount1.AccountKey.PrivateKey.PublicKey))
|
||||
s.Equal(selectedChatPubKey1, accountInfo1.ChatPubKey)
|
||||
s.True(whisperService.HasKeyPair(selectedChatPubKey1), "identity not injected into whisper")
|
||||
|
||||
|
@ -195,7 +194,7 @@ func (s *WhisperTestSuite) TestSelectedAccountOnRestart() {
|
|||
s.NoError(s.Backend.SelectAccount(buildLoginParams(accountInfo2.WalletAddress, accountInfo2.ChatAddress, TestConfig.Account2.Password)))
|
||||
selectedChatAccount2, err := s.Backend.AccountManager().SelectedChatAccount()
|
||||
s.NoError(err)
|
||||
selectedChatPubKey2 := hexutil.Encode(crypto.FromECDSAPub(&selectedChatAccount2.AccountKey.PrivateKey.PublicKey))
|
||||
selectedChatPubKey2 := types.EncodeHex(crypto.FromECDSAPub(&selectedChatAccount2.AccountKey.PrivateKey.PublicKey))
|
||||
s.Equal(selectedChatPubKey2, accountInfo2.ChatPubKey)
|
||||
s.True(whisperService.HasKeyPair(selectedChatPubKey2), "identity not injected into whisper")
|
||||
s.False(whisperService.HasKeyPair(selectedChatPubKey1), "identity should be removed, but it is still present in whisper")
|
||||
|
@ -241,7 +240,7 @@ func (s *WhisperTestSuite) TestSelectedAccountOnRestart() {
|
|||
|
||||
selectedWalletAccount, err = s.Backend.AccountManager().MainAccountAddress()
|
||||
s.EqualError(account.ErrNoAccountSelected, err.Error())
|
||||
s.Equal(common.Address{}, selectedWalletAccount)
|
||||
s.Equal(types.Address{}, selectedWalletAccount)
|
||||
|
||||
selectedChatAccount, err = s.Backend.AccountManager().SelectedChatAccount()
|
||||
s.EqualError(account.ErrNoAccountSelected, err.Error())
|
||||
|
@ -267,6 +266,6 @@ func (s *WhisperTestSuite) TestSelectedChatKeyIsUsedInWhisper() {
|
|||
s.NoError(err)
|
||||
|
||||
// chat key should be injected in whisper
|
||||
selectedChatPubKey := hexutil.Encode(crypto.FromECDSAPub(&selectedChatAccount.AccountKey.PrivateKey.PublicKey))
|
||||
selectedChatPubKey := types.EncodeHex(crypto.FromECDSAPub(&selectedChatAccount.AccountKey.PrivateKey.PublicKey))
|
||||
s.True(whisperService.HasKeyPair(selectedChatPubKey), "identity not injected in whisper")
|
||||
}
|
||||
|
|
|
@ -13,17 +13,17 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
gethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
gethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
gethparams "github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
gethrpc "github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/status-im/status-go/account"
|
||||
"github.com/status-im/status-go/contracts/ens/contract"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/t/utils"
|
||||
|
@ -82,7 +82,7 @@ func (s *TransactorSuite) setupTransactionPoolAPI(args SendTxArgs, returnNonce,
|
|||
// And also set the expected gas and gas price for RLP encoding the expected tx.
|
||||
var usedGas hexutil.Uint64
|
||||
var usedGasPrice *big.Int
|
||||
s.txServiceMock.EXPECT().GetTransactionCount(gomock.Any(), account.Address, gethrpc.PendingBlockNumber).Return(&returnNonce, nil)
|
||||
s.txServiceMock.EXPECT().GetTransactionCount(gomock.Any(), gomock.Eq(common.Address(account.Address)), gethrpc.PendingBlockNumber).Return(&returnNonce, nil)
|
||||
if args.GasPrice == nil {
|
||||
usedGasPrice = (*big.Int)(testGasPrice)
|
||||
s.txServiceMock.EXPECT().GasPrice(gomock.Any()).Return(testGasPrice, nil)
|
||||
|
@ -98,11 +98,11 @@ func (s *TransactorSuite) setupTransactionPoolAPI(args SendTxArgs, returnNonce,
|
|||
// Prepare the transaction and RLP encode it.
|
||||
data := s.rlpEncodeTx(args, s.nodeConfig, account, &resultNonce, usedGas, usedGasPrice)
|
||||
// Expect the RLP encoded transaction.
|
||||
s.txServiceMock.EXPECT().SendRawTransaction(gomock.Any(), data).Return(gethcommon.Hash{}, txErr)
|
||||
s.txServiceMock.EXPECT().SendRawTransaction(gomock.Any(), data).Return(common.Hash{}, txErr)
|
||||
}
|
||||
|
||||
func (s *TransactorSuite) rlpEncodeTx(args SendTxArgs, config *params.NodeConfig, account *account.SelectedExtKey, nonce *hexutil.Uint64, gas hexutil.Uint64, gasPrice *big.Int) hexutil.Bytes {
|
||||
newTx := types.NewTransaction(
|
||||
newTx := gethtypes.NewTransaction(
|
||||
uint64(*nonce),
|
||||
*args.To,
|
||||
args.Value.ToInt(),
|
||||
|
@ -111,7 +111,7 @@ func (s *TransactorSuite) rlpEncodeTx(args SendTxArgs, config *params.NodeConfig
|
|||
[]byte(args.Input),
|
||||
)
|
||||
chainID := big.NewInt(int64(config.NetworkID))
|
||||
signedTx, err := types.SignTx(newTx, types.NewEIP155Signer(chainID), account.AccountKey.PrivateKey)
|
||||
signedTx, err := gethtypes.SignTx(newTx, gethtypes.NewEIP155Signer(chainID), account.AccountKey.PrivateKey)
|
||||
s.NoError(err)
|
||||
data, err := rlp.EncodeToBytes(signedTx)
|
||||
s.NoError(err)
|
||||
|
@ -119,7 +119,7 @@ func (s *TransactorSuite) rlpEncodeTx(args SendTxArgs, config *params.NodeConfig
|
|||
}
|
||||
|
||||
func (s *TransactorSuite) TestGasValues() {
|
||||
key, _ := crypto.GenerateKey()
|
||||
key, _ := gethcrypto.GenerateKey()
|
||||
selectedAccount := &account.SelectedExtKey{
|
||||
Address: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
AccountKey: &keystore.Key{PrivateKey: key},
|
||||
|
@ -155,8 +155,8 @@ func (s *TransactorSuite) TestGasValues() {
|
|||
s.T().Run(testCase.name, func(t *testing.T) {
|
||||
s.SetupTest()
|
||||
args := SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
Gas: testCase.gas,
|
||||
GasPrice: testCase.gasPrice,
|
||||
}
|
||||
|
@ -164,15 +164,15 @@ func (s *TransactorSuite) TestGasValues() {
|
|||
|
||||
hash, err := s.manager.SendTransaction(args, selectedAccount)
|
||||
s.NoError(err)
|
||||
s.False(reflect.DeepEqual(hash, gethcommon.Hash{}))
|
||||
s.False(reflect.DeepEqual(hash, common.Hash{}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TransactorSuite) TestArgsValidation() {
|
||||
args := SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
Data: hexutil.Bytes([]byte{0x01, 0x02}),
|
||||
Input: hexutil.Bytes([]byte{0x02, 0x01}),
|
||||
}
|
||||
|
@ -186,8 +186,8 @@ func (s *TransactorSuite) TestArgsValidation() {
|
|||
|
||||
func (s *TransactorSuite) TestAccountMismatch() {
|
||||
args := SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
}
|
||||
|
||||
var err error
|
||||
|
@ -213,7 +213,7 @@ func (s *TransactorSuite) TestAccountMismatch() {
|
|||
// as the last step, we verify that if tx failed nonce is not updated
|
||||
func (s *TransactorSuite) TestLocalNonce() {
|
||||
txCount := 3
|
||||
key, _ := crypto.GenerateKey()
|
||||
key, _ := gethcrypto.GenerateKey()
|
||||
selectedAccount := &account.SelectedExtKey{
|
||||
Address: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
AccountKey: &keystore.Key{PrivateKey: key},
|
||||
|
@ -222,8 +222,8 @@ func (s *TransactorSuite) TestLocalNonce() {
|
|||
|
||||
for i := 0; i < txCount; i++ {
|
||||
args := SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
}
|
||||
s.setupTransactionPoolAPI(args, nonce, hexutil.Uint64(i), selectedAccount, nil)
|
||||
|
||||
|
@ -235,8 +235,8 @@ func (s *TransactorSuite) TestLocalNonce() {
|
|||
|
||||
nonce = hexutil.Uint64(5)
|
||||
args := SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
}
|
||||
|
||||
s.setupTransactionPoolAPI(args, nonce, nonce, selectedAccount, nil)
|
||||
|
@ -248,10 +248,10 @@ func (s *TransactorSuite) TestLocalNonce() {
|
|||
s.Equal(uint64(nonce)+1, resultNonce.(uint64))
|
||||
|
||||
testErr := errors.New("test")
|
||||
s.txServiceMock.EXPECT().GetTransactionCount(gomock.Any(), selectedAccount.Address, gethrpc.PendingBlockNumber).Return(nil, testErr)
|
||||
s.txServiceMock.EXPECT().GetTransactionCount(gomock.Any(), gomock.Eq(common.Address(selectedAccount.Address)), gethrpc.PendingBlockNumber).Return(nil, testErr)
|
||||
args = SendTxArgs{
|
||||
From: account.FromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.ToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
From: account.GethFromAddress(utils.TestConfig.Account1.WalletAddress),
|
||||
To: account.GethToAddress(utils.TestConfig.Account2.WalletAddress),
|
||||
}
|
||||
|
||||
_, err = s.manager.SendTransaction(args, selectedAccount)
|
||||
|
@ -261,14 +261,14 @@ func (s *TransactorSuite) TestLocalNonce() {
|
|||
}
|
||||
|
||||
func (s *TransactorSuite) TestContractCreation() {
|
||||
key, _ := crypto.GenerateKey()
|
||||
testaddr := crypto.PubkeyToAddress(key.PublicKey)
|
||||
key, _ := gethcrypto.GenerateKey()
|
||||
testaddr := gethcrypto.PubkeyToAddress(key.PublicKey)
|
||||
genesis := core.GenesisAlloc{
|
||||
testaddr: {Balance: big.NewInt(100000000000)},
|
||||
}
|
||||
backend := backends.NewSimulatedBackend(genesis, math.MaxInt64)
|
||||
selectedAccount := &account.SelectedExtKey{
|
||||
Address: testaddr,
|
||||
Address: types.Address(testaddr),
|
||||
AccountKey: &keystore.Key{PrivateKey: key},
|
||||
}
|
||||
s.manager.sender = backend
|
||||
|
@ -276,7 +276,7 @@ func (s *TransactorSuite) TestContractCreation() {
|
|||
s.manager.pendingNonceProvider = backend
|
||||
tx := SendTxArgs{
|
||||
From: testaddr,
|
||||
Input: hexutil.Bytes(gethcommon.FromHex(contract.ENSBin)),
|
||||
Input: hexutil.Bytes(common.FromHex(contract.ENSBin)),
|
||||
}
|
||||
|
||||
hash, err := s.manager.SendTransaction(tx, selectedAccount)
|
||||
|
@ -284,13 +284,13 @@ func (s *TransactorSuite) TestContractCreation() {
|
|||
backend.Commit()
|
||||
receipt, err := backend.TransactionReceipt(context.TODO(), common.Hash(hash))
|
||||
s.NoError(err)
|
||||
s.Equal(crypto.CreateAddress(testaddr, 0), receipt.ContractAddress)
|
||||
s.Equal(gethcrypto.CreateAddress(testaddr, 0), receipt.ContractAddress)
|
||||
}
|
||||
|
||||
func (s *TransactorSuite) TestSendTransactionWithSignature() {
|
||||
privKey, err := crypto.GenerateKey()
|
||||
privKey, err := gethcrypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
address := crypto.PubkeyToAddress(privKey.PublicKey)
|
||||
address := gethcrypto.PubkeyToAddress(privKey.PublicKey)
|
||||
|
||||
scenarios := []struct {
|
||||
localNonce hexutil.Uint64
|
||||
|
@ -339,10 +339,10 @@ func (s *TransactorSuite) TestSendTransactionWithSignature() {
|
|||
}
|
||||
|
||||
// simulate transaction signed externally
|
||||
signer := types.NewEIP155Signer(chainID)
|
||||
tx := types.NewTransaction(uint64(nonce), to, (*big.Int)(value), uint64(gas), (*big.Int)(gasPrice), data)
|
||||
signer := gethtypes.NewEIP155Signer(chainID)
|
||||
tx := gethtypes.NewTransaction(uint64(nonce), to, (*big.Int)(value), uint64(gas), (*big.Int)(gasPrice), data)
|
||||
hash := signer.Hash(tx)
|
||||
sig, err := crypto.Sign(hash[:], privKey)
|
||||
sig, err := gethcrypto.Sign(hash[:], privKey)
|
||||
s.Require().NoError(err)
|
||||
txWithSig, err := tx.WithSignature(signer, sig)
|
||||
s.Require().NoError(err)
|
||||
|
@ -356,7 +356,7 @@ func (s *TransactorSuite) TestSendTransactionWithSignature() {
|
|||
if !scenario.expectError {
|
||||
s.txServiceMock.EXPECT().
|
||||
SendRawTransaction(gomock.Any(), hexutil.Bytes(expectedEncodedTx)).
|
||||
Return(gethcommon.Hash{}, nil)
|
||||
Return(common.Hash{}, nil)
|
||||
}
|
||||
|
||||
_, err = s.manager.SendTransactionWithSignature(args, sig)
|
||||
|
@ -382,9 +382,9 @@ func (s *TransactorSuite) TestSendTransactionWithSignature_InvalidSignature() {
|
|||
}
|
||||
|
||||
func (s *TransactorSuite) TestHashTransaction() {
|
||||
privKey, err := crypto.GenerateKey()
|
||||
privKey, err := gethcrypto.GenerateKey()
|
||||
s.Require().NoError(err)
|
||||
address := crypto.PubkeyToAddress(privKey.PublicKey)
|
||||
address := gethcrypto.PubkeyToAddress(privKey.PublicKey)
|
||||
|
||||
remoteNonce := hexutil.Uint64(1)
|
||||
txNonce := hexutil.Uint64(0)
|
||||
|
|
Loading…
Reference in New Issue