mirror of
https://github.com/status-im/status-go.git
synced 2025-02-07 12:25:20 +00:00
* 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
99 lines
2.4 KiB
Go
99 lines
2.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
"github.com/status-im/status-go/params"
|
|
walletCommon "github.com/status-im/status-go/services/wallet/common"
|
|
)
|
|
|
|
func TestFailToSwitchEthereumChainWithMissingDAppFields(t *testing.T) {
|
|
db, close := SetupTestDB(t)
|
|
defer close()
|
|
|
|
cmd := &SwitchEthereumChainCommand{Db: db}
|
|
|
|
// Missing DApp fields
|
|
request, err := ConstructRPCRequest("wallet_switchEthereumChain", []interface{}{}, nil)
|
|
assert.NoError(t, err)
|
|
|
|
result, err := cmd.Execute(request)
|
|
assert.Equal(t, ErrRequestMissingDAppData, err)
|
|
assert.Empty(t, result)
|
|
}
|
|
|
|
func TestFailToSwitchEthereumChainWithNoChainId(t *testing.T) {
|
|
db, close := SetupTestDB(t)
|
|
defer close()
|
|
|
|
cmd := &SwitchEthereumChainCommand{Db: db}
|
|
|
|
request, err := ConstructRPCRequest("wallet_switchEthereumChain", []interface{}{}, &testDAppData)
|
|
assert.NoError(t, err)
|
|
|
|
_, err = cmd.Execute(request)
|
|
assert.Equal(t, ErrEmptyRPCParams, err)
|
|
}
|
|
|
|
func TestFailToSwitchEthereumChainWithUnsupportedChainId(t *testing.T) {
|
|
db, close := SetupTestDB(t)
|
|
defer close()
|
|
|
|
nm := NetworkManagerMock{}
|
|
nm.SetNetworks([]*params.Network{
|
|
{
|
|
ChainID: walletCommon.EthereumMainnet,
|
|
},
|
|
})
|
|
|
|
cmd := &SwitchEthereumChainCommand{
|
|
Db: db,
|
|
NetworkManager: &nm,
|
|
}
|
|
|
|
params := make([]interface{}, 1)
|
|
params[0] = walletCommon.BinanceTestChainID // some unrecoginzed chain id
|
|
|
|
request, err := ConstructRPCRequest("wallet_switchEthereumChain", params, &testDAppData)
|
|
assert.NoError(t, err)
|
|
|
|
_, err = cmd.Execute(request)
|
|
assert.Equal(t, ErrUnsupportedNetwork, err)
|
|
}
|
|
|
|
func TestSwitchEthereumChain(t *testing.T) {
|
|
db, close := SetupTestDB(t)
|
|
defer close()
|
|
|
|
nm := NetworkManagerMock{}
|
|
nm.SetNetworks([]*params.Network{
|
|
{
|
|
ChainID: walletCommon.EthereumMainnet,
|
|
},
|
|
{
|
|
ChainID: walletCommon.EthereumGoerli,
|
|
},
|
|
})
|
|
|
|
cmd := &SwitchEthereumChainCommand{
|
|
Db: db,
|
|
NetworkManager: &nm,
|
|
}
|
|
|
|
params := make([]interface{}, 1)
|
|
params[0] = walletCommon.EthereumMainnet
|
|
|
|
request, err := ConstructRPCRequest("wallet_switchEthereumChain", params, &testDAppData)
|
|
assert.NoError(t, err)
|
|
|
|
err = PersistDAppData(db, testDAppData, types.HexToAddress("0x6d0aa2a774b74bb1d36f97700315adf962c69fcg"), walletCommon.EthereumMainnet)
|
|
assert.NoError(t, err)
|
|
|
|
response, err := cmd.Execute(request)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, walletCommon.ChainID(walletCommon.EthereumMainnet).String(), response)
|
|
}
|