2017-10-11 16:20:51 +02:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2020-01-02 10:10:19 +01:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
2018-06-08 13:29:50 +02:00
|
|
|
"github.com/status-im/status-go/params"
|
2018-04-18 17:13:27 +02:00
|
|
|
"github.com/status-im/status-go/t/e2e"
|
2018-02-08 20:52:47 +08:00
|
|
|
. "github.com/status-im/status-go/t/utils"
|
2017-10-11 16:20:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccountsRPCTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(AccountsRPCTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccountsRPCTestSuite struct {
|
|
|
|
e2e.BackendTestSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AccountsTestSuite) TestRPCEthAccounts() {
|
2017-10-23 17:03:07 +01:00
|
|
|
s.StartTestBackend()
|
2017-10-11 16:20:51 +02:00
|
|
|
defer s.StopTestBackend()
|
|
|
|
|
|
|
|
// log into test account
|
2020-12-15 19:00:31 +01:00
|
|
|
loginParams, err := buildLoginParams(TestConfig.Account1.WalletAddress, TestConfig.Account1.ChatAddress, TestConfig.Account1.Password, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = s.Backend.SelectAccount(loginParams)
|
2017-10-11 16:20:51 +02:00
|
|
|
s.NoError(err)
|
|
|
|
|
2018-04-05 11:45:26 +02:00
|
|
|
rpcClient := s.Backend.StatusNode().RPCClient()
|
2017-10-11 16:20:51 +02:00
|
|
|
s.NotNil(rpcClient)
|
|
|
|
|
2019-01-18 10:01:14 +01:00
|
|
|
expectedResponse := `{"jsonrpc":"2.0","id":1,"result":["` + strings.ToLower(TestConfig.Account1.WalletAddress) + `"]}`
|
2017-10-11 16:20:51 +02:00
|
|
|
resp := rpcClient.CallRaw(`{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"id": 1,
|
|
|
|
"method": "eth_accounts",
|
|
|
|
"params": []
|
|
|
|
}`)
|
2019-01-18 10:01:14 +01:00
|
|
|
|
2017-10-11 16:20:51 +02:00
|
|
|
s.Equal(expectedResponse, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AccountsTestSuite) TestRPCEthAccountsWithUpstream() {
|
2017-10-26 13:33:42 +01:00
|
|
|
if GetNetworkID() == params.StatusChainNetworkID {
|
|
|
|
s.T().Skip()
|
|
|
|
}
|
|
|
|
|
2017-10-26 14:11:24 +01:00
|
|
|
addr, err := GetRemoteURL()
|
2017-10-25 13:37:42 +01:00
|
|
|
s.NoError(err)
|
|
|
|
s.StartTestBackend(e2e.WithUpstream(addr))
|
2017-10-11 16:20:51 +02:00
|
|
|
defer s.StopTestBackend()
|
|
|
|
|
|
|
|
// log into test account
|
2020-12-15 19:00:31 +01:00
|
|
|
loginParams, err := buildLoginParams(TestConfig.Account1.WalletAddress, TestConfig.Account1.ChatAddress, TestConfig.Account1.Password, nil)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
err = s.Backend.SelectAccount(loginParams)
|
2017-10-11 16:20:51 +02:00
|
|
|
s.NoError(err)
|
|
|
|
|
2018-04-05 11:45:26 +02:00
|
|
|
rpcClient := s.Backend.StatusNode().RPCClient()
|
2017-10-11 16:20:51 +02:00
|
|
|
s.NotNil(rpcClient)
|
|
|
|
|
2019-01-18 10:01:14 +01:00
|
|
|
expectedResponse := `{"jsonrpc":"2.0","id":1,"result":["` + strings.ToLower(TestConfig.Account1.WalletAddress) + `"]}`
|
2017-10-11 16:20:51 +02:00
|
|
|
resp := rpcClient.CallRaw(`{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"id": 1,
|
|
|
|
"method": "eth_accounts",
|
|
|
|
"params": []
|
|
|
|
}`)
|
|
|
|
s.Equal(expectedResponse, resp)
|
|
|
|
}
|