From 97a602864a485bb3a79f460077052bd76cdbff99 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 31 Mar 2015 01:57:17 +0100 Subject: add common/resolver skeleton --- common/resolver/resolver_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 common/resolver/resolver_test.go (limited to 'common/resolver/resolver_test.go') diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go new file mode 100644 index 000000000..ce0116664 --- /dev/null +++ b/common/resolver/resolver_test.go @@ -0,0 +1,17 @@ +package resolver + +import ( + "testing" +) + +func TestNameToContentHash(t *testing.T) { + +} + +func TestContentHashToUrl(t *testing.T) { + +} + +func TestNameToUrl(t *testing.T) { + +} -- cgit v1.2.3 From ac0e5e8b6de43a40bbc25f541aa2399202bbe420 Mon Sep 17 00:00:00 2001 From: zelig Date: Wed, 1 Apr 2015 12:29:16 +0100 Subject: resolver tests - add resolver tests and fix resolver to pass - statereg constructor fixed - comments added to natspec plus docserver integration for natspec userdoc fetching --- common/resolver/resolver_test.go | 64 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) (limited to 'common/resolver/resolver_test.go') diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go index ce0116664..a5b6c3b4f 100644 --- a/common/resolver/resolver_test.go +++ b/common/resolver/resolver_test.go @@ -2,16 +2,74 @@ package resolver import ( "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" ) -func TestNameToContentHash(t *testing.T) { +type testBackend struct { + // contracts mock + contracts map[string](map[string]string) +} + +var ( + text = "test" + codehash = common.RightPadString("1234", 64) + hash = common.Bytes2Hex(crypto.Sha3([]byte(text))) + url = "bzz://bzzhash/my/path/contr.act" +) + +func NewTestBackend() *testBackend { + self := &testBackend{} + self.contracts = make(map[string](map[string]string)) + + self.contracts[nameRegContractAddress] = make(map[string]string) + key := storageAddress(0, common.Hex2Bytes(codehash)) + self.contracts[nameRegContractAddress][key] = hash + + self.contracts[urlHintContractAddress] = make(map[string]string) + key = storageAddress(0, common.Hex2Bytes(hash)) + self.contracts[urlHintContractAddress][key] = url + return self } -func TestContentHashToUrl(t *testing.T) { +func (self *testBackend) StorageAt(ca, sa string) (res string) { + c := self.contracts[ca] + if c == nil { + return + } + res = c[sa] + return +} +func TestNameToContentHash(t *testing.T) { + b := NewTestBackend() + res := New(b, urlHintContractAddress, nameRegContractAddress) + got, err := res.NameToContentHash(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[:])) + } + } } -func TestNameToUrl(t *testing.T) { +func TestContentHashToUrl(t *testing.T) { + b := NewTestBackend() + res := New(b, urlHintContractAddress, nameRegContractAddress) + chash := common.Hash{} + copy(chash[:], common.Hex2Bytes(hash)) + got, err := res.ContentHashToUrl(chash) + 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[:])) + } + } +} +func TestNameToUrl(t *testing.T) { } -- cgit v1.2.3 From e2d333d2095edb349388433c28f4d6a381b1df62 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Fri, 3 Apr 2015 17:37:59 +0200 Subject: NatSpec contracts in genesis block, end to end test (unfinished) --- common/resolver/resolver_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'common/resolver/resolver_test.go') 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) -- cgit v1.2.3 From b635cad9fe127e6b0ca6d993ce9a3b6c61ce79c6 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Tue, 7 Apr 2015 11:50:17 +0200 Subject: NatSpec passing end to end test --- common/resolver/resolver_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'common/resolver/resolver_test.go') diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go index 5652213f6..17a1c4f94 100644 --- a/common/resolver/resolver_test.go +++ b/common/resolver/resolver_test.go @@ -23,12 +23,12 @@ func NewTestBackend() *testBackend { self := &testBackend{} self.contracts = make(map[string](map[string]string)) - self.contracts[NameRegContractAddress] = make(map[string]string) - key := storageAddress(0, common.Hex2Bytes(codehash)) - self.contracts[NameRegContractAddress][key] = hash + self.contracts[HashRegContractAddress] = make(map[string]string) + key := storageAddress(1, common.Hex2Bytes(codehash)) + self.contracts[HashRegContractAddress][key] = hash self.contracts[URLHintContractAddress] = make(map[string]string) - key = storageAddress(0, common.Hex2Bytes(hash)) + key = storageAddress(1, common.Hex2Bytes(hash)) self.contracts[URLHintContractAddress][key] = url return self @@ -43,10 +43,12 @@ func (self *testBackend) StorageAt(ca, sa string) (res string) { return } -func TestNameToContentHash(t *testing.T) { +func TestKeyToContentHash(t *testing.T) { b := NewTestBackend() - res := New(b, URLHintContractAddress, NameRegContractAddress) - got, err := res.NameToContentHash(codehash) + res := New(b, URLHintContractAddress, HashRegContractAddress) + chash := common.Hash{} + copy(chash[:], common.Hex2BytesFixed(codehash, 32)) + got, err := res.KeyToContentHash(chash) if err != nil { t.Errorf("expected no error, got %v", err) } else { @@ -58,7 +60,7 @@ func TestNameToContentHash(t *testing.T) { func TestContentHashToUrl(t *testing.T) { b := NewTestBackend() - res := New(b, URLHintContractAddress, NameRegContractAddress) + res := New(b, URLHintContractAddress, HashRegContractAddress) chash := common.Hash{} copy(chash[:], common.Hex2Bytes(hash)) got, err := res.ContentHashToUrl(chash) @@ -71,5 +73,5 @@ func TestContentHashToUrl(t *testing.T) { } } -func TestNameToUrl(t *testing.T) { +func TestKeyToUrl(t *testing.T) { } -- cgit v1.2.3 From c4b7d4d3f77160fba1ab3d8366cb2657a90e2282 Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Wed, 8 Apr 2015 13:22:31 +0200 Subject: NatSpec cli option, resolver tests passing --- common/resolver/resolver_test.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'common/resolver/resolver_test.go') diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go index 17a1c4f94..7d570cbc6 100644 --- a/common/resolver/resolver_test.go +++ b/common/resolver/resolver_test.go @@ -14,7 +14,7 @@ type testBackend struct { var ( text = "test" - codehash = common.RightPadString("1234", 64) + codehash = "1234" //common.RightPadString("1234", 64) hash = common.Bytes2Hex(crypto.Sha3([]byte(text))) url = "bzz://bzzhash/my/path/contr.act" ) @@ -23,13 +23,13 @@ func NewTestBackend() *testBackend { self := &testBackend{} self.contracts = make(map[string](map[string]string)) - self.contracts[HashRegContractAddress] = make(map[string]string) - key := storageAddress(1, common.Hex2Bytes(codehash)) - self.contracts[HashRegContractAddress][key] = hash + self.contracts["0x"+HashRegContractAddress] = make(map[string]string) + key := storageAddress(1, common.Hex2BytesFixed(codehash, 32)) + self.contracts["0x"+HashRegContractAddress][key] = "0x" + hash - self.contracts[URLHintContractAddress] = make(map[string]string) - key = storageAddress(1, common.Hex2Bytes(hash)) - self.contracts[URLHintContractAddress][key] = url + self.contracts["0x"+URLHintContractAddress] = make(map[string]string) + key = storageAddress(1, common.Hex2BytesFixed(hash, 32)) + self.contracts["0x"+URLHintContractAddress][key] = "0x" + common.Bytes2Hex([]byte(url)) return self } @@ -48,6 +48,7 @@ func TestKeyToContentHash(t *testing.T) { res := New(b, URLHintContractAddress, HashRegContractAddress) chash := common.Hash{} copy(chash[:], common.Hex2BytesFixed(codehash, 32)) + got, err := res.KeyToContentHash(chash) if err != nil { t.Errorf("expected no error, got %v", err) @@ -62,7 +63,7 @@ func TestContentHashToUrl(t *testing.T) { b := NewTestBackend() res := New(b, URLHintContractAddress, HashRegContractAddress) chash := common.Hash{} - copy(chash[:], common.Hex2Bytes(hash)) + copy(chash[:], common.Hex2BytesFixed(hash, 32)) got, err := res.ContentHashToUrl(chash) if err != nil { t.Errorf("expected no error, got %v", err) -- cgit v1.2.3 From e9874cbcc12f5b15ad91a0df396552afe8c71e3e Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Fri, 17 Apr 2015 13:54:23 +0200 Subject: fixed resolver test --- common/resolver/resolver_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'common/resolver/resolver_test.go') diff --git a/common/resolver/resolver_test.go b/common/resolver/resolver_test.go index 7d570cbc6..a67b9ad04 100644 --- a/common/resolver/resolver_test.go +++ b/common/resolver/resolver_test.go @@ -24,12 +24,16 @@ func NewTestBackend() *testBackend { self.contracts = make(map[string](map[string]string)) self.contracts["0x"+HashRegContractAddress] = make(map[string]string) - key := storageAddress(1, common.Hex2BytesFixed(codehash, 32)) + key := storageAddress(storageMapping(storageIdx2Addr(1), common.Hex2BytesFixed(codehash, 32))) self.contracts["0x"+HashRegContractAddress][key] = "0x" + hash self.contracts["0x"+URLHintContractAddress] = make(map[string]string) - key = storageAddress(1, common.Hex2BytesFixed(hash, 32)) + mapaddr := storageMapping(storageIdx2Addr(1), common.Hex2BytesFixed(hash, 32)) + + key = storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(0))) self.contracts["0x"+URLHintContractAddress][key] = "0x" + common.Bytes2Hex([]byte(url)) + key = storageAddress(storageFixedArray(mapaddr, storageIdx2Addr(1))) + self.contracts["0x"+URLHintContractAddress][key] = "0x00" return self } -- cgit v1.2.3 From 093a9106b093310acf4c3911baa61916cff52ab8 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 19 Apr 2015 19:24:46 +0100 Subject: 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 --- common/resolver/resolver_test.go | 44 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'common/resolver/resolver_test.go') 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)) + } + } } -- cgit v1.2.3