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.

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