status-go/services/ens/api_test.go

162 lines
4.7 KiB
Go
Raw Normal View History

2021-12-21 15:05:09 +00:00
package ens
import (
"context"
"database/sql"
"testing"
"time"
2021-12-21 15:05:09 +00:00
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
2021-12-21 15:05:09 +00:00
"github.com/ethereum/go-ethereum/common"
2021-12-21 15:05:09 +00:00
gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/status-im/status-go/appdatabase"
statusRPC "github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/t/helpers"
2021-12-21 15:05:09 +00:00
"github.com/status-im/status-go/t/utils"
"github.com/status-im/status-go/transactions/fake"
)
func createDB(t *testing.T) (*sql.DB, func()) {
db, cleanup, err := helpers.SetupTestSQLDB(appdatabase.DbInitializer{}, "service-ens-tests-")
2021-12-21 15:05:09 +00:00
require.NoError(t, err)
return db, func() { require.NoError(t, cleanup()) }
2021-12-21 15:05:09 +00:00
}
func setupTestAPI(t *testing.T) (*API, func()) {
db, cancel := createDB(t)
txServiceMockCtrl := gomock.NewController(t)
server, _ := fake.NewTestServer(txServiceMockCtrl)
client := gethrpc.DialInProc(server)
_ = client
config := statusRPC.ClientConfig{
Client: nil,
UpstreamChainID: 1,
Networks: nil,
DB: db,
WalletFeed: nil,
ProviderConfigs: nil,
}
rpcClient, err := statusRPC.NewClient(config)
2021-12-21 15:05:09 +00:00
require.NoError(t, err)
// import account keys
utils.Init()
require.NoError(t, utils.ImportTestAccount(t.TempDir(), utils.GetAccount1PKFile()))
2021-12-21 15:05:09 +00:00
return NewAPI(rpcClient, nil, nil, nil, db, time.Now, nil), cancel
2021-12-21 15:05:09 +00:00
}
func TestResolver(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
r, err := api.Resolver(context.Background(), 1, "rramos.eth")
require.NoError(t, err)
require.Equal(t, "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41", r.String())
}
func TestGetName(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
api, cancel := setupTestAPI(t)
defer cancel()
r, err := api.GetName(context.Background(), 1, common.HexToAddress("0x7d28Ab6948F3Db2F95A43742265D382a4888c120"))
require.NoError(t, err)
require.Equal(t, "rramos.eth", r)
}
2021-12-21 15:05:09 +00:00
func TestOwnerOf(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
r, err := api.OwnerOf(context.Background(), 1, "rramos.eth")
require.NoError(t, err)
require.Equal(t, "0x7d28Ab6948F3Db2F95A43742265D382a4888c120", r.String())
}
func TestContentHash(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
r, err := api.ContentHash(context.Background(), 1, "simpledapp.eth")
require.NoError(t, err)
require.Equal(t, []byte{0xe3, 0x1, 0x1, 0x70, 0x12, 0x20, 0x79, 0x5c, 0x1e, 0xa0, 0xce, 0xaf, 0x4c, 0xee, 0xdc, 0x98, 0x96, 0xf1, 0x4b, 0x73, 0xbb, 0x30, 0xe9, 0x78, 0xe4, 0x85, 0x5e, 0xe2, 0x21, 0xb9, 0xa5, 0x7f, 0x5a, 0x93, 0x42, 0x68, 0x28, 0xe}, r)
}
func TestPublicKeyOf(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
pubKey, err := api.PublicKeyOf(context.Background(), 1, "rramos.eth")
require.NoError(t, err)
require.Equal(
t,
2022-02-10 14:19:53 +00:00
"0x04e25da6994ea2dc4ac70727e07eca153ae92bf7609db7befb7ebdceaad348f4fc55bbe90abf9501176301db5aa103fc0eb3bc3750272a26c424a10887db2a7ea8",
2022-01-03 09:07:33 +00:00
pubKey,
2021-12-21 15:05:09 +00:00
)
}
func TestAddressOf(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
r, err := api.AddressOf(context.Background(), 1, "rramos.eth")
require.NoError(t, err)
require.Equal(t, "0x7d28Ab6948F3Db2F95A43742265D382a4888c120", r.String())
}
func TestExpireAt(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
2022-01-03 09:07:33 +00:00
r, err := api.ExpireAt(context.Background(), 1, "rramos")
2021-12-21 15:05:09 +00:00
require.NoError(t, err)
2022-01-03 09:07:33 +00:00
require.Equal(t, "5db32cb7", r)
2021-12-21 15:05:09 +00:00
}
func TestPrice(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
r, err := api.Price(context.Background(), 1)
require.NoError(t, err)
2022-01-03 09:07:33 +00:00
require.Equal(t, "8ac7230489e80000", r)
2021-12-21 15:05:09 +00:00
}
func TestResourceURL(t *testing.T) {
2024-04-24 14:41:42 +00:00
t.Skip("skip test using infura")
2021-12-21 15:05:09 +00:00
api, cancel := setupTestAPI(t)
defer cancel()
uri, err := api.ResourceURL(context.Background(), 1, "simpledapp.eth")
require.NoError(t, err)
require.Equal(t, "https", uri.Scheme)
require.Equal(t, "bafybeidzlqpkbtvpjtxnzgew6ffxhozq5f4ojbk64iq3tjl7lkjue2biby", uri.Host)
2021-12-21 15:05:09 +00:00
require.Equal(t, "", uri.Path)
//fixme: this block is the broken part
uri, err = api.ResourceURL(context.Background(), 1, "swarm.eth")
require.NoError(t, err)
require.Equal(t, "https", uri.Scheme)
require.Equal(t, "swarm-gateways.net", uri.Host)
require.Equal(t, "/bzz:/b7976f7fabd7ba88a897452a2860228dcefec427302a3dedae164b51c780a5b8/", uri.Path)
2021-12-21 15:05:09 +00:00
uri, err = api.ResourceURL(context.Background(), 1, "noahzinsmeister.eth")
require.NoError(t, err)
require.Equal(t, "https", uri.Scheme)
require.Equal(t, "noahzinsmeister.com", uri.Host)
require.Equal(t, "", uri.Path)
}