github.com/KiraCore/sekai@v0.3.43/x/gov/genesis_test.go (about) 1 package gov_test 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "testing" 7 "time" 8 9 simapp "github.com/KiraCore/sekai/app" 10 kiratypes "github.com/KiraCore/sekai/types" 11 "github.com/KiraCore/sekai/x/gov" 12 "github.com/KiraCore/sekai/x/gov/keeper" 13 "github.com/KiraCore/sekai/x/gov/types" 14 dbm "github.com/cometbft/cometbft-db" 15 "github.com/cometbft/cometbft/libs/log" 16 tmproto "github.com/cometbft/cometbft/proto/tendermint/types" 17 "github.com/cosmos/cosmos-sdk/store" 18 storetypes "github.com/cosmos/cosmos-sdk/store/types" 19 sdk "github.com/cosmos/cosmos-sdk/types" 20 "github.com/stretchr/testify/require" 21 ) 22 23 // test for gov export / init genesis process 24 func TestSimappExportGenesis(t *testing.T) { 25 app := simapp.Setup(false) 26 ctx := app.NewContext(false, tmproto.Header{}) 27 28 genesis := gov.ExportGenesis(ctx, app.CustomGovKeeper) 29 bz, err := app.AppCodec().MarshalJSON(genesis) 30 require.NoError(t, err) 31 buffer := new(bytes.Buffer) 32 err = json.Compact(buffer, []byte(`{ 33 "default_denom": "ukex", 34 "bech32_prefix": "kira", 35 "starting_proposal_id": "1", 36 "next_role_id": "3", 37 "roles": [ 38 { 39 "id": 1, 40 "sid": "sudo", 41 "description": "Sudo role" 42 }, 43 { 44 "id": 2, 45 "sid": "validator", 46 "description": "Validator role" 47 } 48 ], 49 "role_permissions": { 50 "1": { 51 "blacklist": [], 52 "whitelist": [ 53 1, 54 2, 55 3, 56 6, 57 8, 58 9, 59 12, 60 13, 61 10, 62 11, 63 14, 64 15, 65 18, 66 19, 67 20, 68 21, 69 22, 70 23, 71 31, 72 32, 73 24, 74 25, 75 16, 76 17, 77 4, 78 5, 79 26, 80 27, 81 28, 82 29, 83 30, 84 33, 85 34, 86 35, 87 36, 88 37, 89 38, 90 39, 91 40, 92 41, 93 42, 94 43, 95 44, 96 45, 97 46, 98 47, 99 48, 100 49, 101 50, 102 51, 103 52, 104 53, 105 54, 106 55, 107 56, 108 57, 109 58, 110 59, 111 60, 112 61, 113 62, 114 63, 115 64, 116 65, 117 66 118 ] 119 }, 120 "2": { 121 "blacklist": [], 122 "whitelist": [ 123 2 124 ] 125 } 126 }, 127 "network_actors": [], 128 "network_properties": { 129 "min_tx_fee": "100", 130 "max_tx_fee": "1000000", 131 "vote_quorum": "33", 132 "minimum_proposal_end_time": "300", 133 "proposal_enactment_time": "300", 134 "min_proposal_end_blocks": "2", 135 "min_proposal_enactment_blocks": "1", 136 "enable_foreign_fee_payments": true, 137 "mischance_rank_decrease_amount": "10", 138 "max_mischance": "110", 139 "mischance_confidence": "10", 140 "inactive_rank_decrease_percent": "0.500000000000000000", 141 "min_validators": "1", 142 "poor_network_max_bank_send": "1000000", 143 "unjail_max_time": "600", 144 "enable_token_whitelist": false, 145 "enable_token_blacklist": true, 146 "min_identity_approval_tip": "200", 147 "unique_identity_keys": "moniker,username", 148 "ubi_hardcap": "6000000", 149 "validators_fee_share": "0.500000000000000000", 150 "inflation_rate": "0.180000000000000000", 151 "inflation_period": "31557600", 152 "unstaking_period": "2629800", 153 "max_delegators": "100", 154 "min_delegation_pushout": "10", 155 "slashing_period": "3600", 156 "max_jailed_percentage": "0.250000000000000000", 157 "max_slashing_percentage": "0.010000000000000000", 158 "min_custody_reward": "200", 159 "max_custody_buffer_size": "10", 160 "max_custody_tx_size": "8192", 161 "abstention_rank_decrease_amount": "1", 162 "max_abstention": "2", 163 "min_collective_bond": "100000", 164 "min_collective_bonding_time": "86400", 165 "max_collective_outputs": "10", 166 "min_collective_claim_period": "14400", 167 "validator_recovery_bond": "300000", 168 "max_annual_inflation": "0.350000000000000000", 169 "max_proposal_title_size": "128", 170 "max_proposal_description_size": "1024", 171 "max_proposal_poll_option_size": "64", 172 "max_proposal_poll_option_count": "128", 173 "max_proposal_reference_size": "512", 174 "max_proposal_checksum_size": "128", 175 "min_dapp_bond": "1000000", 176 "max_dapp_bond": "10000000", 177 "dapp_liquidation_threshold": "0", 178 "dapp_liquidation_period": "0", 179 "dapp_bond_duration": "604800", 180 "dapp_verifier_bond": "0.001000000000000000", 181 "dapp_auto_denounce_time": "60", 182 "dapp_mischance_rank_decrease_amount": "1", 183 "dapp_max_mischance": "10", 184 "dapp_inactive_rank_decrease_percent": "10", 185 "dapp_pool_slippage_default": "0.100000000000000000", 186 "minting_ft_fee": "100000000000000", 187 "minting_nft_fee": "100000000000000", 188 "veto_threshold": "33.400000000000000000", 189 "autocompound_interval_num_blocks": "17280" 190 }, 191 "execution_fees": [ 192 { 193 "transaction_type": "activate", 194 "execution_fee": "100", 195 "failure_fee": "1000", 196 "timeout": "10", 197 "default_parameters": "0" 198 }, 199 { 200 "transaction_type": "claim-councilor", 201 "execution_fee": "100", 202 "failure_fee": "1", 203 "timeout": "10", 204 "default_parameters": "0" 205 }, 206 { 207 "transaction_type": "claim-proposal-type-x", 208 "execution_fee": "100", 209 "failure_fee": "1", 210 "timeout": "10", 211 "default_parameters": "0" 212 }, 213 { 214 "transaction_type": "claim-validator", 215 "execution_fee": "100", 216 "failure_fee": "1", 217 "timeout": "10", 218 "default_parameters": "0" 219 }, 220 { 221 "transaction_type": "pause", 222 "execution_fee": "100", 223 "failure_fee": "100", 224 "timeout": "10", 225 "default_parameters": "0" 226 }, 227 { 228 "transaction_type": "submit-proposal-type-x", 229 "execution_fee": "10", 230 "failure_fee": "1", 231 "timeout": "10", 232 "default_parameters": "0" 233 }, 234 { 235 "transaction_type": "unpause", 236 "execution_fee": "100", 237 "failure_fee": "100", 238 "timeout": "10", 239 "default_parameters": "0" 240 }, 241 { 242 "transaction_type": "upsert-token-alias", 243 "execution_fee": "100", 244 "failure_fee": "1", 245 "timeout": "10", 246 "default_parameters": "0" 247 }, 248 { 249 "transaction_type": "veto-proposal-type-x", 250 "execution_fee": "100", 251 "failure_fee": "1", 252 "timeout": "10", 253 "default_parameters": "0" 254 }, 255 { 256 "transaction_type": "vote-proposal-type-x", 257 "execution_fee": "100", 258 "failure_fee": "1", 259 "timeout": "10", 260 "default_parameters": "0" 261 } 262 ], 263 "poor_network_messages": { 264 "messages": [ 265 "submit-proposal", 266 "set-network-properties", 267 "vote-proposal", 268 "claim-councilor", 269 "whitelist-permissions", 270 "blacklist-permissions", 271 "create-role", 272 "assign-role", 273 "unassign-role", 274 "whitelist-role-permission", 275 "blacklist-role-permission", 276 "remove-whitelist-role-permission", 277 "remove-blacklist-role-permission", 278 "claim-validator", 279 "activate", 280 "pause", 281 "unpause", 282 "register-identity-records", 283 "edit-identity-record", 284 "request-identity-records-verify", 285 "handle-identity-records-verify-request", 286 "cancel-identity-records-verify-request" 287 ] 288 }, 289 "proposals": [], 290 "votes": [], 291 "data_registry": {}, 292 "identity_records": [], 293 "last_identity_record_id": "0", 294 "id_records_verify_requests": [], 295 "last_id_record_verify_request_id": "0", 296 "proposal_durations": {} 297 }`)) 298 require.NoError(t, err) 299 require.Equal(t, string(bz), buffer.String()) 300 } 301 302 func TestExportInitGenesis(t *testing.T) { 303 // Initialize store keys 304 keyGovernance := sdk.NewKVStoreKey(types.ModuleName) 305 306 // Initialize memory database and mount stores on it 307 db := dbm.NewMemDB() 308 ms := store.NewCommitMultiStore(db) 309 ms.MountStoreWithDB(keyGovernance, storetypes.StoreTypeIAVL, nil) 310 ms.LoadLatestVersion() 311 312 ctx := sdk.NewContext(ms, tmproto.Header{ 313 Height: 1, 314 Time: time.Date(2020, time.March, 1, 1, 0, 0, 0, time.UTC), 315 }, false, log.TestingLogger()) 316 317 k := keeper.NewKeeper(keyGovernance, simapp.MakeEncodingConfig().Marshaler, nil) 318 319 genState := types.GenesisState{ 320 DefaultDenom: "ukex", 321 Bech32Prefix: "kira", 322 NextRoleId: 3, 323 Roles: []types.Role{ 324 { 325 Id: uint32(types.RoleSudo), 326 Sid: "sudo", 327 Description: "Sudo role", 328 }, 329 { 330 Id: uint32(types.RoleValidator), 331 Sid: "validator", 332 Description: "Validator role", 333 }, 334 }, 335 RolePermissions: map[uint64]*types.Permissions{ 336 uint64(types.RoleSudo): types.NewPermissions([]types.PermValue{ 337 types.PermSetPermissions, 338 types.PermClaimValidator, 339 types.PermClaimCouncilor, 340 types.PermUpsertTokenAlias, 341 }, nil), 342 }, 343 StartingProposalId: 1, 344 NetworkProperties: &types.NetworkProperties{ 345 MinTxFee: 100, 346 MaxTxFee: 1000000, 347 VoteQuorum: 33, 348 MinimumProposalEndTime: 300, // 300 seconds / 5 mins 349 ProposalEnactmentTime: 300, // 300 seconds / 5 mins 350 MinProposalEndBlocks: 2, 351 MinProposalEnactmentBlocks: 1, 352 MischanceRankDecreaseAmount: 1, 353 MaxMischance: 1, 354 InactiveRankDecreasePercent: sdk.NewDecWithPrec(2, 2), 355 MinValidators: 1, 356 PoorNetworkMaxBankSend: 1, 357 EnableForeignFeePayments: true, 358 MinIdentityApprovalTip: 200, 359 UniqueIdentityKeys: "moniker,username", 360 UbiHardcap: 6000_000, 361 ValidatorsFeeShare: sdk.NewDecWithPrec(50, 2), // 50% 362 InflationRate: sdk.NewDecWithPrec(18, 2), // 18% 363 InflationPeriod: 31557600, // 1 year 364 UnstakingPeriod: 2629800, // 1 month 365 MaxDelegators: 100, 366 MinDelegationPushout: 10, 367 SlashingPeriod: 3600, 368 MaxJailedPercentage: sdk.NewDecWithPrec(25, 2), 369 MaxSlashingPercentage: sdk.NewDecWithPrec(1, 2), 370 MinCustodyReward: 200, 371 MaxCustodyBufferSize: 10, 372 MaxCustodyTxSize: 8192, 373 AbstentionRankDecreaseAmount: 1, 374 MaxAbstention: 2, 375 MinCollectiveBond: 100_000, // in KEX 376 MinCollectiveBondingTime: 86400, // in seconds 377 MaxCollectiveOutputs: 10, 378 MinCollectiveClaimPeriod: 14400, // 4hrs 379 ValidatorRecoveryBond: 300000, // 300k KEX 380 MaxAnnualInflation: sdk.NewDecWithPrec(35, 2), // 35% 381 MaxProposalTitleSize: 128, 382 MaxProposalDescriptionSize: 1024, 383 MaxProposalPollOptionSize: 64, 384 MaxProposalPollOptionCount: 128, 385 MaxProposalReferenceSize: 512, 386 MaxProposalChecksumSize: 128, 387 MinDappBond: 1000000, 388 MaxDappBond: 10000000, 389 DappBondDuration: 604800, 390 DappVerifierBond: sdk.NewDecWithPrec(1, 3), //0.1% 391 DappAutoDenounceTime: 60, // 60s 392 DappMischanceRankDecreaseAmount: 1, 393 DappMaxMischance: 10, 394 DappInactiveRankDecreasePercent: 10, 395 DappPoolSlippageDefault: sdk.NewDecWithPrec(1, 1), // 10% 396 MintingFtFee: 100_000_000_000_000, 397 MintingNftFee: 100_000_000_000_000, 398 VetoThreshold: sdk.NewDecWithPrec(3340, 2), // 33.40% 399 AutocompoundIntervalNumBlocks: 17280, 400 }, 401 ExecutionFees: []types.ExecutionFee{ 402 { 403 TransactionType: "claim-validator-seat", 404 ExecutionFee: 10, 405 FailureFee: 1, 406 Timeout: 10, 407 DefaultParameters: 0, 408 }, 409 }, 410 PoorNetworkMessages: &types.AllowedMessages{ 411 Messages: []string{ 412 kiratypes.MsgTypeSetNetworkProperties, 413 }, 414 }, 415 } 416 err := gov.InitGenesis(ctx, k, genState) 417 require.NoError(t, err) 418 419 genesis := gov.ExportGenesis(ctx, k) 420 bz, err := simapp.MakeEncodingConfig().Marshaler.MarshalJSON(genesis) 421 require.NoError(t, err) 422 buffer := new(bytes.Buffer) 423 err = json.Compact(buffer, []byte(` { 424 "default_denom": "ukex", 425 "bech32_prefix": "kira", 426 "starting_proposal_id": "1", 427 "next_role_id": "3", 428 "roles": [ 429 { 430 "id": 1, 431 "sid": "sudo", 432 "description": "Sudo role" 433 }, 434 { 435 "id": 2, 436 "sid": "validator", 437 "description": "Validator role" 438 } 439 ], 440 "role_permissions": { 441 "1": { 442 "blacklist": [], 443 "whitelist": [ 444 1, 445 2, 446 3, 447 6 448 ] 449 }, 450 "2": { 451 "blacklist": [], 452 "whitelist": [] 453 } 454 }, 455 "network_actors": [], 456 "network_properties": { 457 "min_tx_fee": "100", 458 "max_tx_fee": "1000000", 459 "vote_quorum": "33", 460 "minimum_proposal_end_time": "300", 461 "proposal_enactment_time": "300", 462 "min_proposal_end_blocks": "2", 463 "min_proposal_enactment_blocks": "1", 464 "enable_foreign_fee_payments": true, 465 "mischance_rank_decrease_amount": "1", 466 "max_mischance": "1", 467 "mischance_confidence": "0", 468 "inactive_rank_decrease_percent": "0.020000000000000000", 469 "min_validators": "1", 470 "poor_network_max_bank_send": "1", 471 "unjail_max_time": "0", 472 "enable_token_whitelist": false, 473 "enable_token_blacklist": false, 474 "min_identity_approval_tip": "200", 475 "unique_identity_keys": "moniker,username", 476 "ubi_hardcap": "6000000", 477 "validators_fee_share": "0.500000000000000000", 478 "inflation_rate": "0.180000000000000000", 479 "inflation_period": "31557600", 480 "unstaking_period": "2629800", 481 "max_delegators": "100", 482 "min_delegation_pushout": "10", 483 "slashing_period": "3600", 484 "max_jailed_percentage": "0.250000000000000000", 485 "max_slashing_percentage": "0.010000000000000000", 486 "min_custody_reward": "200", 487 "max_custody_buffer_size": "10", 488 "max_custody_tx_size": "8192", 489 "abstention_rank_decrease_amount": "1", 490 "max_abstention": "2", 491 "min_collective_bond": "100000", 492 "min_collective_bonding_time": "86400", 493 "max_collective_outputs": "10", 494 "min_collective_claim_period": "14400", 495 "validator_recovery_bond": "300000", 496 "max_annual_inflation": "0.350000000000000000", 497 "max_proposal_title_size": "128", 498 "max_proposal_description_size": "1024", 499 "max_proposal_poll_option_size": "64", 500 "max_proposal_poll_option_count": "128", 501 "max_proposal_reference_size": "512", 502 "max_proposal_checksum_size": "128", 503 "min_dapp_bond": "1000000", 504 "max_dapp_bond": "10000000", 505 "dapp_liquidation_threshold": "0", 506 "dapp_liquidation_period": "0", 507 "dapp_bond_duration": "604800", 508 "dapp_verifier_bond": "0.001000000000000000", 509 "dapp_auto_denounce_time": "60", 510 "dapp_mischance_rank_decrease_amount": "1", 511 "dapp_max_mischance": "10", 512 "dapp_inactive_rank_decrease_percent": "10", 513 "dapp_pool_slippage_default": "0.100000000000000000", 514 "minting_ft_fee": "100000000000000", 515 "minting_nft_fee": "100000000000000", 516 "veto_threshold": "33.400000000000000000", 517 "autocompound_interval_num_blocks": "17280" 518 }, 519 "execution_fees": [ 520 { 521 "transaction_type": "claim-validator-seat", 522 "execution_fee": "10", 523 "failure_fee": "1", 524 "timeout": "10", 525 "default_parameters": "0" 526 } 527 ], 528 "poor_network_messages": { 529 "messages": [ 530 "set-network-properties" 531 ] 532 }, 533 "proposals": [], 534 "votes": [], 535 "data_registry": {}, 536 "identity_records": [], 537 "last_identity_record_id": "0", 538 "id_records_verify_requests": [], 539 "last_id_record_verify_request_id": "0", 540 "proposal_durations": {} 541 }`)) 542 require.NoError(t, err) 543 require.Equal(t, string(bz), buffer.String()) 544 }