mirror of
https://github.com/status-im/status-go.git
synced 2025-01-10 06:36:32 +00:00
4c6ca00520
* feat(connector)_: impl `eth_requestAccounts` for browser plugin * feat(connector)_: add impl for `wallet_switchEthereumChain` and `eth_chainId` * feat(connector)_: add impl for `eth_sendTransaction` * feat(connector)_: add a signal and an endpoint for wallet ui side * chore_: refactor connector tests * feat(connector)_: impl `eth_requestAccounts` with signal * chore(connector)_: Add test, covering full transaction flow And polish impl & test for connector endpoints * fix(connector)_: temporary allow all origins for ws connection * chore_: review fixes * fix(connector)_: make user select chain id for dApp * fix(connector)_: add requestID and fine tune endpoints * chore(connector)_: naming fixes and tests improvments
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package commands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
walletCommon "github.com/status-im/status-go/services/wallet/common"
|
|
)
|
|
|
|
func TestFailToGetChainIdWithMissingDAppFields(t *testing.T) {
|
|
db, close := SetupTestDB(t)
|
|
defer close()
|
|
|
|
cmd := &ChainIDCommand{Db: db}
|
|
|
|
// Missing DApp fields
|
|
request, err := ConstructRPCRequest("eth_chainId", []interface{}{}, nil)
|
|
assert.NoError(t, err)
|
|
|
|
result, err := cmd.Execute(request)
|
|
assert.Equal(t, ErrRequestMissingDAppData, err)
|
|
assert.Empty(t, result)
|
|
}
|
|
|
|
func TestFailToGetChainIdForUnpermittedDApp(t *testing.T) {
|
|
db, close := SetupTestDB(t)
|
|
defer close()
|
|
|
|
cmd := &ChainIDCommand{Db: db}
|
|
|
|
request, err := ConstructRPCRequest("eth_chainId", []interface{}{}, &testDAppData)
|
|
assert.NoError(t, err)
|
|
|
|
result, err := cmd.Execute(request)
|
|
assert.Equal(t, ErrDAppIsNotPermittedByUser, err)
|
|
assert.Empty(t, result)
|
|
}
|
|
|
|
func TestGetChainIdForPermittedDApp(t *testing.T) {
|
|
db, close := SetupTestDB(t)
|
|
defer close()
|
|
|
|
cmd := &ChainIDCommand{Db: db}
|
|
|
|
sharedAccount := types.HexToAddress("0x6d0aa2a774b74bb1d36f97700315adf962c69fcg")
|
|
chainID := uint64(0x123)
|
|
|
|
err := PersistDAppData(db, testDAppData, sharedAccount, chainID)
|
|
assert.NoError(t, err)
|
|
|
|
request, err := ConstructRPCRequest("eth_chainId", []interface{}{}, &testDAppData)
|
|
assert.NoError(t, err)
|
|
|
|
response, err := cmd.Execute(request)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, walletCommon.ChainID(chainID).String(), response)
|
|
}
|