diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-16 18:27:38 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-16 18:27:38 +0800 |
commit | b5234413611ce5984292f85a01de1f56c045b490 (patch) | |
tree | e6e0c6f7fe8358a2dc63cdea11ac66b4f59397f5 /common/natspec/natspec_test.go | |
parent | 0b8f66ed9ef177dc72442dd7ba337c6733e30344 (diff) | |
download | dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.gz dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.zst dexon-b5234413611ce5984292f85a01de1f56c045b490.zip |
Moved ethutil => common
Diffstat (limited to 'common/natspec/natspec_test.go')
-rw-r--r-- | common/natspec/natspec_test.go | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/common/natspec/natspec_test.go b/common/natspec/natspec_test.go new file mode 100644 index 000000000..330dc831d --- /dev/null +++ b/common/natspec/natspec_test.go @@ -0,0 +1,97 @@ +package natspec + +import ( + "testing" +) + +func TestNotice(t *testing.T) { + + tx := ` + { + "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) + } + + 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 { + t.Errorf("incorrect notice. expected %v, got %v", expected, notice) + } 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: Error: Natspec evaluation failed, wrong input params" + + 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: Error: Natspec evaluation failed, method does not exist" + + 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) + } + } + +} |