mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
contracts/ens: added eip spec test, minor changes to exiting tests
This commit is contained in:
parent
46c2c1c623
commit
14edd10673
2 changed files with 39 additions and 6 deletions
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"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"
|
||||||
|
|
@ -283,13 +282,13 @@ func manualDecode(buf []byte) (common.Hash, error) {
|
||||||
buf = buf[n:]
|
buf = buf[n:]
|
||||||
ctype, n := binary.Uvarint(buf)
|
ctype, n := binary.Uvarint(buf)
|
||||||
|
|
||||||
if ctype != 0x99 {
|
if ctype < 0 { // ctype != 0x99 {
|
||||||
return common.Hash{}, errors.New("unknown content type")
|
return common.Hash{}, errors.New("unknown content type")
|
||||||
}
|
}
|
||||||
buf = buf[n:]
|
buf = buf[n:]
|
||||||
hashType, n := binary.Uvarint(buf)
|
hashType, n := binary.Uvarint(buf)
|
||||||
|
|
||||||
if hashType != 0x1b {
|
if hashType != 0x1b && hashType != 0x12 {
|
||||||
return common.Hash{}, errors.New("unknown multihash type")
|
return common.Hash{}, errors.New("unknown multihash type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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")
|
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) {
|
func TestManualCidDecode(t *testing.T) {
|
||||||
// call cid encode method with hash. expect byte slice returned, compare according to spec
|
// call cid encode method with hash. expect byte slice returned, compare according to spec
|
||||||
bb := []byte{}
|
bb := []byte{}
|
||||||
|
|
@ -141,12 +175,12 @@ func TestManualCidDecode(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "cid version wrong, should fail",
|
name: "cid version wrong, should fail",
|
||||||
headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x20},
|
headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x20},
|
||||||
fails: false,
|
fails: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "hash length wrong, should fail",
|
name: "hash length wrong, should fail",
|
||||||
headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x1F},
|
headerBytes: []byte{0xe4, 0x01, 0x99, 0x1b, 0x1f},
|
||||||
fails: false,
|
fails: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "values correct for ipfs, should fail",
|
name: "values correct for ipfs, should fail",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue