From 8096613fdaa991c77602d4be766a8a66cec06c72 Mon Sep 17 00:00:00 2001 From: JFO Date: Wed, 22 May 2019 17:45:07 +0200 Subject: [PATCH] eventByID: returning nil instead of error when event not found. Updating tests --- accounts/abi/abi.go | 6 +++--- accounts/abi/abi_test.go | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index e92970556a..8c7f880571 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -150,11 +150,11 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) { // EventById looks up a event by the topic hash // returns nil if none found -func (abi *ABI) EventById(topic common.Hash) (*Event, error) { +func (abi *ABI) EventById(topic common.Hash) *Event { for _, event := range abi.Events { if event.Id() == topic { - return &event, nil + return &event } } - return nil, fmt.Errorf("no event with topic: %#x", topic.Hex()) + return nil } diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index cbd7940380..15c85dfa0f 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -757,23 +757,24 @@ func TestABI_EventById(t *testing.T) { abi, err := JSON(strings.NewReader(abiJSON)) if err != nil { - t.Fatal(err) + t.Error(err) } topic := "received(address,uint256,bytes)" topicID := crypto.Keccak256Hash([]byte(topic)) - event, err := abi.EventById(topicID) - if err != nil { - t.Fatalf("Failed to look up ABI event: %v", err) + event := abi.EventById(topicID) + if event == nil { + t.Errorf("we should find a event for topic %s", topicID.Hex()) } if event.Id() != topicID { - t.Errorf("topic %v (id %v) not 'findable' by id in ABI", topic, topicID) + t.Errorf("event id %s does not match topic %s", event.Id().Hex(), topicID.Hex()) } unknowntopicID := crypto.Keccak256Hash([]byte("unknownEvent")) - if _, err := abi.EventById(unknowntopicID); err == nil { - t.Errorf("Expected error, no matching event id") + unknownEvent := abi.EventById(unknowntopicID) + if unknownEvent != nil { + t.Errorf("we should not find any event for topic %s", unknowntopicID.Hex()) } }