github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/contracts/ens/ens_test.go (about)

     1  // Copyright 2016 The Spectrum Authors
     2  // This file is part of the Spectrum library.
     3  //
     4  // The Spectrum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The Spectrum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the Spectrum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package ens
    18  
    19  import (
    20  	"math/big"
    21  	"testing"
    22  
    23  	"github.com/SmartMeshFoundation/Spectrum/accounts/abi/bind"
    24  	"github.com/SmartMeshFoundation/Spectrum/accounts/abi/bind/backends"
    25  	"github.com/SmartMeshFoundation/Spectrum/core"
    26  	"github.com/SmartMeshFoundation/Spectrum/crypto"
    27  )
    28  
    29  var (
    30  	key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
    31  	name   = "my name on ENS"
    32  	hash   = crypto.Keccak256Hash([]byte("my content"))
    33  	addr   = crypto.PubkeyToAddress(key.PublicKey)
    34  )
    35  
    36  func TestENS(t *testing.T) {
    37  	contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
    38  	transactOpts := bind.NewKeyedTransactor(key)
    39  	// Workaround for bug estimating gas in the call to Register
    40  	transactOpts.GasLimit = big.NewInt(1000000)
    41  
    42  	ens, err := DeployENS(transactOpts, contractBackend)
    43  	if err != nil {
    44  		t.Fatalf("expected no error, got %v", err)
    45  	}
    46  	contractBackend.Commit()
    47  
    48  	_, err = ens.Register(name)
    49  	if err != nil {
    50  		t.Fatalf("expected no error, got %v", err)
    51  	}
    52  	contractBackend.Commit()
    53  
    54  	_, err = ens.SetContentHash(name, hash)
    55  	if err != nil {
    56  		t.Fatalf("expected no error, got %v", err)
    57  	}
    58  	contractBackend.Commit()
    59  
    60  	vhost, err := ens.Resolve(name)
    61  	if err != nil {
    62  		t.Fatalf("expected no error, got %v", err)
    63  	}
    64  	if vhost != hash {
    65  		t.Fatalf("resolve error, expected %v, got %v", hash.Hex(), vhost.Hex())
    66  	}
    67  }