contracts/ens: added eip spec test, minor changes to exiting tests

This commit is contained in:
Elad 2019-03-08 17:19:22 +07:00
parent 46c2c1c623
commit 14edd10673
2 changed files with 39 additions and 6 deletions

View file

@ -27,7 +27,6 @@ import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts/ens/contract"
@ -283,13 +282,13 @@ func manualDecode(buf []byte) (common.Hash, error) {
buf = buf[n:]
ctype, n := binary.Uvarint(buf)
if ctype != 0x99 {
if ctype < 0 { // ctype != 0x99 {
return common.Hash{}, errors.New("unknown content type")
}
buf = buf[n:]
hashType, n := binary.Uvarint(buf)
if hashType != 0x1b {
if hashType != 0x1b && hashType != 0x12 {
return common.Hash{}, errors.New("unknown multihash type")
}

View file

@ -124,6 +124,40 @@ func TestENS(t *testing.T) {
}
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")
}
func TestEIPSpecCidDecode(t *testing.T) {
/*storage system: IPFS (0xe3)
CID version: 1 (0x01)
content type: dag-pb (0x70)
hash function: sha2-256 (0x12)
hash length: 32 bytes (0x20)
hash: 29f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f
*/
const eipSpecHash = "e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f"
const eipHash = "29f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f"
b, err := hex.DecodeString(eipSpecHash)
if err != nil {
t.Fatal(err)
}
hashBytes, err := hex.DecodeString(eipHash)
if err != nil {
t.Fatal(err)
}
h, err := manualDecode(b)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(h[:], hashBytes) {
t.Fatal("should be equal")
}
}
func TestManualCidDecode(t *testing.T) {
// call cid encode method with hash. expect byte slice returned, compare according to spec
bb := []byte{}
@ -141,12 +175,12 @@ func TestManualCidDecode(t *testing.T) {
{
name: "cid version wrong, should fail",
headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x20},
fails: false,
fails: true,
},
{
name: "hash length wrong, should fail",
headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x1F},
fails: false,
headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x1f},
fails: true,
},
{
name: "values correct for ipfs, should fail",