aboutsummaryrefslogtreecommitdiffstats
path: root/common/resolver
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-04-20 02:24:46 +0800
committerzelig <viktor.tron@gmail.com>2015-04-20 04:09:30 +0800
commit093a9106b093310acf4c3911baa61916cff52ab8 (patch)
tree7d5d5db476ff116e6fd0ba969750c7e4e64d1b03 /common/resolver
parent71c974f3eb080ffcdcf4812f3dd082e668627c8b (diff)
downloaddexon-093a9106b093310acf4c3911baa61916cff52ab8.tar
dexon-093a9106b093310acf4c3911baa61916cff52ab8.tar.gz
dexon-093a9106b093310acf4c3911baa61916cff52ab8.tar.bz2
dexon-093a9106b093310acf4c3911baa61916cff52ab8.tar.lz
dexon-093a9106b093310acf4c3911baa61916cff52ab8.tar.xz
dexon-093a9106b093310acf4c3911baa61916cff52ab8.tar.zst
dexon-093a9106b093310acf4c3911baa61916cff52ab8.zip
contract addresses include hex prefix
- simplify resolver and tests - added missing test for KeyToUrl - fix notice error message and its test with !%x(MISSING) - natspec test: insertTx modified - does not prepend 0x to contract address - disable networking in e2e test
Diffstat (limited to 'common/resolver')
-rw-r--r--common/resolver/resolver.go8
-rw-r--r--common/resolver/resolver_test.go44
2 files changed, 28 insertions, 24 deletions
diff --git a/common/resolver/resolver.go b/common/resolver/resolver.go
index 35f765349..1e6d03ffb 100644
--- a/common/resolver/resolver.go
+++ b/common/resolver/resolver.go
@@ -32,8 +32,6 @@ func CreateContracts(xeth *xe.XEth, addr string) {
if err != nil {
panic(err)
}
- URLHintContractAddress = URLHintContractAddress[2:]
- HashRegContractAddress = HashRegContractAddress[2:]
}
type Resolver struct {
@@ -53,7 +51,7 @@ func New(eth Backend, uhca, nrca string) *Resolver {
func (self *Resolver) KeyToContentHash(khash common.Hash) (chash common.Hash, err error) {
// look up in hashReg
key := storageAddress(storageMapping(storageIdx2Addr(1), khash[:]))
- hash := self.backend.StorageAt("0x"+self.hashRegContractAddress, key)
+ hash := self.backend.StorageAt(self.hashRegContractAddress, key)
if hash == "0x0" || len(hash) < 3 {
err = fmt.Errorf("GetHashReg: content hash not found")
@@ -71,7 +69,7 @@ func (self *Resolver) ContentHashToUrl(chash common.Hash) (uri string, err error
for len(str) > 0 {
mapaddr := storageMapping(storageIdx2Addr(1), chash[:])
key := storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(idx)))
- hex := self.backend.StorageAt("0x"+self.urlHintContractAddress, key)
+ hex := self.backend.StorageAt(self.urlHintContractAddress, key)
str = string(common.Hex2Bytes(hex[2:]))
l := len(str)
for (l > 0) && (str[l-1] == 0) {
@@ -126,5 +124,5 @@ func storageFixedArray(addr, idx []byte) []byte {
}
func storageAddress(addr []byte) string {
- return "0x" + common.Bytes2Hex(addr)
+ return common.ToHex(addr)
}
diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go
index a67b9ad04..f5eb51437 100644
--- a/common/resolver/resolver_test.go
+++ b/common/resolver/resolver_test.go
@@ -14,8 +14,8 @@ type testBackend struct {
var (
text = "test"
- codehash = "1234" //common.RightPadString("1234", 64)
- hash = common.Bytes2Hex(crypto.Sha3([]byte(text)))
+ codehash = common.StringToHash("1234")
+ hash = common.BytesToHash(crypto.Sha3([]byte(text)))
url = "bzz://bzzhash/my/path/contr.act"
)
@@ -23,17 +23,17 @@ func NewTestBackend() *testBackend {
self := &testBackend{}
self.contracts = make(map[string](map[string]string))
- self.contracts["0x"+HashRegContractAddress] = make(map[string]string)
- key := storageAddress(storageMapping(storageIdx2Addr(1), common.Hex2BytesFixed(codehash, 32)))
- self.contracts["0x"+HashRegContractAddress][key] = "0x" + hash
+ self.contracts[HashRegContractAddress] = make(map[string]string)
+ key := storageAddress(storageMapping(storageIdx2Addr(1), codehash[:]))
+ self.contracts[HashRegContractAddress][key] = hash.Hex()
- self.contracts["0x"+URLHintContractAddress] = make(map[string]string)
- mapaddr := storageMapping(storageIdx2Addr(1), common.Hex2BytesFixed(hash, 32))
+ self.contracts[URLHintContractAddress] = make(map[string]string)
+ mapaddr := storageMapping(storageIdx2Addr(1), hash[:])
key = storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(0)))
- self.contracts["0x"+URLHintContractAddress][key] = "0x" + common.Bytes2Hex([]byte(url))
+ self.contracts[URLHintContractAddress][key] = common.ToHex([]byte(url))
key = storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(1)))
- self.contracts["0x"+URLHintContractAddress][key] = "0x00"
+ self.contracts[URLHintContractAddress][key] = "0x00"
return self
}
@@ -50,15 +50,13 @@ func (self *testBackend) StorageAt(ca, sa string) (res string) {
func TestKeyToContentHash(t *testing.T) {
b := NewTestBackend()
res := New(b, URLHintContractAddress, HashRegContractAddress)
- chash := common.Hash{}
- copy(chash[:], common.Hex2BytesFixed(codehash, 32))
- got, err := res.KeyToContentHash(chash)
+ got, err := res.KeyToContentHash(codehash)
if err != nil {
t.Errorf("expected no error, got %v", err)
} else {
- if common.Bytes2Hex(got[:]) != hash {
- t.Errorf("incorrect result, expected %x, got %x: ", hash, common.Bytes2Hex(got[:]))
+ if got != hash {
+ t.Errorf("incorrect result, expected %x, got %x: ", hash.Hex(), got.Hex())
}
}
}
@@ -66,17 +64,25 @@ func TestKeyToContentHash(t *testing.T) {
func TestContentHashToUrl(t *testing.T) {
b := NewTestBackend()
res := New(b, URLHintContractAddress, HashRegContractAddress)
- chash := common.Hash{}
- copy(chash[:], common.Hex2BytesFixed(hash, 32))
- got, err := res.ContentHashToUrl(chash)
+ got, err := res.ContentHashToUrl(hash)
if err != nil {
t.Errorf("expected no error, got %v", err)
} else {
- if string(got[:]) != url {
- t.Errorf("incorrect result, expected %v, got %s: ", url, string(got[:]))
+ if string(got) != url {
+ t.Errorf("incorrect result, expected %v, got %s: ", url, string(got))
}
}
}
func TestKeyToUrl(t *testing.T) {
+ b := NewTestBackend()
+ res := New(b, URLHintContractAddress, HashRegContractAddress)
+ got, _, err := res.KeyToUrl(codehash)
+ if err != nil {
+ t.Errorf("expected no error, got %v", err)
+ } else {
+ if string(got) != url {
+ t.Errorf("incorrect result, expected %v, got %s: ", url, string(got))
+ }
+ }
}