2024-07-18 15:30:10 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFailToGetAccountWithMissingDAppFields(t *testing.T) {
|
|
|
|
db, close := SetupTestDB(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
cmd := &AccountsCommand{Db: db}
|
|
|
|
|
|
|
|
// Missing DApp fields
|
|
|
|
request, err := ConstructRPCRequest("eth_accounts", []interface{}{}, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
result, err := cmd.Execute(request)
|
|
|
|
assert.Equal(t, ErrRequestMissingDAppData, err)
|
|
|
|
assert.Empty(t, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFailToGetAccountForUnpermittedDApp(t *testing.T) {
|
|
|
|
db, close := SetupTestDB(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
cmd := &AccountsCommand{Db: db}
|
|
|
|
|
|
|
|
request, err := ConstructRPCRequest("eth_accounts", []interface{}{}, &testDAppData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
result, err := cmd.Execute(request)
|
|
|
|
assert.Equal(t, ErrDAppIsNotPermittedByUser, err)
|
|
|
|
assert.Empty(t, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetAccountForPermittedDApp(t *testing.T) {
|
|
|
|
db, close := SetupTestDB(t)
|
|
|
|
defer close()
|
|
|
|
|
|
|
|
cmd := &AccountsCommand{Db: db}
|
|
|
|
|
|
|
|
sharedAccount := types.HexToAddress("0x6d0aa2a774b74bb1d36f97700315adf962c69fcg")
|
|
|
|
|
|
|
|
err := PersistDAppData(db, testDAppData, sharedAccount, 0x123)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
request, err := ConstructRPCRequest("eth_accounts", []interface{}{}, &testDAppData)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2024-08-02 07:43:31 +00:00
|
|
|
expectedResponse := FormatAccountAddressToResponse(sharedAccount)
|
2024-07-18 15:30:10 +00:00
|
|
|
response, err := cmd.Execute(request)
|
|
|
|
assert.NoError(t, err)
|
2024-08-02 07:43:31 +00:00
|
|
|
assert.Equal(t, expectedResponse, response)
|
2024-07-18 15:30:10 +00:00
|
|
|
}
|