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.

69 lines
1.7 KiB

  1. package types
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. abci "github.com/tendermint/tendermint/abci/types"
  6. crypto "github.com/tendermint/tendermint/crypto"
  7. )
  8. func TestABCIPubKey(t *testing.T) {
  9. pkEd := crypto.GenPrivKeyEd25519().PubKey()
  10. pkSecp := crypto.GenPrivKeySecp256k1().PubKey()
  11. testABCIPubKey(t, pkEd, ABCIPubKeyTypeEd25519)
  12. testABCIPubKey(t, pkSecp, ABCIPubKeyTypeSecp256k1)
  13. }
  14. func testABCIPubKey(t *testing.T, pk crypto.PubKey, typeStr string) {
  15. abciPubKey := TM2PB.PubKey(pk)
  16. pk2, err := PB2TM.PubKey(abciPubKey)
  17. assert.Nil(t, err)
  18. assert.Equal(t, pk, pk2)
  19. }
  20. func TestABCIValidators(t *testing.T) {
  21. pkEd := crypto.GenPrivKeyEd25519().PubKey()
  22. // correct validator
  23. tmValExpected := &Validator{
  24. Address: pkEd.Address(),
  25. PubKey: pkEd,
  26. VotingPower: 10,
  27. }
  28. tmVal := &Validator{
  29. Address: pkEd.Address(),
  30. PubKey: pkEd,
  31. VotingPower: 10,
  32. }
  33. abciVal := TM2PB.Validator(tmVal)
  34. tmVals, err := PB2TM.Validators([]abci.Validator{abciVal})
  35. assert.Nil(t, err)
  36. assert.Equal(t, tmValExpected, tmVals[0])
  37. // val with address
  38. tmVal.Address = pkEd.Address()
  39. abciVal = TM2PB.Validator(tmVal)
  40. tmVals, err = PB2TM.Validators([]abci.Validator{abciVal})
  41. assert.Nil(t, err)
  42. assert.Equal(t, tmValExpected, tmVals[0])
  43. // val with incorrect address
  44. abciVal = TM2PB.Validator(tmVal)
  45. abciVal.Address = []byte("incorrect!")
  46. tmVals, err = PB2TM.Validators([]abci.Validator{abciVal})
  47. assert.NotNil(t, err)
  48. assert.Nil(t, tmVals)
  49. }
  50. func TestABCIConsensusParams(t *testing.T) {
  51. cp := DefaultConsensusParams()
  52. cp.EvidenceParams.MaxAge = 0 // TODO add this to ABCI
  53. abciCP := TM2PB.ConsensusParams(cp)
  54. cp2 := PB2TM.ConsensusParams(abciCP)
  55. assert.Equal(t, *cp, cp2)
  56. }