|
|
@ -120,6 +120,7 @@ var methods = map[string]Method{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestReader(t *testing.T) { |
|
|
|
func TestReader(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abi := ABI{ |
|
|
|
abi := ABI{ |
|
|
|
Methods: methods, |
|
|
|
Methods: methods, |
|
|
|
} |
|
|
|
} |
|
|
@ -151,6 +152,7 @@ func TestReader(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestInvalidABI(t *testing.T) { |
|
|
|
func TestInvalidABI(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
json := `[{ "type" : "function", "name" : "", "constant" : fals }]` |
|
|
|
json := `[{ "type" : "function", "name" : "", "constant" : fals }]` |
|
|
|
_, err := JSON(strings.NewReader(json)) |
|
|
|
_, err := JSON(strings.NewReader(json)) |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
@ -170,6 +172,7 @@ func TestInvalidABI(t *testing.T) { |
|
|
|
// constructor(uint256 a, uint256 b) public{}
|
|
|
|
// constructor(uint256 a, uint256 b) public{}
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
func TestConstructor(t *testing.T) { |
|
|
|
func TestConstructor(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
json := `[{ "inputs": [{"internalType": "uint256","name": "a","type": "uint256" },{ "internalType": "uint256","name": "b","type": "uint256"}],"stateMutability": "nonpayable","type": "constructor"}]` |
|
|
|
json := `[{ "inputs": [{"internalType": "uint256","name": "a","type": "uint256" },{ "internalType": "uint256","name": "b","type": "uint256"}],"stateMutability": "nonpayable","type": "constructor"}]` |
|
|
|
method := NewMethod("", "", Constructor, "nonpayable", false, false, []Argument{{"a", Uint256, false}, {"b", Uint256, false}}, nil) |
|
|
|
method := NewMethod("", "", Constructor, "nonpayable", false, false, []Argument{{"a", Uint256, false}, {"b", Uint256, false}}, nil) |
|
|
|
// Test from JSON
|
|
|
|
// Test from JSON
|
|
|
@ -199,6 +202,7 @@ func TestConstructor(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestTestNumbers(t *testing.T) { |
|
|
|
func TestTestNumbers(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
t.Fatal(err) |
|
|
@ -236,6 +240,7 @@ func TestTestNumbers(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMethodSignature(t *testing.T) { |
|
|
|
func TestMethodSignature(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
m := NewMethod("foo", "foo", Function, "", false, false, []Argument{{"bar", String, false}, {"baz", String, false}}, nil) |
|
|
|
m := NewMethod("foo", "foo", Function, "", false, false, []Argument{{"bar", String, false}, {"baz", String, false}}, nil) |
|
|
|
exp := "foo(string,string)" |
|
|
|
exp := "foo(string,string)" |
|
|
|
if m.Sig != exp { |
|
|
|
if m.Sig != exp { |
|
|
@ -274,6 +279,7 @@ func TestMethodSignature(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestOverloadedMethodSignature(t *testing.T) { |
|
|
|
func TestOverloadedMethodSignature(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
json := `[{"constant":true,"inputs":[{"name":"i","type":"uint256"},{"name":"j","type":"uint256"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"i","type":"uint256"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"i","type":"uint256"}],"name":"bar","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"i","type":"uint256"},{"indexed":false,"name":"j","type":"uint256"}],"name":"bar","type":"event"}]` |
|
|
|
json := `[{"constant":true,"inputs":[{"name":"i","type":"uint256"},{"name":"j","type":"uint256"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"i","type":"uint256"}],"name":"foo","outputs":[],"payable":false,"stateMutability":"pure","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"i","type":"uint256"}],"name":"bar","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"i","type":"uint256"},{"indexed":false,"name":"j","type":"uint256"}],"name":"bar","type":"event"}]` |
|
|
|
abi, err := JSON(strings.NewReader(json)) |
|
|
|
abi, err := JSON(strings.NewReader(json)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -297,6 +303,7 @@ func TestOverloadedMethodSignature(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestCustomErrors(t *testing.T) { |
|
|
|
func TestCustomErrors(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
json := `[{ "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ],"name": "MyError", "type": "error"} ]` |
|
|
|
json := `[{ "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ],"name": "MyError", "type": "error"} ]` |
|
|
|
abi, err := JSON(strings.NewReader(json)) |
|
|
|
abi, err := JSON(strings.NewReader(json)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -311,6 +318,7 @@ func TestCustomErrors(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMultiPack(t *testing.T) { |
|
|
|
func TestMultiPack(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
t.Fatal(err) |
|
|
@ -348,6 +356,7 @@ func ExampleJSON() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestInputVariableInputLength(t *testing.T) { |
|
|
|
func TestInputVariableInputLength(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
const definition = `[ |
|
|
|
const definition = `[ |
|
|
|
{ "type" : "function", "name" : "strOne", "constant" : true, "inputs" : [ { "name" : "str", "type" : "string" } ] }, |
|
|
|
{ "type" : "function", "name" : "strOne", "constant" : true, "inputs" : [ { "name" : "str", "type" : "string" } ] }, |
|
|
|
{ "type" : "function", "name" : "bytesOne", "constant" : true, "inputs" : [ { "name" : "str", "type" : "bytes" } ] }, |
|
|
|
{ "type" : "function", "name" : "bytesOne", "constant" : true, "inputs" : [ { "name" : "str", "type" : "bytes" } ] }, |
|
|
@ -476,6 +485,7 @@ func TestInputVariableInputLength(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestInputFixedArrayAndVariableInputLength(t *testing.T) { |
|
|
|
func TestInputFixedArrayAndVariableInputLength(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
t.Error(err) |
|
|
@ -650,6 +660,7 @@ func TestInputFixedArrayAndVariableInputLength(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestDefaultFunctionParsing(t *testing.T) { |
|
|
|
func TestDefaultFunctionParsing(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
const definition = `[{ "name" : "balance", "type" : "function" }]` |
|
|
|
const definition = `[{ "name" : "balance", "type" : "function" }]` |
|
|
|
|
|
|
|
|
|
|
|
abi, err := JSON(strings.NewReader(definition)) |
|
|
|
abi, err := JSON(strings.NewReader(definition)) |
|
|
@ -663,6 +674,7 @@ func TestDefaultFunctionParsing(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestBareEvents(t *testing.T) { |
|
|
|
func TestBareEvents(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
const definition = `[ |
|
|
|
const definition = `[ |
|
|
|
{ "type" : "event", "name" : "balance" }, |
|
|
|
{ "type" : "event", "name" : "balance" }, |
|
|
|
{ "type" : "event", "name" : "anon", "anonymous" : true}, |
|
|
|
{ "type" : "event", "name" : "anon", "anonymous" : true}, |
|
|
@ -739,6 +751,7 @@ func TestBareEvents(t *testing.T) { |
|
|
|
//
|
|
|
|
//
|
|
|
|
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
|
|
|
|
// receipt{status=1 cgas=23949 bloom=00000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000040200000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 logs=[log: b6818c8064f645cd82d99b59a1a267d6d61117ef [75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed] 000000000000000000000000376c47978271565f56deb45495afa69e59c16ab200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158 9ae378b6d4409eada347a5dc0c180f186cb62dc68fcc0f043425eb917335aa28 0 95d429d309bb9d753954195fe2d69bd140b4ae731b9b5b605c34323de162cf00 0]}
|
|
|
|
func TestUnpackEvent(t *testing.T) { |
|
|
|
func TestUnpackEvent(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes"}],"name":"received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"}],"name":"receivedAddr","type":"event"}]` |
|
|
|
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes"}],"name":"received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"}],"name":"receivedAddr","type":"event"}]` |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -777,6 +790,7 @@ func TestUnpackEvent(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestUnpackEventIntoMap(t *testing.T) { |
|
|
|
func TestUnpackEventIntoMap(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes"}],"name":"received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"}],"name":"receivedAddr","type":"event"}]` |
|
|
|
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"memo","type":"bytes"}],"name":"received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"}],"name":"receivedAddr","type":"event"}]` |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -827,6 +841,7 @@ func TestUnpackEventIntoMap(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestUnpackMethodIntoMap(t *testing.T) { |
|
|
|
func TestUnpackMethodIntoMap(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"send","outputs":[{"name":"amount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"get","outputs":[{"name":"hash","type":"bytes"}],"payable":true,"stateMutability":"payable","type":"function"}]` |
|
|
|
const abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"receive","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"send","outputs":[{"name":"amount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"get","outputs":[{"name":"hash","type":"bytes"}],"payable":true,"stateMutability":"payable","type":"function"}]` |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -877,6 +892,7 @@ func TestUnpackMethodIntoMap(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestUnpackIntoMapNamingConflict(t *testing.T) { |
|
|
|
func TestUnpackIntoMapNamingConflict(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
// Two methods have the same name
|
|
|
|
// Two methods have the same name
|
|
|
|
var abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"get","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"send","outputs":[{"name":"amount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"get","outputs":[{"name":"hash","type":"bytes"}],"payable":true,"stateMutability":"payable","type":"function"}]` |
|
|
|
var abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"get","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"send","outputs":[{"name":"amount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"get","outputs":[{"name":"hash","type":"bytes"}],"payable":true,"stateMutability":"payable","type":"function"}]` |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
abi, err := JSON(strings.NewReader(abiJSON)) |
|
|
@ -960,6 +976,7 @@ func TestUnpackIntoMapNamingConflict(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestABI_MethodById(t *testing.T) { |
|
|
|
func TestABI_MethodById(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
abi, err := JSON(strings.NewReader(jsondata)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
t.Fatal(err) |
|
|
@ -992,6 +1009,7 @@ func TestABI_MethodById(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestABI_EventById(t *testing.T) { |
|
|
|
func TestABI_EventById(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
tests := []struct { |
|
|
|
tests := []struct { |
|
|
|
name string |
|
|
|
name string |
|
|
|
json string |
|
|
|
json string |
|
|
@ -1058,6 +1076,7 @@ func TestABI_EventById(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestABI_ErrorByID(t *testing.T) { |
|
|
|
func TestABI_ErrorByID(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abi, err := JSON(strings.NewReader(`[ |
|
|
|
abi, err := JSON(strings.NewReader(`[ |
|
|
|
{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"MyError1","type":"error"}, |
|
|
|
{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"MyError1","type":"error"}, |
|
|
|
{"inputs":[{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"x","type":"tuple"},{"internalType":"address","name":"y","type":"address"},{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"z","type":"tuple"}],"name":"MyError2","type":"error"}, |
|
|
|
{"inputs":[{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"x","type":"tuple"},{"internalType":"address","name":"y","type":"address"},{"components":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"string","name":"b","type":"string"},{"internalType":"address","name":"c","type":"address"}],"internalType":"struct MyError.MyStruct","name":"z","type":"tuple"}],"name":"MyError2","type":"error"}, |
|
|
@ -1088,6 +1107,7 @@ func TestABI_ErrorByID(t *testing.T) { |
|
|
|
// TestDoubleDuplicateMethodNames checks that if transfer0 already exists, there won't be a name
|
|
|
|
// TestDoubleDuplicateMethodNames checks that if transfer0 already exists, there won't be a name
|
|
|
|
// conflict and that the second transfer method will be renamed transfer1.
|
|
|
|
// conflict and that the second transfer method will be renamed transfer1.
|
|
|
|
func TestDoubleDuplicateMethodNames(t *testing.T) { |
|
|
|
func TestDoubleDuplicateMethodNames(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abiJSON := `[{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"},{"name":"data","type":"bytes"}],"name":"transfer0","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"},{"name":"data","type":"bytes"},{"name":"customFallback","type":"string"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]` |
|
|
|
abiJSON := `[{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"},{"name":"data","type":"bytes"}],"name":"transfer0","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"},{"name":"data","type":"bytes"},{"name":"customFallback","type":"string"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]` |
|
|
|
contractAbi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
contractAbi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -1117,6 +1137,7 @@ func TestDoubleDuplicateMethodNames(t *testing.T) { |
|
|
|
// event send();
|
|
|
|
// event send();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
func TestDoubleDuplicateEventNames(t *testing.T) { |
|
|
|
func TestDoubleDuplicateEventNames(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abiJSON := `[{"anonymous": false,"inputs": [{"indexed": false,"internalType": "uint256","name": "a","type": "uint256"}],"name": "send","type": "event"},{"anonymous": false,"inputs": [],"name": "send0","type": "event"},{ "anonymous": false, "inputs": [],"name": "send","type": "event"}]` |
|
|
|
abiJSON := `[{"anonymous": false,"inputs": [{"indexed": false,"internalType": "uint256","name": "a","type": "uint256"}],"name": "send","type": "event"},{"anonymous": false,"inputs": [],"name": "send0","type": "event"},{ "anonymous": false, "inputs": [],"name": "send","type": "event"}]` |
|
|
|
contractAbi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
contractAbi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -1144,6 +1165,7 @@ func TestDoubleDuplicateEventNames(t *testing.T) { |
|
|
|
// event send(uint256, uint256);
|
|
|
|
// event send(uint256, uint256);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
func TestUnnamedEventParam(t *testing.T) { |
|
|
|
func TestUnnamedEventParam(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
abiJSON := `[{ "anonymous": false, "inputs": [{ "indexed": false,"internalType": "uint256", "name": "","type": "uint256"},{"indexed": false,"internalType": "uint256","name": "","type": "uint256"}],"name": "send","type": "event"}]` |
|
|
|
abiJSON := `[{ "anonymous": false, "inputs": [{ "indexed": false,"internalType": "uint256", "name": "","type": "uint256"},{"indexed": false,"internalType": "uint256","name": "","type": "uint256"}],"name": "send","type": "event"}]` |
|
|
|
contractAbi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
contractAbi, err := JSON(strings.NewReader(abiJSON)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -1177,7 +1199,9 @@ func TestUnpackRevert(t *testing.T) { |
|
|
|
{"4e487b7100000000000000000000000000000000000000000000000000000000000000ff", "unknown panic code: 0xff", nil}, |
|
|
|
{"4e487b7100000000000000000000000000000000000000000000000000000000000000ff", "unknown panic code: 0xff", nil}, |
|
|
|
} |
|
|
|
} |
|
|
|
for index, c := range cases { |
|
|
|
for index, c := range cases { |
|
|
|
|
|
|
|
index, c := index, c |
|
|
|
t.Run(fmt.Sprintf("case %d", index), func(t *testing.T) { |
|
|
|
t.Run(fmt.Sprintf("case %d", index), func(t *testing.T) { |
|
|
|
|
|
|
|
t.Parallel() |
|
|
|
got, err := UnpackRevert(common.Hex2Bytes(c.input)) |
|
|
|
got, err := UnpackRevert(common.Hex2Bytes(c.input)) |
|
|
|
if c.expectErr != nil { |
|
|
|
if c.expectErr != nil { |
|
|
|
if err == nil { |
|
|
|
if err == nil { |
|
|
|