mirror of
https://github.com/status-im/status-go.git
synced 2025-01-11 23:25:29 +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
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package persistence
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"database/sql"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
"github.com/status-im/status-go/t/helpers"
|
|
"github.com/status-im/status-go/walletdatabase"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var testDApp = DApp{
|
|
Name: "Test DApp",
|
|
URL: "https://test-dapp-url.com",
|
|
IconURL: "https://test-dapp-icon-url.com",
|
|
SharedAccount: types.HexToAddress("0x1234567890"),
|
|
ChainID: 0x1,
|
|
}
|
|
|
|
func setupTestDB(t *testing.T) (db *sql.DB, close func()) {
|
|
db, err := helpers.SetupTestMemorySQLDB(walletdatabase.DbInitializer{})
|
|
require.NoError(t, err)
|
|
return db, func() {
|
|
require.NoError(t, db.Close())
|
|
}
|
|
}
|
|
|
|
func TestInsertAndSelectDApp(t *testing.T) {
|
|
db, close := setupTestDB(t)
|
|
defer close()
|
|
|
|
err := UpsertDApp(db, &testDApp)
|
|
require.NoError(t, err)
|
|
|
|
dAppBack, err := SelectDAppByUrl(db, testDApp.URL)
|
|
require.NoError(t, err)
|
|
require.Equal(t, &testDApp, dAppBack)
|
|
}
|
|
|
|
func TestInsertAndUpdateDApp(t *testing.T) {
|
|
db, close := setupTestDB(t)
|
|
defer close()
|
|
|
|
err := UpsertDApp(db, &testDApp)
|
|
require.NoError(t, err)
|
|
|
|
updatedDApp := DApp{
|
|
Name: "Updated Test DApp",
|
|
URL: testDApp.URL,
|
|
IconURL: "https://updated-test-dapp-icon-url.com",
|
|
}
|
|
|
|
err = UpsertDApp(db, &updatedDApp)
|
|
require.NoError(t, err)
|
|
|
|
dAppBack, err := SelectDAppByUrl(db, testDApp.URL)
|
|
require.NoError(t, err)
|
|
require.Equal(t, &updatedDApp, dAppBack)
|
|
require.NotEqual(t, &testDApp, dAppBack)
|
|
}
|
|
|
|
func TestInsertAndRemoveDApp(t *testing.T) {
|
|
db, close := setupTestDB(t)
|
|
defer close()
|
|
|
|
err := UpsertDApp(db, &testDApp)
|
|
require.NoError(t, err)
|
|
|
|
dAppBack, err := SelectDAppByUrl(db, testDApp.URL)
|
|
require.NoError(t, err)
|
|
require.Equal(t, &testDApp, dAppBack)
|
|
|
|
err = DeleteDApp(db, testDApp.URL)
|
|
require.NoError(t, err)
|
|
|
|
dAppBack, err = SelectDAppByUrl(db, testDApp.URL)
|
|
require.NoError(t, err)
|
|
require.Empty(t, dAppBack)
|
|
}
|