diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 3d1010229c..7eadb664b4 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -34,7 +34,8 @@ import ( type ABI struct { Constructor Method Methods map[string]Method - Events map[string]Event + // todo: make events loggable from an interface that specifies very abstract functions. + Events map[string]Event } // JSON returns a parsed ABI interface and error if it failed. diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index a45bd6cc0f..9b37ec9750 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -370,6 +370,7 @@ func TestPack(t *testing.T) { {"address[]", []common.Address{{1}, {2}}, formatSliceOutput(pad([]byte{1}, 20, false), pad([]byte{2}, 20, false))}, {"bytes32[]", []common.Hash{{1}, {2}}, formatSliceOutput(pad([]byte{1}, 32, false), pad([]byte{2}, 32, false))}, {"function", [24]byte{1}, pad([]byte{1}, 32, false)}, + {"bool[]", []bool{false, false}, formatSliceOutput(pad([]byte{0}, 32, true), pad([]byte{0}, 32, true))}, } { typ, err := NewType(test.typ) if err != nil { @@ -471,7 +472,8 @@ const jsondata2 = ` { "type" : "function", "name" : "uint64[2]", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[2]" } ] }, { "type" : "function", "name" : "uint64[]", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "uint64[]" } ] }, { "type" : "function", "name" : "foo", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" } ] }, - { "type" : "function", "name" : "bar", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" }, { "name" : "string", "type" : "uint16" } ] }, + { "type" : "function", "name" : "bar", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32" }, { "name" : "", "type" : "uint16" } ] }, + { "type" : "function", "name" : "boolMultiPack", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "bool" }, { "name" : "", "type" : "bool" } ] }, { "type" : "function", "name" : "slice", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "uint32[2]" } ] }, { "type" : "function", "name" : "slice256", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "uint256[2]" } ] }, { "type" : "function", "name" : "sliceAddress", "constant" : false, "inputs" : [ { "name" : "inputs", "type" : "address[]" } ] }, @@ -626,6 +628,22 @@ func TestMultiPack(t *testing.T) { if !bytes.Equal(packed, sig) { t.Errorf("expected %x got %x", sig, packed) } + + sig = crypto.Keccak256([]byte("boolMultiPack(bool,bool)"))[:4] + sig = append(sig, make([]byte, 64)...) + sig[35] = 0 + sig[67] = 0 + + packed, err = abi.Pack("boolMultiPack", []interface{}{false, false}...) + if err != nil { + t.Error(err) + t.FailNow() + } + + if !bytes.Equal(packed, sig) { + t.Errorf("expected %x got %x", sig, packed) + } + } func ExampleJSON() { diff --git a/accounts/abi/packing.go b/accounts/abi/packing.go index 1d7f85e2ba..579e4365da 100644 --- a/accounts/abi/packing.go +++ b/accounts/abi/packing.go @@ -17,6 +17,7 @@ package abi import ( + "fmt" "reflect" "github.com/ethereum/go-ethereum/common" @@ -48,6 +49,7 @@ func packElement(t Type, reflectValue reflect.Value) []byte { if reflectValue.Bool() { return math.PaddedBigBytes(common.Big1, 32) } else { + fmt.Printf("Got this for value: %v\n", math.PaddedBigBytes(common.Big0, 32)) return math.PaddedBigBytes(common.Big0, 32) } case BytesTy: diff --git a/common/math/big_test.go b/common/math/big_test.go index e789bd18e1..c9839e972d 100644 --- a/common/math/big_test.go +++ b/common/math/big_test.go @@ -125,6 +125,7 @@ func TestPaddedBigBytes(t *testing.T) { {num: big.NewInt(1), n: 4, result: []byte{0, 0, 0, 1}}, {num: big.NewInt(512), n: 4, result: []byte{0, 0, 2, 0}}, {num: BigPow(2, 32), n: 4, result: []byte{1, 0, 0, 0, 0}}, + {num: big.NewInt(0), n: 32, result: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, } for _, test := range tests { if result := PaddedBigBytes(test.num, test.n); !bytes.Equal(result, test.result) {