diff options
author | zsfelfoldi <zsfelfoldi@gmail.com> | 2015-04-03 23:37:59 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-04-20 03:57:49 +0800 |
commit | e2d333d2095edb349388433c28f4d6a381b1df62 (patch) | |
tree | 2bc2dbf45ffeb1de93606122d263913d790d048f /common/resolver | |
parent | ac0e5e8b6de43a40bbc25f541aa2399202bbe420 (diff) | |
download | go-tangerine-e2d333d2095edb349388433c28f4d6a381b1df62.tar go-tangerine-e2d333d2095edb349388433c28f4d6a381b1df62.tar.gz go-tangerine-e2d333d2095edb349388433c28f4d6a381b1df62.tar.bz2 go-tangerine-e2d333d2095edb349388433c28f4d6a381b1df62.tar.lz go-tangerine-e2d333d2095edb349388433c28f4d6a381b1df62.tar.xz go-tangerine-e2d333d2095edb349388433c28f4d6a381b1df62.tar.zst go-tangerine-e2d333d2095edb349388433c28f4d6a381b1df62.zip |
NatSpec contracts in genesis block, end to end test (unfinished)
Diffstat (limited to 'common/resolver')
-rw-r--r-- | common/resolver/resolver.go | 11 | ||||
-rw-r--r-- | common/resolver/resolver_test.go | 12 |
2 files changed, 12 insertions, 11 deletions
diff --git a/common/resolver/resolver.go b/common/resolver/resolver.go index ba592feb0..1d80fdb42 100644 --- a/common/resolver/resolver.go +++ b/common/resolver/resolver.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" ) @@ -17,8 +18,8 @@ The resolver is meant to be called by the roundtripper transport implementation of a url scheme */ const ( - urlHintContractAddress = "urlhint" - nameRegContractAddress = "nameReg" + URLHintContractAddress = core.ContractAddrURLhint + NameRegContractAddress = core.ContractAddrHashReg ) type Resolver struct { @@ -37,7 +38,7 @@ func New(eth Backend, uhca, nrca string) *Resolver { func (self *Resolver) NameToContentHash(name string) (chash common.Hash, err error) { // look up in nameReg - key := storageAddress(0, common.Hex2Bytes(name)) + key := storageAddress(1, common.Hex2BytesFixed(name, 32)) hash := self.backend.StorageAt(self.nameRegContractAddress, key) copy(chash[:], common.Hex2Bytes(hash)) return @@ -45,8 +46,8 @@ func (self *Resolver) NameToContentHash(name string) (chash common.Hash, err err func (self *Resolver) ContentHashToUrl(chash common.Hash) (uri string, err error) { // look up in nameReg - key := storageAddress(0, chash[:]) - uri = self.backend.StorageAt(self.urlHintContractAddress, key) + key := storageAddress(2, chash[:]) + uri = string(common.Hex2Bytes(self.backend.StorageAt(self.urlHintContractAddress, key))) l := len(uri) for (l > 0) && (uri[l-1] == 0) { l-- diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go index a5b6c3b4f..5652213f6 100644 --- a/common/resolver/resolver_test.go +++ b/common/resolver/resolver_test.go @@ -23,13 +23,13 @@ func NewTestBackend() *testBackend { self := &testBackend{} self.contracts = make(map[string](map[string]string)) - self.contracts[nameRegContractAddress] = make(map[string]string) + self.contracts[NameRegContractAddress] = make(map[string]string) key := storageAddress(0, common.Hex2Bytes(codehash)) - self.contracts[nameRegContractAddress][key] = hash + self.contracts[NameRegContractAddress][key] = hash - self.contracts[urlHintContractAddress] = make(map[string]string) + self.contracts[URLHintContractAddress] = make(map[string]string) key = storageAddress(0, common.Hex2Bytes(hash)) - self.contracts[urlHintContractAddress][key] = url + self.contracts[URLHintContractAddress][key] = url return self } @@ -45,7 +45,7 @@ func (self *testBackend) StorageAt(ca, sa string) (res string) { func TestNameToContentHash(t *testing.T) { b := NewTestBackend() - res := New(b, urlHintContractAddress, nameRegContractAddress) + res := New(b, URLHintContractAddress, NameRegContractAddress) got, err := res.NameToContentHash(codehash) if err != nil { t.Errorf("expected no error, got %v", err) @@ -58,7 +58,7 @@ func TestNameToContentHash(t *testing.T) { func TestContentHashToUrl(t *testing.T) { b := NewTestBackend() - res := New(b, urlHintContractAddress, nameRegContractAddress) + res := New(b, URLHintContractAddress, NameRegContractAddress) chash := common.Hash{} copy(chash[:], common.Hex2Bytes(hash)) got, err := res.ContentHashToUrl(chash) |