You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.5 KiB

  1. package types
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestResultQuery(t *testing.T) {
  7. orig := &ResponseQuery{
  8. Code: CodeType_OK,
  9. Index: 0,
  10. Key: []byte("hello"),
  11. Value: []byte("world"),
  12. Height: 1,
  13. }
  14. res := orig.Result()
  15. assert.False(t, res.IsErr())
  16. orig = &ResponseQuery{
  17. Code: CodeType_BadNonce,
  18. Index: 0,
  19. Key: []byte("hello"),
  20. Value: []byte("world"),
  21. Height: 1,
  22. Log: "bad",
  23. }
  24. res = orig.Result()
  25. assert.True(t, res.IsErr())
  26. assert.Equal(t, "Error bad nonce (3): bad", res.Error())
  27. }
  28. func TestResponseDeliverTx(t *testing.T) {
  29. res := ResponseDeliverTx{
  30. Code: CodeType_OK,
  31. Data: []byte("Victor Mancha"),
  32. }
  33. assert.False(t, res.IsErr())
  34. res = ResponseDeliverTx{
  35. Code: CodeType_InternalError,
  36. Log: "bad",
  37. }
  38. assert.True(t, res.IsErr())
  39. assert.Equal(t, "Internal error (1): bad", res.Error())
  40. }
  41. func TestResponseCheckTx(t *testing.T) {
  42. res := ResponseCheckTx{
  43. Code: CodeType_OK,
  44. Data: []byte("Talos"),
  45. }
  46. assert.False(t, res.IsErr())
  47. res = ResponseCheckTx{
  48. Code: CodeType_InternalError,
  49. Log: "bad",
  50. }
  51. assert.True(t, res.IsErr())
  52. assert.Equal(t, "Internal error (1): bad", res.Error())
  53. }
  54. func TestResponseCommit(t *testing.T) {
  55. res := ResponseCommit{
  56. Code: CodeType_OK,
  57. Data: []byte("Old Lace"),
  58. }
  59. assert.False(t, res.IsErr())
  60. res = ResponseCommit{
  61. Code: CodeType_Unauthorized,
  62. Log: "bad",
  63. }
  64. assert.True(t, res.IsErr())
  65. assert.Equal(t, "Unauthorized (4): bad", res.Error())
  66. }