2017-10-11 14:20:51 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/e2e"
|
2017-10-26 13:14:11 +00:00
|
|
|
"github.com/status-im/status-go/geth/params"
|
2017-10-11 14:20:51 +00:00
|
|
|
. "github.com/status-im/status-go/testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccountsRPCTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(AccountsRPCTestSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccountsRPCTestSuite struct {
|
|
|
|
e2e.BackendTestSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AccountsTestSuite) TestRPCEthAccounts() {
|
2017-10-23 16:03:07 +00:00
|
|
|
s.StartTestBackend()
|
2017-10-11 14:20:51 +00:00
|
|
|
defer s.StopTestBackend()
|
|
|
|
|
|
|
|
// log into test account
|
|
|
|
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
rpcClient := s.Backend.NodeManager().RPCClient()
|
|
|
|
s.NotNil(rpcClient)
|
|
|
|
|
|
|
|
expectedResponse := `{"jsonrpc":"2.0","id":1,"result":["` + strings.ToLower(TestConfig.Account1.Address) + `"]}`
|
|
|
|
resp := rpcClient.CallRaw(`{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"id": 1,
|
|
|
|
"method": "eth_accounts",
|
|
|
|
"params": []
|
|
|
|
}`)
|
|
|
|
s.Equal(expectedResponse, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *AccountsTestSuite) TestRPCEthAccountsWithUpstream() {
|
2017-10-26 12:33:42 +00:00
|
|
|
if GetNetworkID() == params.StatusChainNetworkID {
|
|
|
|
s.T().Skip()
|
|
|
|
}
|
|
|
|
|
2017-10-26 13:11:24 +00:00
|
|
|
addr, err := GetRemoteURL()
|
2017-10-25 12:37:42 +00:00
|
|
|
s.NoError(err)
|
|
|
|
s.StartTestBackend(e2e.WithUpstream(addr))
|
2017-10-11 14:20:51 +00:00
|
|
|
defer s.StopTestBackend()
|
|
|
|
|
|
|
|
// log into test account
|
2017-10-25 12:37:42 +00:00
|
|
|
err = s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
2017-10-11 14:20:51 +00:00
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
rpcClient := s.Backend.NodeManager().RPCClient()
|
|
|
|
s.NotNil(rpcClient)
|
|
|
|
|
|
|
|
expectedResponse := `{"jsonrpc":"2.0","id":1,"result":["` + strings.ToLower(TestConfig.Account1.Address) + `"]}`
|
|
|
|
resp := rpcClient.CallRaw(`{
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"id": 1,
|
|
|
|
"method": "eth_accounts",
|
|
|
|
"params": []
|
|
|
|
}`)
|
|
|
|
s.Equal(expectedResponse, resp)
|
|
|
|
}
|