diff options
author | zsfelfoldi <zsfelfoldi@gmail.com> | 2015-04-08 18:35:02 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-04-20 03:57:49 +0800 |
commit | b46e15217131e4ebe64e1ee55594c3ab0620395c (patch) | |
tree | 1a732f7461c606db75e204dc46f08aefd313888d /common | |
parent | 8e6a068d2d5b6374e0a8588a34a96a26562bae83 (diff) | |
download | go-tangerine-b46e15217131e4ebe64e1ee55594c3ab0620395c.tar go-tangerine-b46e15217131e4ebe64e1ee55594c3ab0620395c.tar.gz go-tangerine-b46e15217131e4ebe64e1ee55594c3ab0620395c.tar.bz2 go-tangerine-b46e15217131e4ebe64e1ee55594c3ab0620395c.tar.lz go-tangerine-b46e15217131e4ebe64e1ee55594c3ab0620395c.tar.xz go-tangerine-b46e15217131e4ebe64e1ee55594c3ab0620395c.tar.zst go-tangerine-b46e15217131e4ebe64e1ee55594c3ab0620395c.zip |
default fallback NatSpec messages
Diffstat (limited to 'common')
-rw-r--r-- | common/natspec/natspec.go | 29 | ||||
-rw-r--r-- | common/natspec/natspec_e2e_test.go | 34 |
2 files changed, 49 insertions, 14 deletions
diff --git a/common/natspec/natspec.go b/common/natspec/natspec.go index 0253ebd81..ceac3f5d3 100644 --- a/common/natspec/natspec.go +++ b/common/natspec/natspec.go @@ -24,6 +24,33 @@ type NatSpec struct { // abiDoc abiDoc } +func getFallbackNotice(comment, tx string) string { + + return "About to submit transaction (" + comment + "): " + tx + +} + +func GetNotice(xeth *xeth.XEth, tx string, http *docserver.DocServer) (notice string) { + + ns, err := New(xeth, tx, http) + if err != nil { + if ns == nil { + return getFallbackNotice("no NatSpec info found for contract", tx) + } else { + return getFallbackNotice("invalid NatSpec info", tx) + } + } + + notice, err2 := ns.Notice() + + if err2 != nil { + return getFallbackNotice("couldn't create NatSpec notice", tx) + } + + return + +} + func New(xeth *xeth.XEth, tx string, http *docserver.DocServer) (self *NatSpec, err error) { // extract contract address from tx @@ -46,7 +73,7 @@ func New(xeth *xeth.XEth, tx string, http *docserver.DocServer) (self *NatSpec, return } codehex := xeth.CodeAt(contractAddress) - codeHash := common.BytesToHash(crypto.Sha3(common.Hex2Bytes(codehex))) + codeHash := common.BytesToHash(crypto.Sha3(common.Hex2Bytes(codehex[2:]))) // parse out host/domain // set up nameresolver with natspecreg + urlhint contract addresses diff --git a/common/natspec/natspec_e2e_test.go b/common/natspec/natspec_e2e_test.go index aff094d1d..a99ba7fcd 100644 --- a/common/natspec/natspec_e2e_test.go +++ b/common/natspec/natspec_e2e_test.go @@ -32,7 +32,9 @@ type testFrontend struct { } const testNotice = "Register key `_key` <- content `_content`" -const testExpNotice = "Register key 8.9477152217924674838424037953991966239322087453347756267410168184682657981552e+76 <- content 2.9345842665291639932787537650068479186757226656217642728276414736233000517704e+76" +const testExpNotice = "Register key 7.8620552293692941353904828453472309202657763561546399188096247518683806402731e+76 <- content 2.9345842665291639932787537650068479186757226656217642728276414736233000517704e+76" +const testExpNotice2 = `About to submit transaction (couldn't create NatSpec notice): {"id":6,"jsonrpc":"2.0","method":"eth_transact","params":[{"from":"0xe273f01c99144c438695e10f24926dc1f9fbf62d","to":"0x0000000000000000000000000000000000000009","value":"100000000000","gas":"100000","gasPrice":"100000","data":"0x31e12c20"}]}` +const testExpNotice3 = `About to submit transaction (no NatSpec info found for contract): {"id":6,"jsonrpc":"2.0","method":"eth_transact","params":[{"from":"0xe273f01c99144c438695e10f24926dc1f9fbf62d","to":"0x0000000000000000000000000000000000000008","value":"100000000000","gas":"100000","gasPrice":"100000","data":"0xd66d6c1040e128891caf6033850eb422796ecd92ca7393052020b64455cf8ac00c4ac04800000000000000000000000066696c653a2f2f2f746573742e636f6e74656e74"}]}` const testUserDoc = ` { @@ -89,15 +91,7 @@ func (f *testFrontend) ConfirmTransaction(tx string) bool { if err != nil { f.t.Errorf("Error creating DocServer: %v", err) } - nat, err2 := natspec.New(f.xeth, tx, ds) - if err2 == nil { - f.lastConfirm, err = nat.Notice() - if err != nil { - f.t.Errorf("Notice error: %v", err) - } - } else { - f.t.Errorf("Error creating NatSpec: %v", err2) - } + f.lastConfirm = natspec.GetNotice(f.xeth, tx, ds) } return true } @@ -270,7 +264,7 @@ func TestNatspecE2E(t *testing.T) { dochash := common.BytesToHash(crypto.Sha3([]byte(testDocs))) codehex := tf.xeth.CodeAt(core.ContractAddrHashReg) - codehash := common.BytesToHash(crypto.Sha3(common.Hex2Bytes(codehex))) + codehash := common.BytesToHash(crypto.Sha3(common.Hex2Bytes(codehex[2:]))) tf.setOwner() tf.registerNatSpec(codehash, dochash) @@ -288,12 +282,26 @@ func TestNatspecE2E(t *testing.T) { } t.Logf("url = %v err = %v", url, err2) + // NatSpec info for register method of HashReg contract installed + // now using the same transactions to check confirm messages + tf.makeNatSpec = true - tf.registerNatSpec(codehash, dochash) // call again just to get a confirm message + tf.registerNatSpec(codehash, dochash) t.Logf("Confirm message: %v\n", tf.lastConfirm) - if tf.lastConfirm != testExpNotice { t.Errorf("Wrong confirm message, expected '%v', got '%v'", testExpNotice, tf.lastConfirm) } + tf.setOwner() + t.Logf("Confirm message for unknown method: %v\n", tf.lastConfirm) + if tf.lastConfirm != testExpNotice2 { + t.Errorf("Wrong confirm message, expected '%v', got '%v'", testExpNotice2, tf.lastConfirm) + } + + tf.registerURL(dochash, "file:///test.content") + t.Logf("Confirm message for unknown contract: %v\n", tf.lastConfirm) + if tf.lastConfirm != testExpNotice3 { + t.Errorf("Wrong confirm message, expected '%v', got '%v'", testExpNotice3, tf.lastConfirm) + } + } |