aboutsummaryrefslogtreecommitdiffstats
path: root/signer/core
diff options
context:
space:
mode:
Diffstat (limited to 'signer/core')
-rw-r--r--signer/core/abihelper_test.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/signer/core/abihelper_test.go b/signer/core/abihelper_test.go
index 8bb577669..2afeec73e 100644
--- a/signer/core/abihelper_test.go
+++ b/signer/core/abihelper_test.go
@@ -100,16 +100,6 @@ func TestNewUnpacker(t *testing.T) {
}
-/*
-func TestReflect(t *testing.T) {
- a := big.NewInt(0)
- b := new(big.Int).SetBytes([]byte{0x00})
- if !reflect.DeepEqual(a, b) {
- t.Fatalf("Nope, %v != %v", a, b)
- }
-}
-*/
-
func TestCalldataDecoding(t *testing.T) {
// send(uint256) : a52c101e
@@ -123,7 +113,7 @@ func TestCalldataDecoding(t *testing.T) {
{"type":"function","name":"sam","inputs":[{"name":"a","type":"bytes"},{"name":"a","type":"bool"},{"name":"a","type":"uint256[]"}]}
]`
//Expected failures
- for _, hexdata := range []string{
+ for i, hexdata := range []string{
"a52c101e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000042",
"a52c101e000000000000000000000000000000000000000000000000000000000000001200",
"a52c101e00000000000000000000000000000000000000000000000000000000000000",
@@ -145,12 +135,11 @@ func TestCalldataDecoding(t *testing.T) {
} {
_, err := parseCallData(common.Hex2Bytes(hexdata), jsondata)
if err == nil {
- t.Errorf("Expected decoding to fail: %s", hexdata)
+ t.Errorf("test %d: expected decoding to fail: %s", i, hexdata)
}
}
-
//Expected success
- for _, hexdata := range []string{
+ for i, hexdata := range []string{
// From https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
"a5643bf20000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000464617665000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003",
"a52c101e0000000000000000000000000000000000000000000000000000000000000012",
@@ -169,7 +158,7 @@ func TestCalldataDecoding(t *testing.T) {
} {
_, err := parseCallData(common.Hex2Bytes(hexdata), jsondata)
if err != nil {
- t.Errorf("Unexpected failure on input %s:\n %v (%d bytes) ", hexdata, err, len(common.Hex2Bytes(hexdata)))
+ t.Errorf("test %d: unexpected failure on input %s:\n %v (%d bytes) ", i, hexdata, err, len(common.Hex2Bytes(hexdata)))
}
}
}
@@ -245,3 +234,18 @@ func TestCustomABI(t *testing.T) {
t.Fatalf("Save failed: should find a match for abi signature after loading from disk")
}
}
+
+func TestMaliciousAbiStrings(t *testing.T) {
+ tests := []string{
+ "func(uint256,uint256,[]uint256)",
+ "func(uint256,uint256,uint256,)",
+ "func(,uint256,uint256,uint256)",
+ }
+ data := common.Hex2Bytes("4401a6e40000000000000000000000000000000000000000000000000000000000000012")
+ for i, tt := range tests {
+ _, err := testSelector(tt, data)
+ if err == nil {
+ t.Errorf("test %d: expected error for selector '%v'", i, tt)
+ }
+ }
+}