api_test.go 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package api
  2. import (
  3. "testing"
  4. "github.com/ethereum/go-ethereum/rpc/codec"
  5. )
  6. func TestParseApiString(t *testing.T) {
  7. apis, err := ParseApiString("", codec.JSON, nil, nil)
  8. if err == nil {
  9. t.Errorf("Expected an err from parsing empty API string but got nil")
  10. }
  11. if len(apis) != 0 {
  12. t.Errorf("Expected 0 apis from empty API string")
  13. }
  14. apis, err = ParseApiString("eth", codec.JSON, nil, nil)
  15. if err != nil {
  16. t.Errorf("Expected nil err from parsing empty API string but got %v", err)
  17. }
  18. if len(apis) != 1 {
  19. t.Errorf("Expected 1 apis but got %d - %v", apis, apis)
  20. }
  21. apis, err = ParseApiString("eth,eth", codec.JSON, nil, nil)
  22. if err != nil {
  23. t.Errorf("Expected nil err from parsing empty API string but got \"%v\"", err)
  24. }
  25. if len(apis) != 2 {
  26. t.Errorf("Expected 2 apis but got %d - %v", apis, apis)
  27. }
  28. apis, err = ParseApiString("eth,invalid", codec.JSON, nil, nil)
  29. if err == nil {
  30. t.Errorf("Expected an err but got no err")
  31. }
  32. }