@@ -31,25 +31,25 @@ import (
3131
3232const jsondata = `
3333[
34- { "name" : "balance", "const" : true },
35- { "name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] }
34+ { "type" : "function", " name" : "balance", "const" : true },
35+ { "type" : "function", " name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] }
3636]`
3737
3838const jsondata2 = `
3939[
40- { "name" : "balance", "const" : true },
41- { "name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] },
42- { "name" : "test", "const" : false, "inputs" : [ { "name" : "number", "type" : "uint32" } ] },
43- { "name" : "string", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "string" } ] },
44- { "name" : "bool", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "bool" } ] },
45- { "name" : "address", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "address" } ] },
46- { "name" : "string32", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "string32" } ] },
47- { "name" : "uint64[2]", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[2]" } ] },
48- { "name" : "uint64[]", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[]" } ] },
49- { "name" : "foo", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" } ] },
50- { "name" : "bar", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" }, { "name" : "string", "type" : "uint16" } ] },
51- { "name" : "slice", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32[2]" } ] },
52- { "name" : "slice256", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint256[2]" } ] }
40+ { "type" : "function", " name" : "balance", "const" : true },
41+ { "type" : "function", " name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] },
42+ { "type" : "function", " name" : "test", "const" : false, "inputs" : [ { "name" : "number", "type" : "uint32" } ] },
43+ { "type" : "function", " name" : "string", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "string" } ] },
44+ { "type" : "function", " name" : "bool", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "bool" } ] },
45+ { "type" : "function", " name" : "address", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "address" } ] },
46+ { "type" : "function", " name" : "string32", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "string32" } ] },
47+ { "type" : "function", " name" : "uint64[2]", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[2]" } ] },
48+ { "type" : "function", " name" : "uint64[]", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[]" } ] },
49+ { "type" : "function", " name" : "foo", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" } ] },
50+ { "type" : "function", " name" : "bar", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" }, { "name" : "string", "type" : "uint16" } ] },
51+ { "type" : "function", " name" : "slice", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32[2]" } ] },
52+ { "type" : "function", " name" : "slice256", "const" : false, "inputs" : [ { "name" : "inputs", "type" : "uint256[2]" } ] }
5353]`
5454
5555func TestType (t * testing.T ) {
@@ -96,7 +96,7 @@ func TestReader(t *testing.T) {
9696 },
9797 "send" : Method {
9898 "send" , false , []Argument {
99- Argument {"amount" , Uint256 },
99+ Argument {"amount" , Uint256 , false },
100100 }, nil ,
101101 },
102102 },
@@ -238,7 +238,7 @@ func TestTestAddress(t *testing.T) {
238238func TestMethodSignature (t * testing.T ) {
239239 String , _ := NewType ("string" )
240240 String32 , _ := NewType ("string32" )
241- m := Method {"foo" , false , []Argument {Argument {"bar" , String32 }, Argument {"baz" , String }}, nil }
241+ m := Method {"foo" , false , []Argument {Argument {"bar" , String32 , false }, Argument {"baz" , String , false }}, nil }
242242 exp := "foo(string32,string)"
243243 if m .Sig () != exp {
244244 t .Error ("signature mismatch" , exp , "!=" , m .Sig ())
@@ -250,7 +250,7 @@ func TestMethodSignature(t *testing.T) {
250250 }
251251
252252 uintt , _ := NewType ("uint" )
253- m = Method {"foo" , false , []Argument {Argument {"bar" , uintt }}, nil }
253+ m = Method {"foo" , false , []Argument {Argument {"bar" , uintt , false }}, nil }
254254 exp = "foo(uint256)"
255255 if m .Sig () != exp {
256256 t .Error ("signature mismatch" , exp , "!=" , m .Sig ())
@@ -367,8 +367,8 @@ func ExampleJSON() {
367367
368368func TestBytes (t * testing.T ) {
369369 const definition = `[
370- { "name" : "balance", "const" : true, "inputs" : [ { "name" : "address", "type" : "bytes20" } ] },
371- { "name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] }
370+ { "type" : "function", " name" : "balance", "const" : true, "inputs" : [ { "name" : "address", "type" : "bytes20" } ] },
371+ { "type" : "function", " name" : "send", "const" : false, "inputs" : [ { "name" : "amount", "type" : "uint256" } ] }
372372]`
373373
374374 abi , err := JSON (strings .NewReader (definition ))
@@ -396,10 +396,8 @@ func TestBytes(t *testing.T) {
396396
397397func TestReturn (t * testing.T ) {
398398 const definition = `[
399- { "name" : "balance", "const" : true, "inputs" : [], "outputs" : [ { "name": "", "type": "hash" } ] },
400- { "name" : "name", "const" : true, "inputs" : [], "outputs" : [ { "name": "", "type": "address" } ] }
401-
402- ]`
399+ { "type" : "function", "name" : "balance", "const" : true, "inputs" : [], "outputs" : [ { "name": "", "type": "hash" } ] },
400+ { "type" : "function", "name" : "name", "const" : true, "inputs" : [], "outputs" : [ { "name": "", "type": "address" } ] }]`
403401
404402 abi , err := JSON (strings .NewReader (definition ))
405403 if err != nil {
@@ -424,3 +422,39 @@ func TestReturn(t *testing.T) {
424422 t .Errorf ("expected type common.Address, got %T" , r )
425423 }
426424}
425+
426+ func TestDefaultFunctionParsing (t * testing.T ) {
427+ const definition = `[{ "name" : "balance" }]`
428+
429+ abi , err := JSON (strings .NewReader (definition ))
430+ if err != nil {
431+ t .Fatal (err )
432+ }
433+
434+ if _ , ok := abi .Methods ["balance" ]; ! ok {
435+ t .Error ("expected 'balance' to be present" )
436+ }
437+ }
438+
439+ func TestBareEvents (t * testing.T ) {
440+ const definition = `[
441+ { "type" : "event", "name" : "balance" },
442+ { "type" : "event", "name" : "name" }]`
443+
444+ abi , err := JSON (strings .NewReader (definition ))
445+ if err != nil {
446+ t .Fatal (err )
447+ }
448+
449+ if len (abi .Events ) != 2 {
450+ t .Error ("expected 2 events" )
451+ }
452+
453+ if _ , ok := abi .Events ["balance" ]; ! ok {
454+ t .Error ("expected 'balance' event to be present" )
455+ }
456+
457+ if _ , ok := abi .Events ["name" ]; ! ok {
458+ t .Error ("expected 'name' event to be present" )
459+ }
460+ }
0 commit comments