(t *testing.T)
| 231 | } |
| 232 | |
| 233 | func TestJSONRPCService(t *testing.T) { |
| 234 | t.Logf("testdb: %s", testdb) |
| 235 | mockData(t) |
| 236 | defer os.Remove(testdb + "-shm") |
| 237 | defer os.Remove(testdb + "-wal") |
| 238 | defer os.Remove(testdb) |
| 239 | |
| 240 | // log.SetLevel(log.DebugLevel) |
| 241 | go api.Serve(":8546", testdb) |
| 242 | defer api.StopService() |
| 243 | |
| 244 | var ( |
| 245 | addr = "ws://localhost:8546" |
| 246 | conveyBlock = func(convey C, item *models.Block, cp []interface{}) { |
| 247 | if cp == nil { |
| 248 | convey.So(item, ShouldBeNil) |
| 249 | return |
| 250 | } |
| 251 | convey.So(item.Height, ShouldEqual, cp[0].(int)) |
| 252 | convey.So(item.Hash, ShouldEqual, cp[1].(string)) |
| 253 | convey.So(item.Timestamp, ShouldEqual, cp[2].(int)) |
| 254 | convey.So(item.TimestampHuman.UnixNano(), ShouldEqual, item.Timestamp) |
| 255 | convey.So(item.Version, ShouldEqual, cp[3].(int)) |
| 256 | convey.So(item.Producer, ShouldEqual, cp[4].(string)) |
| 257 | convey.So(item.MerkleRoot, ShouldEqual, cp[5].(string)) |
| 258 | convey.So(item.Parent, ShouldEqual, cp[6].(string)) |
| 259 | convey.So(item.TxCount, ShouldEqual, cp[7].(int)) |
| 260 | } |
| 261 | |
| 262 | conveyTransaction = func(convey C, item *models.Transaction, cp []interface{}) { |
| 263 | if cp == nil { |
| 264 | convey.So(item, ShouldBeNil) |
| 265 | return |
| 266 | } |
| 267 | |
| 268 | convey.So(item.BlockHeight, ShouldEqual, cp[0].(int)) |
| 269 | convey.So(item.TxIndex, ShouldEqual, cp[1].(int)) |
| 270 | convey.So(item.Hash, ShouldEqual, cp[2].(string)) |
| 271 | convey.So(item.BlockHash, ShouldEqual, cp[3].(string)) |
| 272 | convey.So(item.Timestamp, ShouldEqual, cp[4].(int)) |
| 273 | convey.So(item.TimestampHuman.UnixNano(), ShouldEqual, item.Timestamp) |
| 274 | convey.So(item.TxType, ShouldEqual, cp[5].(int)) |
| 275 | convey.So(item.Address, ShouldEqual, cp[6].(string)) |
| 276 | convey.So(item.Raw, ShouldEqual, cp[7].(string)) |
| 277 | } |
| 278 | ) |
| 279 | |
| 280 | Convey("API not found", t, func() { |
| 281 | rpc, err := setupWebsocketClient(addr) |
| 282 | if err != nil { |
| 283 | t.Errorf("failed to connect to wsapi server: %v", err) |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | Convey("call method should fail if method not found", func() { |
| 288 | var result interface{} |
| 289 | err := rpc.Call(context.Background(), "method_NotFound", nil, &result) |
| 290 | So(err, ShouldNotBeNil) |
nothing calls this directly
no test coverage detected