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