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.

45 lines
971 B

  1. package common
  2. import (
  3. "database/sql"
  4. "database/sql/driver"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestTxIDScannerValue(t *testing.T) {
  9. txid0 := &TxID{}
  10. txid1 := &TxID{}
  11. txid0B := [12]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
  12. txid1B := [12]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  13. copy(txid0[:], txid0B[:])
  14. copy(txid1[:], txid1B[:])
  15. var value driver.Valuer
  16. var scan sql.Scanner
  17. value = txid0
  18. scan = txid1
  19. fromDB, err := value.Value()
  20. assert.NoError(t, err)
  21. assert.NoError(t, scan.Scan(fromDB))
  22. assert.Equal(t, value, scan)
  23. }
  24. func TestTxIDMarshalers(t *testing.T) {
  25. h := []byte("0x00000000000001e240004700")
  26. var txid TxID
  27. err := txid.UnmarshalText(h)
  28. assert.Nil(t, err)
  29. assert.Equal(t, h, []byte(txid.String()))
  30. h2, err := txid.MarshalText()
  31. assert.Nil(t, err)
  32. assert.Equal(t, h, h2)
  33. var txid2 TxID
  34. err = txid2.UnmarshalText(h2)
  35. assert.Nil(t, err)
  36. assert.Equal(t, h2, []byte(txid2.String()))
  37. assert.Equal(t, h, h2)
  38. }