mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
contracts/ens: fix ens tests to use cid decode and encode
This commit is contained in:
parent
5dad797acf
commit
4a601337c0
2 changed files with 16 additions and 11 deletions
|
|
@ -179,11 +179,12 @@ func (ens *ENS) Resolve(name string) (common.Hash, error) {
|
||||||
|
|
||||||
// END DEPRECATED CODE
|
// END DEPRECATED CODE
|
||||||
|
|
||||||
ret, err := resolver.Contenthash(node)
|
contentHash, err := resolver.Contenthash(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
return common.BytesToHash(ret[:]), nil
|
|
||||||
|
return extractContentHash(contentHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Addr is a non-transactional call that returns the address associated with a name.
|
// Addr is a non-transactional call that returns the address associated with a name.
|
||||||
|
|
|
||||||
|
|
@ -65,18 +65,23 @@ func TestENS(t *testing.T) {
|
||||||
contractBackend.Commit()
|
contractBackend.Commit()
|
||||||
|
|
||||||
// Set the content hash for the name.
|
// Set the content hash for the name.
|
||||||
if _, err = ens.SetContentHash(name, hash.Bytes()); err != nil {
|
|
||||||
|
cid, err := encodeSwarmHash(hash)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err = ens.SetContentHash(name, cid); err != nil {
|
||||||
t.Fatalf("can't set content hash: %v", err)
|
t.Fatalf("can't set content hash: %v", err)
|
||||||
}
|
}
|
||||||
contractBackend.Commit()
|
contractBackend.Commit()
|
||||||
|
|
||||||
// Try to resolve the name.
|
// Try to resolve the name.
|
||||||
vhost, err := ens.Resolve(name)
|
resolvedHash, err := ens.Resolve(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("expected no error, got %v", err)
|
t.Fatalf("expected no error, got %v", err)
|
||||||
}
|
}
|
||||||
if vhost != hash {
|
if resolvedHash.Hex() != hash.Hex() {
|
||||||
t.Fatalf("resolve error, expected %v, got %v", hash.Hex(), vhost.Hex())
|
t.Fatalf("resolve error, expected %v, got %v", hash.Hex(), resolvedHash.Hex())
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the address for the name
|
// set the address for the name
|
||||||
|
|
@ -90,7 +95,7 @@ func TestENS(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("expected no error, got %v", err)
|
t.Fatalf("expected no error, got %v", err)
|
||||||
}
|
}
|
||||||
if testAddr != recoveredAddr {
|
if testAddr.Hex() != recoveredAddr.Hex() {
|
||||||
t.Fatalf("resolve error, expected %v, got %v", testAddr.Hex(), recoveredAddr.Hex())
|
t.Fatalf("resolve error, expected %v, got %v", testAddr.Hex(), recoveredAddr.Hex())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,12 +116,11 @@ func TestENS(t *testing.T) {
|
||||||
contractBackend.Commit()
|
contractBackend.Commit()
|
||||||
|
|
||||||
// Try to resolve the name.
|
// Try to resolve the name.
|
||||||
vhost, err = ens.Resolve(name)
|
fallbackResolvedHash, err := ens.Resolve(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("expected no error, got %v", err)
|
t.Fatalf("expected no error, got %v", err)
|
||||||
}
|
}
|
||||||
if vhost != fallbackHash {
|
if fallbackResolvedHash.Hex() != fallbackHash.Hex() {
|
||||||
t.Fatalf("resolve error, expected %v, got %v", hash.Hex(), vhost.Hex())
|
t.Fatalf("resolve error, expected %v, got %v", hash.Hex(), resolvedHash.Hex())
|
||||||
}
|
}
|
||||||
t.Fatal("todo: try to set old contract with new multicodec stuff and assert fail, set new contract with multicodec stuff, encode, decode and assert returns correct hash")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue