2018-04-10 12:02:54 +02:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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 13:04:02 +02:00
|
|
|
. "github.com/status-im/status-go/t/utils"
|
2018-04-10 12:02:54 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-08-16 04:37:53 -07:00
|
|
|
signDataString = "0xBAADBEEF"
|
2018-04-10 12:02:54 +02:00
|
|
|
)
|
|
|
|
|
2018-08-16 04:37:53 -07:00
|
|
|
type PersonalSignSuite struct {
|
|
|
|
upstream bool
|
|
|
|
BaseJSONRPCSuite
|
2018-04-10 12:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPersonalSignSuiteUpstream(t *testing.T) {
|
|
|
|
s := new(PersonalSignSuite)
|
|
|
|
s.upstream = true
|
|
|
|
suite.Run(t, s)
|
|
|
|
}
|
|
|
|
|
2018-04-18 13:04:02 +02:00
|
|
|
func (s *PersonalSignSuite) TestRestrictedPersonalAPIs() {
|
|
|
|
if s.upstream && GetNetworkID() == params.StatusChainNetworkID {
|
|
|
|
s.T().Skip()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-16 04:37:53 -07:00
|
|
|
err := s.SetupTest(true, false, false)
|
2018-04-18 13:04:02 +02:00
|
|
|
s.NoError(err)
|
|
|
|
defer func() {
|
|
|
|
err := s.Backend.StopNode()
|
|
|
|
s.NoError(err)
|
|
|
|
}()
|
|
|
|
// These personal APIs should be available
|
2018-05-03 12:36:56 +02:00
|
|
|
s.AssertAPIMethodExported("personal_sign")
|
|
|
|
s.AssertAPIMethodExported("personal_ecRecover")
|
2018-04-18 13:04:02 +02:00
|
|
|
// These personal APIs shouldn't be exported
|
2018-05-03 12:36:56 +02:00
|
|
|
s.AssertAPIMethodUnexported("personal_sendTransaction")
|
|
|
|
s.AssertAPIMethodUnexported("personal_unlockAccount")
|
|
|
|
s.AssertAPIMethodUnexported("personal_newAccount")
|
|
|
|
s.AssertAPIMethodUnexported("personal_lockAccount")
|
|
|
|
s.AssertAPIMethodUnexported("personal_listAccounts")
|
|
|
|
s.AssertAPIMethodUnexported("personal_importRawKey")
|
2018-04-18 13:04:02 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 04:37:53 -07:00
|
|
|
func (s *PersonalSignSuite) TestPersonalSignUnsupportedMethod() {
|
2018-04-10 12:02:54 +02:00
|
|
|
// Test upstream if that's not StatusChain
|
|
|
|
if s.upstream && GetNetworkID() == params.StatusChainNetworkID {
|
|
|
|
s.T().Skip()
|
|
|
|
}
|
|
|
|
|
2018-08-16 04:37:53 -07:00
|
|
|
err := s.SetupTest(true, false, false)
|
2018-04-10 12:02:54 +02:00
|
|
|
s.NoError(err)
|
|
|
|
defer func() {
|
|
|
|
err := s.Backend.StopNode()
|
|
|
|
s.NoError(err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
basicCall := fmt.Sprintf(
|
|
|
|
`{"jsonrpc":"2.0","method":"personal_sign","params":["%s", "%s"],"id":67}`,
|
|
|
|
signDataString,
|
2019-01-18 10:01:14 +01:00
|
|
|
TestConfig.Account1.WalletAddress)
|
2018-04-10 12:02:54 +02:00
|
|
|
|
2018-12-20 09:31:17 +01:00
|
|
|
rawResult, err := s.Backend.CallRPC(basicCall)
|
|
|
|
s.NoError(err)
|
2018-08-16 04:37:53 -07:00
|
|
|
s.Contains(rawResult, `"error":{"code":-32700,"message":"method is unsupported by RPC interface"}`)
|
2018-04-10 12:02:54 +02:00
|
|
|
}
|
|
|
|
|
2018-08-16 04:37:53 -07:00
|
|
|
func (s *PersonalSignSuite) TestPersonalRecoverUnsupportedMethod() {
|
2018-04-18 13:04:02 +02:00
|
|
|
|
|
|
|
// Test upstream if that's not StatusChain
|
|
|
|
if s.upstream && GetNetworkID() == params.StatusChainNetworkID {
|
|
|
|
s.T().Skip()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-16 04:37:53 -07:00
|
|
|
err := s.SetupTest(true, false, false)
|
2018-04-18 13:04:02 +02:00
|
|
|
s.NoError(err)
|
|
|
|
defer func() {
|
|
|
|
err := s.Backend.StopNode()
|
|
|
|
s.NoError(err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// 2. Test recover
|
|
|
|
basicCall := fmt.Sprintf(
|
|
|
|
`{"jsonrpc":"2.0","method":"personal_ecRecover","params":["%s", "%s"],"id":67}`,
|
|
|
|
signDataString,
|
2018-08-16 04:37:53 -07:00
|
|
|
"")
|
2018-04-18 13:04:02 +02:00
|
|
|
|
2018-12-20 09:31:17 +01:00
|
|
|
rawResult, err := s.Backend.CallRPC(basicCall)
|
|
|
|
s.NoError(err)
|
2018-08-16 04:37:53 -07:00
|
|
|
s.Contains(rawResult, `"error":{"code":-32700,"message":"method is unsupported by RPC interface"}`)
|
2018-04-18 13:04:02 +02:00
|
|
|
}
|