@ -36,6 +36,7 @@ var bindTests = []struct {
abi string
abi string
imports string
imports string
tester string
tester string
fsigs [ ] map [ string ] string
} {
} {
// Test that the binding is available in combined and separate forms too
// Test that the binding is available in combined and separate forms too
{
{
@ -55,6 +56,7 @@ var bindTests = []struct {
t . Fatalf ( "transactor binding (%v) nil or error (%v) not nil" , b , nil )
t . Fatalf ( "transactor binding (%v) nil or error (%v) not nil" , b , nil )
}
}
` ,
` ,
nil ,
} ,
} ,
// Test that all the official sample contracts bind correctly
// Test that all the official sample contracts bind correctly
{
{
@ -68,6 +70,7 @@ var bindTests = []struct {
t . Fatalf ( "binding (%v) nil or error (%v) not nil" , b , nil )
t . Fatalf ( "binding (%v) nil or error (%v) not nil" , b , nil )
}
}
` ,
` ,
nil ,
} ,
} ,
{
{
` Crowdsale ` ,
` Crowdsale ` ,
@ -80,6 +83,7 @@ var bindTests = []struct {
t . Fatalf ( "binding (%v) nil or error (%v) not nil" , b , nil )
t . Fatalf ( "binding (%v) nil or error (%v) not nil" , b , nil )
}
}
` ,
` ,
nil ,
} ,
} ,
{
{
` DAO ` ,
` DAO ` ,
@ -92,6 +96,7 @@ var bindTests = []struct {
t . Fatalf ( "binding (%v) nil or error (%v) not nil" , b , nil )
t . Fatalf ( "binding (%v) nil or error (%v) not nil" , b , nil )
}
}
` ,
` ,
nil ,
} ,
} ,
// Test that named and anonymous inputs are handled correctly
// Test that named and anonymous inputs are handled correctly
{
{
@ -125,6 +130,7 @@ var bindTests = []struct {
fmt . Println ( err )
fmt . Println ( err )
} ` ,
} ` ,
nil ,
} ,
} ,
// Test that named and anonymous outputs are handled correctly
// Test that named and anonymous outputs are handled correctly
{
{
@ -161,6 +167,7 @@ var bindTests = []struct {
fmt . Println ( str1 , str2 , res . Str1 , res . Str2 , err )
fmt . Println ( str1 , str2 , res . Str1 , res . Str2 , err )
} ` ,
} ` ,
nil ,
} ,
} ,
// Tests that named, anonymous and indexed events are handled correctly
// Tests that named, anonymous and indexed events are handled correctly
{
{
@ -226,6 +233,7 @@ var bindTests = []struct {
if _ , ok := reflect . TypeOf ( & EventChecker { } ) . MethodByName ( "FilterAnonymous" ) ; ok {
if _ , ok := reflect . TypeOf ( & EventChecker { } ) . MethodByName ( "FilterAnonymous" ) ; ok {
t . Errorf ( "binding has disallowed method (FilterAnonymous)" )
t . Errorf ( "binding has disallowed method (FilterAnonymous)" )
} ` ,
} ` ,
nil ,
} ,
} ,
// Test that contract interactions (deploy, transact and call) generate working code
// Test that contract interactions (deploy, transact and call) generate working code
{
{
@ -282,6 +290,7 @@ var bindTests = []struct {
t . Fatalf ( "Transact string mismatch: have '%s', want 'Transact string'" , str )
t . Fatalf ( "Transact string mismatch: have '%s', want 'Transact string'" , str )
}
}
` ,
` ,
nil ,
} ,
} ,
// Tests that plain values can be properly returned and deserialized
// Tests that plain values can be properly returned and deserialized
{
{
@ -322,6 +331,7 @@ var bindTests = []struct {
t . Fatalf ( "Retrieved value mismatch: have %v/%v, want %v/%v" , str , num , "Hi" , 1 )
t . Fatalf ( "Retrieved value mismatch: have %v/%v, want %v/%v" , str , num , "Hi" , 1 )
}
}
` ,
` ,
nil ,
} ,
} ,
// Tests that tuples can be properly returned and deserialized
// Tests that tuples can be properly returned and deserialized
{
{
@ -362,6 +372,7 @@ var bindTests = []struct {
t . Fatalf ( "Retrieved value mismatch: have %v/%v, want %v/%v" , res . A , res . B , "Hi" , 1 )
t . Fatalf ( "Retrieved value mismatch: have %v/%v, want %v/%v" , res . A , res . B , "Hi" , 1 )
}
}
` ,
` ,
nil ,
} ,
} ,
// Tests that arrays/slices can be properly returned and deserialized.
// Tests that arrays/slices can be properly returned and deserialized.
// Only addresses are tested, remainder just compiled to keep the test small.
// Only addresses are tested, remainder just compiled to keep the test small.
@ -414,6 +425,7 @@ var bindTests = []struct {
t . Fatalf ( "Slice return mismatch: have %v, want %v" , out , [ ] common . Address { auth . From , common . Address { } } )
t . Fatalf ( "Slice return mismatch: have %v, want %v" , out , [ ] common . Address { auth . From , common . Address { } } )
}
}
` ,
` ,
nil ,
} ,
} ,
// Tests that anonymous default methods can be correctly invoked
// Tests that anonymous default methods can be correctly invoked
{
{
@ -459,6 +471,7 @@ var bindTests = []struct {
t . Fatalf ( "Address mismatch: have %v, want %v" , caller , auth . From )
t . Fatalf ( "Address mismatch: have %v, want %v" , caller , auth . From )
}
}
` ,
` ,
nil ,
} ,
} ,
// Tests that non-existent contracts are reported as such (though only simulator test)
// Tests that non-existent contracts are reported as such (though only simulator test)
{
{
@ -493,6 +506,7 @@ var bindTests = []struct {
t . Fatalf ( "Error mismatch: have %v, want %v" , err , bind . ErrNoCode )
t . Fatalf ( "Error mismatch: have %v, want %v" , err , bind . ErrNoCode )
}
}
` ,
` ,
nil ,
} ,
} ,
// Tests that gas estimation works for contracts with weird gas mechanics too.
// Tests that gas estimation works for contracts with weird gas mechanics too.
{
{
@ -543,6 +557,7 @@ var bindTests = []struct {
t . Fatalf ( "Field mismatch: have %v, want %v" , field , "automatic" )
t . Fatalf ( "Field mismatch: have %v, want %v" , field , "automatic" )
}
}
` ,
` ,
nil ,
} ,
} ,
// Test that constant functions can be called from an (optional) specified address
// Test that constant functions can be called from an (optional) specified address
{
{
@ -591,6 +606,7 @@ var bindTests = []struct {
}
}
}
}
` ,
` ,
nil ,
} ,
} ,
// Tests that methods and returns with underscores inside work correctly.
// Tests that methods and returns with underscores inside work correctly.
{
{
@ -665,6 +681,7 @@ var bindTests = []struct {
fmt . Println ( a , b , err )
fmt . Println ( a , b , err )
` ,
` ,
nil ,
} ,
} ,
// Tests that logs can be successfully filtered and decoded.
// Tests that logs can be successfully filtered and decoded.
{
{
@ -881,6 +898,7 @@ var bindTests = []struct {
case <- time . After ( 250 * time . Millisecond ) :
case <- time . After ( 250 * time . Millisecond ) :
}
}
` ,
` ,
nil ,
} ,
} ,
{
{
` DeeplyNestedArray ` ,
` DeeplyNestedArray ` ,
@ -956,6 +974,46 @@ var bindTests = []struct {
t . Fatalf ( "Retrieved value does not match expected value! got: %d, expected: %d. %v" , retrievedArr [ 4 ] [ 3 ] [ 2 ] , testArr [ 4 ] [ 3 ] [ 2 ] , err )
t . Fatalf ( "Retrieved value does not match expected value! got: %d, expected: %d. %v" , retrievedArr [ 4 ] [ 3 ] [ 2 ] , testArr [ 4 ] [ 3 ] [ 2 ] , err )
}
}
` ,
` ,
nil ,
} ,
{
` CallbackParam ` ,
`
contract FunctionPointerTest {
function test ( function ( uint256 ) external callback ) external {
callback ( 1 ) ;
}
}
` ,
` 608060405234801561001057600080fd5b5061015e806100206000396000f3fe60806040526004361061003b576000357c010000000000000000000000000000000000000000000000000000000090048063d7a5aba214610040575b600080fd5b34801561004c57600080fd5b506100be6004803603602081101561006357600080fd5b810190808035806c0100000000000000000000000090049068010000000000000000900463ffffffff1677ffffffffffffffffffffffffffffffffffffffffffffffff169091602001919093929190939291905050506100c0565b005b818160016040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b15801561011657600080fd5b505af115801561012a573d6000803e3d6000fd5b50505050505056fea165627a7a7230582062f87455ff84be90896dbb0c4e4ddb505c600d23089f8e80a512548440d7e2580029 ` ,
` [
{
"constant" : false ,
"inputs" : [
{
"name" : "callback" ,
"type" : "function"
}
] ,
"name" : "test" ,
"outputs" : [ ] ,
"payable" : false ,
"stateMutability" : "nonpayable" ,
"type" : "function"
}
] ` , `
"strings"
` ,
`
if strings . Compare ( "test(function)" , CallbackParamFuncSigs [ "d7a5aba2" ] ) != 0 {
t . Fatalf ( "" )
}
` ,
[ ] map [ string ] string {
{
"test(function)" : "d7a5aba2" ,
} ,
} ,
} ,
} ,
}
}
@ -981,7 +1039,7 @@ func TestGolangBindings(t *testing.T) {
// Generate the test suite for all the contracts
// Generate the test suite for all the contracts
for i , tt := range bindTests {
for i , tt := range bindTests {
// Generate the binding and create a Go source file in the workspace
// Generate the binding and create a Go source file in the workspace
bind , err := Bind ( [ ] string { tt . name } , [ ] string { tt . abi } , [ ] string { tt . bytecode } , "bindtest" , LangGo )
bind , err := Bind ( [ ] string { tt . name } , [ ] string { tt . abi } , [ ] string { tt . bytecode } , tt . fsigs , "bindtest" , LangGo )
if err != nil {
if err != nil {
t . Fatalf ( "test %d: failed to generate binding: %v" , i , err )
t . Fatalf ( "test %d: failed to generate binding: %v" , i , err )
}
}
@ -1072,6 +1130,7 @@ func TestJavaBindings(t *testing.T) {
package bindtest ;
package bindtest ;
import org . ethereum . geth . * ;
import org . ethereum . geth . * ;
import java . util . * ;
public class Test {
public class Test {
@ -1400,7 +1459,7 @@ public class Test {
} ,
} ,
}
}
for i , c := range cases {
for i , c := range cases {
binding , err := Bind ( [ ] string { c . name } , [ ] string { c . abi } , [ ] string { c . bytecode } , "bindtest" , LangJava )
binding , err := Bind ( [ ] string { c . name } , [ ] string { c . abi } , [ ] string { c . bytecode } , nil , "bindtest" , LangJava )
if err != nil {
if err != nil {
t . Fatalf ( "test %d: failed to generate binding: %v" , i , err )
t . Fatalf ( "test %d: failed to generate binding: %v" , i , err )
}
}