mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eventByID: returning nil instead of error when event not found. Updating tests
This commit is contained in:
parent
9eff6b80bb
commit
8096613fda
2 changed files with 11 additions and 10 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue