api_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package rpc
  2. import (
  3. "encoding/json"
  4. // "sync"
  5. "testing"
  6. // "time"
  7. )
  8. func TestWeb3Sha3(t *testing.T) {
  9. jsonstr := `{"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":64}`
  10. expected := "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"
  11. api := &EthereumApi{}
  12. var req RpcRequest
  13. json.Unmarshal([]byte(jsonstr), &req)
  14. var response interface{}
  15. _ = api.GetRequestReply(&req, &response)
  16. if response.(string) != expected {
  17. t.Errorf("Expected %s got %s", expected, response)
  18. }
  19. }
  20. // func TestFilterClose(t *testing.T) {
  21. // t.Skip()
  22. // api := &EthereumApi{
  23. // logs: make(map[int]*logFilter),
  24. // messages: make(map[int]*whisperFilter),
  25. // quit: make(chan struct{}),
  26. // }
  27. // filterTickerTime = 1
  28. // api.logs[0] = &logFilter{}
  29. // api.messages[0] = &whisperFilter{}
  30. // var wg sync.WaitGroup
  31. // wg.Add(1)
  32. // go api.start()
  33. // go func() {
  34. // select {
  35. // case <-time.After(500 * time.Millisecond):
  36. // api.stop()
  37. // wg.Done()
  38. // }
  39. // }()
  40. // wg.Wait()
  41. // if len(api.logs) != 0 {
  42. // t.Error("expected logs to be empty")
  43. // }
  44. // if len(api.messages) != 0 {
  45. // t.Error("expected messages to be empty")
  46. // }
  47. // }