contracts/ens: added test coverage for fallback contract
This commit is contained in:
@ -22,6 +22,7 @@ package ens
|
|||||||
//go:generate abigen --sol contract/PublicResolver.sol --exc contract/ENS.sol:ENS --pkg contract --out contract/publicresolver.go
|
//go:generate abigen --sol contract/PublicResolver.sol --exc contract/ENS.sol:ENS --pkg contract --out contract/publicresolver.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/binary"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
@ -32,10 +33,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
MainNetAddress = common.HexToAddress("0x314159265dD8dbb310642f98f50C066173C1259b")
|
MainNetAddress = common.HexToAddress("0x314159265dD8dbb310642f98f50C066173C1259b")
|
||||||
TestNetAddress = common.HexToAddress("0x112234455c3a32fd11230c42e7bccd4a84e02010")
|
TestNetAddress = common.HexToAddress("0x112234455c3a32fd11230c42e7bccd4a84e02010")
|
||||||
|
contentHash_Interface_Id [4]byte
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const contentHash_Interface_Id_Spec = 0xbc1c58d1
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
binary.BigEndian.PutUint32(contentHash_Interface_Id[:], contentHash_Interface_Id_Spec)
|
||||||
|
}
|
||||||
|
|
||||||
// ENS is the swarm domain name registry and resolver
|
// ENS is the swarm domain name registry and resolver
|
||||||
type ENS struct {
|
type ENS struct {
|
||||||
*contract.ENSSession
|
*contract.ENSSession
|
||||||
@ -135,6 +143,18 @@ func (ens *ENS) Resolve(name string) (common.Hash, error) {
|
|||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IMPORTANT: The old contract is deprecated. This code should be removed latest on June 1st 2019
|
||||||
|
supported, err := resolver.SupportsInterface(contentHash_Interface_Id)
|
||||||
|
if err != nil {
|
||||||
|
return common.Hash{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !supported {
|
||||||
|
panic("w00t")
|
||||||
|
}
|
||||||
|
|
||||||
|
// END DEPRECATED CODE
|
||||||
|
|
||||||
ret, err := resolver.Contenthash(node)
|
ret, err := resolver.Contenthash(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
@ -191,6 +211,19 @@ func (ens *ENS) SetContentHash(name string, hash []byte) (*types.Transaction, er
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IMPORTANT: The old contract is deprecated. This code should be removed latest on June 1st 2019
|
||||||
|
supported, err := resolver.SupportsInterface(contentHash_Interface_Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !supported {
|
||||||
|
panic("w00t")
|
||||||
|
}
|
||||||
|
|
||||||
|
// END DEPRECATED CODE
|
||||||
|
|
||||||
opts := ens.TransactOpts
|
opts := ens.TransactOpts
|
||||||
opts.GasLimit = 200000
|
opts.GasLimit = 200000
|
||||||
return resolver.Contract.SetContenthash(&opts, node, hash)
|
return resolver.Contract.SetContenthash(&opts, node, hash)
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/contracts/ens/contract"
|
"github.com/ethereum/go-ethereum/contracts/ens/contract"
|
||||||
|
"github.com/ethereum/go-ethereum/contracts/ens/fallback_contract"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
@ -91,4 +92,30 @@ func TestENS(t *testing.T) {
|
|||||||
if testAddr != recoveredAddr {
|
if testAddr != recoveredAddr {
|
||||||
t.Fatalf("resolve error, expected %v, got %v", testAddr.Hex(), recoveredAddr.Hex())
|
t.Fatalf("resolve error, expected %v, got %v", testAddr.Hex(), recoveredAddr.Hex())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deploy the fallback contract and see that the fallback mechanism works
|
||||||
|
newResolverAddr, _, _, err := fallback_contract.DeployPublicResolver(transactOpts, contractBackend, ensAddr)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't deploy resolver: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := ens.SetResolver(EnsNode(name), newResolverAddr); err != nil {
|
||||||
|
t.Fatalf("can't set resolver: %v", err)
|
||||||
|
}
|
||||||
|
contractBackend.Commit()
|
||||||
|
|
||||||
|
// Set the content hash for the name.
|
||||||
|
if _, err = ens.SetContentHash(name, hash.Bytes()); err != nil {
|
||||||
|
t.Fatalf("can't set content hash: %v", err)
|
||||||
|
}
|
||||||
|
contractBackend.Commit()
|
||||||
|
|
||||||
|
// Try to resolve the name.
|
||||||
|
vhost, err = ens.Resolve(name)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("expected no error, got %v", err)
|
||||||
|
}
|
||||||
|
if vhost != hash {
|
||||||
|
t.Fatalf("resolve error, expected %v, got %v", hash.Hex(), vhost.Hex())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Code generated - DO NOT EDIT.
|
// Code generated - DO NOT EDIT.
|
||||||
// This file is a generated binding and any manual changes will be lost.
|
// This file is a generated binding and any manual changes will be lost.
|
||||||
|
|
||||||
package contract
|
package fallback_contract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Code generated - DO NOT EDIT.
|
// Code generated - DO NOT EDIT.
|
||||||
// This file is a generated binding and any manual changes will be lost.
|
// This file is a generated binding and any manual changes will be lost.
|
||||||
|
|
||||||
package contract
|
package fallback_contract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Code generated - DO NOT EDIT.
|
// Code generated - DO NOT EDIT.
|
||||||
// This file is a generated binding and any manual changes will be lost.
|
// This file is a generated binding and any manual changes will be lost.
|
||||||
|
|
||||||
package contract
|
package fallback_contract
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
Reference in New Issue
Block a user