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.

87 lines
2.3 KiB

  1. package state
  2. import (
  3. "bytes"
  4. "encoding/hex"
  5. "fmt"
  6. "testing"
  7. tdb "github.com/tendermint/tendermint/db"
  8. ptypes "github.com/tendermint/tendermint/permission/types"
  9. . "github.com/tendermint/tendermint/state/types"
  10. )
  11. var chain_id = "lone_ranger"
  12. var addr1, _ = hex.DecodeString("964B1493BBE3312278B7DEB94C39149F7899A345")
  13. var send1, name1, call1 = 1, 1, 0
  14. var perms, setbit = 66, 70
  15. var accName = "me"
  16. var roles1 = []string{"master", "universal-ruler"}
  17. var amt1 int64 = 1000000
  18. var g1 = fmt.Sprintf(`
  19. {
  20. "chain_id":"%s",
  21. "accounts": [
  22. {
  23. "address": "%X",
  24. "amount": %d,
  25. "name": "%s",
  26. "permissions": {
  27. "base": {
  28. "perms": %d,
  29. "set": %d
  30. },
  31. "roles": [
  32. "%s",
  33. "%s"
  34. ]
  35. }
  36. }
  37. ],
  38. "validators": [
  39. {
  40. "amount": 100000000,
  41. "pub_key": [1,"F6C79CF0CB9D66B677988BCB9B8EADD9A091CD465A60542A8AB85476256DBA92"],
  42. "unbond_to": [
  43. {
  44. "address": "964B1493BBE3312278B7DEB94C39149F7899A345",
  45. "amount": 10000000
  46. }
  47. ]
  48. }
  49. ]
  50. }
  51. `, chain_id, addr1, amt1, accName, perms, setbit, roles1[0], roles1[1])
  52. func TestGenesisReadable(t *testing.T) {
  53. genDoc := GenesisDocFromJSON([]byte(g1))
  54. if genDoc.ChainID != chain_id {
  55. t.Fatalf("Incorrect chain id. Got %d, expected %d\n", genDoc.ChainID, chain_id)
  56. }
  57. acc := genDoc.Accounts[0]
  58. if bytes.Compare(acc.Address, addr1) != 0 {
  59. t.Fatalf("Incorrect address for account. Got %X, expected %X\n", acc.Address, addr1)
  60. }
  61. if acc.Amount != amt1 {
  62. t.Fatalf("Incorrect amount for account. Got %d, expected %d\n", acc.Amount, amt1)
  63. }
  64. if acc.Name != accName {
  65. t.Fatalf("Incorrect name for account. Got %s, expected %s\n", acc.Name, accName)
  66. }
  67. perm, _ := acc.Permissions.Base.Get(ptypes.Send)
  68. if perm != (send1 > 0) {
  69. t.Fatalf("Incorrect permission for send. Got %v, expected %v\n", perm, send1 > 0)
  70. }
  71. }
  72. func TestGenesisMakeState(t *testing.T) {
  73. genDoc := GenesisDocFromJSON([]byte(g1))
  74. db := tdb.NewMemDB()
  75. st := MakeGenesisState(db, genDoc)
  76. acc := st.GetAccount(addr1)
  77. v, _ := acc.Permissions.Base.Get(ptypes.Send)
  78. if v != (send1 > 0) {
  79. t.Fatalf("Incorrect permission for send. Got %v, expected %v\n", v, send1 > 0)
  80. }
  81. }