github.com/ethersphere/bee/v2@v2.2.0/pkg/resolver/client/ens/ens_integration_test.go (about) 1 // Copyright 2020 The Swarm Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build integration 6 7 package ens_test 8 9 import ( 10 "errors" 11 "testing" 12 13 "github.com/ethersphere/bee/v2/pkg/resolver/client/ens" 14 "github.com/ethersphere/bee/v2/pkg/swarm" 15 ) 16 17 func TestENSIntegration(t *testing.T) { 18 // TODO: consider using a stable gateway instead of INFURA. 19 defaultEndpoint := "https://sepolia.infura.io/v3/59d83a5a4be74f86b9851190c802297b" 20 defaultAddr := swarm.MustParseHexAddress("00cb23598c2e520b6a6aae3ddc94fed4435a2909690bdd709bf9d9e7c2aadfad") 21 22 testCases := []struct { 23 desc string 24 endpoint string 25 contractAddress string 26 name string 27 wantAdr swarm.Address 28 wantErr error 29 }{ 30 // TODO: add a test targeting a resolver with an invalid contenthash 31 // record. 32 { 33 desc: "invalid resolver endpoint", 34 endpoint: "example.com", 35 wantErr: ens.ErrFailedToConnect, 36 }, 37 { 38 desc: "no domain", 39 name: "idonthaveadomain", 40 wantErr: ens.ErrResolveFailed, 41 }, 42 { 43 desc: "no eth domain", 44 name: "centralized.com", 45 wantErr: ens.ErrResolveFailed, 46 }, 47 { 48 desc: "not registered", 49 name: "unused.test.swarm.eth", 50 wantErr: ens.ErrResolveFailed, 51 }, 52 { 53 desc: "no content hash", 54 name: "nocontent.resolver.test.swarm.eth", 55 wantErr: ens.ErrResolveFailed, 56 }, 57 { 58 desc: "invalid contract address", 59 contractAddress: "0xFFFFFFFF", 60 name: "example.resolver.test.swarm.eth", 61 wantErr: ens.ErrFailedToConnect, 62 }, 63 { 64 desc: "ok", 65 name: "example.resolver.test.swarm.eth", 66 wantAdr: defaultAddr, 67 }, 68 } 69 for _, tC := range testCases { 70 t.Run(tC.desc, func(t *testing.T) { 71 if tC.endpoint == "" { 72 tC.endpoint = defaultEndpoint 73 } 74 75 ensClient, err := ens.NewClient(tC.endpoint, ens.WithContractAddress(tC.contractAddress)) 76 if err != nil { 77 if !errors.Is(err, tC.wantErr) { 78 t.Errorf("got %v, want %v", err, tC.wantErr) 79 } 80 return 81 } 82 testutil.CleanupCloser(t, ensClient) 83 84 addr, err := ensClient.Resolve(tC.name) 85 if err != nil { 86 if !errors.Is(err, tC.wantErr) { 87 t.Errorf("got %v, want %v", err, tC.wantErr) 88 } 89 return 90 } 91 92 if !addr.Equal(defaultAddr) { 93 t.Errorf("bad addr: got %s, want %s", addr, defaultAddr) 94 } 95 96 err = ensClient.Close() 97 if err != nil { 98 t.Fatal(err) 99 } 100 }) 101 } 102 }