event_test.go 999 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package abi
  2. import (
  3. "strings"
  4. "testing"
  5. "github.com/ethereum/go-ethereum/common"
  6. "github.com/ethereum/go-ethereum/crypto"
  7. )
  8. func TestEventId(t *testing.T) {
  9. var table = []struct {
  10. definition string
  11. expectations map[string]common.Hash
  12. }{
  13. {
  14. definition: `[
  15. { "type" : "event", "name" : "balance", "inputs": [{ "name" : "in", "type": "uint" }] },
  16. { "type" : "event", "name" : "check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
  17. ]`,
  18. expectations: map[string]common.Hash{
  19. "balance": crypto.Keccak256Hash([]byte("balance(uint256)")),
  20. "check": crypto.Keccak256Hash([]byte("check(address,uint256)")),
  21. },
  22. },
  23. }
  24. for _, test := range table {
  25. abi, err := JSON(strings.NewReader(test.definition))
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. for name, event := range abi.Events {
  30. if event.Id() != test.expectations[name] {
  31. t.Errorf("expected id to be %x, got %x", test.expectations[name], event.Id())
  32. }
  33. }
  34. }
  35. }