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.

67 lines
1.7 KiB

  1. package types
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. abci "github.com/tendermint/tendermint/abci/types"
  7. "github.com/tendermint/tendermint/crypto"
  8. "github.com/tendermint/tendermint/crypto/ed25519"
  9. cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
  10. )
  11. func TestABCIPubKey(t *testing.T) {
  12. pkEd := ed25519.GenPrivKey().PubKey()
  13. err := testABCIPubKey(t, pkEd, ABCIPubKeyTypeEd25519)
  14. assert.NoError(t, err)
  15. }
  16. func testABCIPubKey(t *testing.T, pk crypto.PubKey, typeStr string) error {
  17. abciPubKey, err := cryptoenc.PubKeyToProto(pk)
  18. require.NoError(t, err)
  19. pk2, err := cryptoenc.PubKeyFromProto(abciPubKey)
  20. require.NoError(t, err)
  21. require.Equal(t, pk, pk2)
  22. return nil
  23. }
  24. func TestABCIValidators(t *testing.T) {
  25. pkEd := ed25519.GenPrivKey().PubKey()
  26. // correct validator
  27. tmValExpected := NewValidator(pkEd, 10)
  28. tmVal := NewValidator(pkEd, 10)
  29. abciVal := TM2PB.ValidatorUpdate(tmVal)
  30. tmVals, err := PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{abciVal})
  31. assert.Nil(t, err)
  32. assert.Equal(t, tmValExpected, tmVals[0])
  33. abciVals := TM2PB.ValidatorUpdates(NewValidatorSet(tmVals))
  34. assert.Equal(t, []abci.ValidatorUpdate{abciVal}, abciVals)
  35. // val with address
  36. tmVal.Address = pkEd.Address()
  37. abciVal = TM2PB.ValidatorUpdate(tmVal)
  38. tmVals, err = PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{abciVal})
  39. assert.Nil(t, err)
  40. assert.Equal(t, tmValExpected, tmVals[0])
  41. }
  42. func TestABCIValidatorWithoutPubKey(t *testing.T) {
  43. pkEd := ed25519.GenPrivKey().PubKey()
  44. abciVal := TM2PB.Validator(NewValidator(pkEd, 10))
  45. // pubkey must be nil
  46. tmValExpected := abci.Validator{
  47. Address: pkEd.Address(),
  48. Power: 10,
  49. }
  50. assert.Equal(t, tmValExpected, abciVal)
  51. }