aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/natspec/natspec_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-11 00:14:31 +0800
committerFelix Lange <fjl@twurst.com>2015-03-11 00:14:31 +0800
commit269cfbb8ace76ddc1f50dbd5b218c499308c8a5c (patch)
treec2e9e274c64f431f03b9a6b8b3de22585c016027 /ethutil/natspec/natspec_test.go
parent972e2c1e31067a9bab77228c19348b66964ce643 (diff)
parent0542df941f57a75fa7b699089db1d9ae40e4ff71 (diff)
downloaddexon-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar
dexon-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.gz
dexon-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.bz2
dexon-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.lz
dexon-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.xz
dexon-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.tar.zst
dexon-269cfbb8ace76ddc1f50dbd5b218c499308c8a5c.zip
Merge branch origin/develop into accounts-integration
Conflicts: cmd/blocktest/main.go cmd/mist/debugger.go cmd/utils/cmd.go
Diffstat (limited to 'ethutil/natspec/natspec_test.go')
-rw-r--r--ethutil/natspec/natspec_test.go104
1 files changed, 75 insertions, 29 deletions
diff --git a/ethutil/natspec/natspec_test.go b/ethutil/natspec/natspec_test.go
index 48a9cb25c..498f8d78e 100644
--- a/ethutil/natspec/natspec_test.go
+++ b/ethutil/natspec/natspec_test.go
@@ -6,41 +6,48 @@ import (
func TestNotice(t *testing.T) {
- ns, err := NewNATSpec(`
+ tx := `
{
- "jsonrpc": "2.0",
- "method": "eth_call",
- "params": [{
- "to": "0x8521742d3f456bd237e312d6e30724960f72517a",
- "data": "0xc6888fa1000000000000000000000000000000000000000000000000000000000000007a"
- }],
- "id": 6
- }
- `)
+ "jsonrpc": "2.0",
+ "method": "eth_call",
+ "params": [{
+ "to": "0x8521742d3f456bd237e312d6e30724960f72517a",
+ "data": "0xc6888fa1000000000000000000000000000000000000000000000000000000000000007a"
+ }],
+ "id": 6
+ }
+ `
+ abi := `
+ [{
+ "name": "multiply",
+ "constant": false,
+ "type": "function",
+ "inputs": [{
+ "name": "a",
+ "type": "uint256"
+ }],
+ "outputs": [{
+ "name": "d",
+ "type": "uint256"
+ }]
+ }]
+ `
+
+ desc := "Will multiply `a` by 7 and return `a * 7`."
+
+ method := "multiply"
+
+ ns, err := New()
if err != nil {
t.Errorf("NewNATSpec error %v", err)
}
- ns.SetABI(`
- [{
- "name": "multiply",
- "constant": false,
- "type": "function",
- "inputs": [{
- "name": "a",
- "type": "uint256"
- }],
- "outputs": [{
- "name": "d",
- "type": "uint256"
- }]
- }]
- `)
- ns.SetDescription("Will multiply `a` by 7 and return `a * 7`.")
- ns.SetMethod("multiply")
-
- notice := ns.Parse()
+ notice, err := ns.Notice(tx, abi, method, desc)
+
+ if err != nil {
+ t.Errorf("expected no error got %v", err)
+ }
expected := "Will multiply 122 by 7 and return 854."
if notice != expected {
@@ -48,4 +55,43 @@ func TestNotice(t *testing.T) {
} else {
t.Logf("returned notice \"%v\"", notice)
}
+
+ notice, err = ns.Notice(tx, abi, method, "Will multiply 122 by \"7\" and return 854.")
+
+ expected = "natspec.js error setting expression: (anonymous): Line 1:41 Unexpected number"
+
+ if err == nil {
+ t.Errorf("expected error, got nothing (notice: '%v')", err, notice)
+ } else {
+ if err.Error() != expected {
+ t.Errorf("expected error '%s' got '%v' (notice: '%v')", expected, err, notice)
+ }
+ }
+
+ // https://github.com/ethereum/natspec.js/issues/1
+ // badDesc := "Will multiply `e` by 7 and return `a * 7`."
+ // notice, err = ns.Notice(tx, abi, method, badDesc)
+
+ // expected = "natspec.js error evaluating expression: wrong input param in expression ''"
+
+ // if err == nil {
+ // t.Errorf("expected error, got nothing (notice: '%v')", notice)
+ // } else {
+ // if err.Error() != expected {
+ // t.Errorf("expected error '%s' got '%v' (notice: '%v')", expected, err, notice)
+ // }
+ // }
+
+ notice, err = ns.Notice(tx, abi, "missing_method", desc)
+
+ expected = "natspec.js error evaluating expression: wrong input params in expression 'Will multiply `a` by 7 and return `a * 7`.'"
+
+ if err == nil {
+ t.Errorf("expected error, got nothing (notice: '%v')", notice)
+ } else {
+ if err.Error() != expected {
+ t.Errorf("expected error '%s' got '%v' (notice: '%v')", expected, err, notice)
+ }
+ }
+
}