github.com/lino-network/lino@v0.6.11/app/genesis_test.go (about) 1 package app 2 3 import ( 4 "encoding/json" 5 "strconv" 6 "testing" 7 "time" 8 9 "github.com/lino-network/lino/param" 10 "github.com/lino-network/lino/types" 11 "github.com/stretchr/testify/assert" 12 "github.com/tendermint/tendermint/crypto/secp256k1" 13 14 wire "github.com/cosmos/cosmos-sdk/codec" 15 // sdk "github.com/cosmos/cosmos-sdk/types" 16 ) 17 18 func TestGetGenesisJson(t *testing.T) { 19 resetPriv := secp256k1.GenPrivKey() 20 transactionPriv := secp256k1.GenPrivKey() 21 validatorPriv := secp256k1.GenPrivKey() 22 23 totalLino := types.NewCoinFromInt64(10000000000 * types.Decimals) 24 genesisAcc := GenesisAccount{ 25 Name: "Lino", 26 Coin: totalLino, 27 TxKey: resetPriv.PubKey(), 28 SignKey: transactionPriv.PubKey(), 29 IsValidator: true, 30 ValPubKey: validatorPriv.PubKey(), 31 } 32 33 genesisAppDeveloper := GenesisAppDeveloper{ 34 Name: "Lino", 35 } 36 genesisState := GenesisState{ 37 LoadPrevStates: false, 38 GenesisPools: GenesisPools{ 39 Pools: []GenesisPool{ 40 { 41 Name: types.InflationDeveloperPool, 42 Amount: types.NewCoinFromInt64(0), 43 }, 44 { 45 Name: types.InflationValidatorPool, 46 Amount: types.NewCoinFromInt64(0), 47 }, 48 { 49 Name: types.InflationConsumptionPool, 50 Amount: types.NewCoinFromInt64(0), 51 }, 52 { 53 Name: types.VoteStakeInPool, 54 Amount: types.NewCoinFromInt64(0), 55 }, 56 { 57 Name: types.VoteStakeReturnPool, 58 Amount: types.NewCoinFromInt64(0), 59 }, 60 { 61 Name: types.VoteFrictionPool, 62 Amount: types.NewCoinFromInt64(0), 63 }, 64 { 65 Name: types.DevIDAReservePool, 66 Amount: types.MustLinoToCoin("2000000000"), 67 }, 68 { 69 Name: types.AccountVestingPool, 70 Amount: types.MustLinoToCoin("8000000000"), 71 }, 72 }, 73 Total: types.MustLinoToCoin("10000000000"), 74 }, 75 InitCoinPrice: types.NewMiniDollar(1200), 76 Accounts: []GenesisAccount{genesisAcc}, 77 Developers: []GenesisAppDeveloper{genesisAppDeveloper}, 78 GenesisParam: GenesisParam{ 79 true, 80 param.GlobalAllocationParam{ 81 GlobalGrowthRate: types.NewDecFromRat(98, 1000), 82 ContentCreatorAllocation: types.NewDecFromRat(10, 100), 83 DeveloperAllocation: types.NewDecFromRat(70, 100), 84 ValidatorAllocation: types.NewDecFromRat(20, 100), 85 }, 86 param.VoteParam{ 87 MinStakeIn: types.NewCoinFromInt64(1000 * types.Decimals), 88 VoterCoinReturnIntervalSec: int64(7 * 24 * 3600), 89 VoterCoinReturnTimes: int64(7), 90 DelegatorCoinReturnIntervalSec: int64(7 * 24 * 3600), 91 DelegatorCoinReturnTimes: int64(7), 92 }, 93 param.ProposalParam{ 94 ContentCensorshipDecideSec: int64(24 * 7 * 3600), 95 ContentCensorshipPassRatio: types.NewDecFromRat(50, 100), 96 ContentCensorshipPassVotes: types.NewCoinFromInt64(10000 * types.Decimals), 97 ContentCensorshipMinDeposit: types.NewCoinFromInt64(100 * types.Decimals), 98 99 ChangeParamDecideSec: int64(24 * 7 * 3600), 100 ChangeParamPassRatio: types.NewDecFromRat(70, 100), 101 ChangeParamPassVotes: types.NewCoinFromInt64(1000000 * types.Decimals), 102 ChangeParamMinDeposit: types.NewCoinFromInt64(100000 * types.Decimals), 103 104 ProtocolUpgradeDecideSec: int64(24 * 7 * 3600), 105 ProtocolUpgradePassRatio: types.NewDecFromRat(80, 100), 106 ProtocolUpgradePassVotes: types.NewCoinFromInt64(10000000 * types.Decimals), 107 ProtocolUpgradeMinDeposit: types.NewCoinFromInt64(1000000 * types.Decimals), 108 }, 109 param.DeveloperParam{ 110 DeveloperMinDeposit: types.NewCoinFromInt64(1000000 * types.Decimals), 111 DeveloperCoinReturnIntervalSec: int64(7 * 24 * 3600), 112 DeveloperCoinReturnTimes: int64(7), 113 }, 114 param.ValidatorParam{ 115 ValidatorMinDeposit: types.NewCoinFromInt64(200000 * types.Decimals), 116 ValidatorCoinReturnIntervalSec: int64(7 * 24 * 3600), 117 ValidatorCoinReturnTimes: int64(7), 118 PenaltyMissCommit: types.NewCoinFromInt64(200 * types.Decimals), 119 PenaltyByzantine: types.NewCoinFromInt64(1000 * types.Decimals), 120 AbsentCommitLimitation: int64(600), // 30min 121 OncallSize: int64(22), 122 StandbySize: int64(7), 123 ValidatorRevokePendingSec: int64(7 * 24 * 3600), 124 OncallInflationWeight: int64(2), 125 StandbyInflationWeight: int64(1), 126 MaxVotedValidators: int64(3), 127 SlashLimitation: int64(5), 128 }, 129 param.CoinDayParam{ 130 SecondsToRecoverCoinDay: int64(7 * 24 * 3600), 131 }, 132 param.BandwidthParam{ 133 SecondsToRecoverBandwidth: int64(7 * 24 * 3600), 134 CapacityUsagePerTransaction: types.NewCoinFromInt64(1 * types.Decimals), 135 VirtualCoin: types.NewCoinFromInt64(1 * types.Decimals), 136 GeneralMsgQuotaRatio: types.NewDecFromRat(20, 100), 137 GeneralMsgEMAFactor: types.NewDecFromRat(1, 10), 138 AppMsgQuotaRatio: types.NewDecFromRat(80, 100), 139 AppMsgEMAFactor: types.NewDecFromRat(1, 10), 140 ExpectedMaxMPS: types.NewDecFromRat(1000, 1), 141 MsgFeeFactorA: types.NewDecFromRat(6, 1), 142 MsgFeeFactorB: types.NewDecFromRat(10, 1), 143 MaxMPSDecayRate: types.NewDecFromRat(99, 100), 144 AppBandwidthPoolSize: types.NewDecFromRat(10, 1), 145 AppVacancyFactor: types.NewDecFromRat(69, 100), 146 AppPunishmentFactor: types.NewDecFromRat(14, 5), 147 }, 148 param.AccountParam{ 149 MinimumBalance: types.NewCoinFromInt64(0), 150 RegisterFee: types.NewCoinFromInt64(1 * types.Decimals), 151 FirstDepositFullCoinDayLimit: types.NewCoinFromInt64(1 * types.Decimals), 152 MaxNumFrozenMoney: 10, 153 }, 154 param.PostParam{ 155 ReportOrUpvoteIntervalSec: 24 * 3600, 156 PostIntervalSec: 600, 157 MaxReportReputation: types.NewCoinFromInt64(100 * types.Decimals), 158 }, 159 param.ReputationParam{ 160 BestContentIndexN: 200, 161 UserMaxN: 50, 162 }, 163 param.PriceParam{ 164 TestnetMode: true, 165 UpdateEverySec: int64(time.Hour.Seconds()), 166 FeedEverySec: int64((10 * time.Minute).Seconds()), 167 HistoryMaxLen: 71, 168 PenaltyMissFeed: types.NewCoinFromInt64(10000 * types.Decimals), 169 }, 170 }, 171 } 172 173 cdc := wire.New() 174 wire.RegisterCrypto(cdc) 175 appState, err := wire.MarshalJSONIndent(cdc, genesisState) 176 assert.Nil(t, err) 177 appGenesisState := new(GenesisState) 178 err = cdc.UnmarshalJSON(appState, appGenesisState) 179 assert.Nil(t, err) 180 181 assert.Equal(t, genesisState, *appGenesisState) 182 } 183 184 func TestLinoBlockchainGenTx(t *testing.T) { 185 cdc := MakeCodec() 186 pk := secp256k1.GenPrivKey().PubKey() 187 appGenTx, _, validator, err := LinoBlockchainGenTx(cdc, pk) 188 assert.Nil(t, err) 189 var genesisAcc GenesisAccount 190 err = cdc.UnmarshalJSON(appGenTx, &genesisAcc) 191 assert.Nil(t, err) 192 assert.Equal(t, genesisAcc.Name, "lino") 193 assert.Equal(t, genesisAcc.Coin, types.NewCoinFromInt64(100000000*types.Decimals)) 194 assert.Equal(t, genesisAcc.IsValidator, true) 195 assert.Equal(t, genesisAcc.ValPubKey, pk) 196 assert.Equal(t, validator.PubKey, pk) 197 } 198 199 func TestLinoBlockchainGenState(t *testing.T) { 200 cdc := MakeCodec() 201 appGenTxs := []json.RawMessage{} 202 coinPerValidator := types.NewCoinFromInt64(100000000 * types.Decimals) 203 for i := 1; i < 21; i++ { 204 genesisAcc := GenesisAccount{ 205 Name: "validator" + strconv.Itoa(i), 206 Coin: coinPerValidator, 207 TxKey: secp256k1.GenPrivKey().PubKey(), 208 SignKey: secp256k1.GenPrivKey().PubKey(), 209 IsValidator: true, 210 ValPubKey: secp256k1.GenPrivKey().PubKey(), 211 } 212 marshalResult, err := wire.MarshalJSONIndent(cdc, genesisAcc) 213 assert.Nil(t, err) 214 appGenTxs = append(appGenTxs, json.RawMessage(marshalResult)) 215 } 216 appState, err := LinoBlockchainGenState(cdc, appGenTxs) 217 assert.Nil(t, err) 218 219 genesisState := new(GenesisState) 220 if err := cdc.UnmarshalJSON(appState, genesisState); err != nil { 221 panic(err) 222 } 223 for i, gacc := range genesisState.Accounts { 224 assert.Equal(t, gacc.Name, "validator"+strconv.Itoa(i+1)) 225 assert.Equal(t, gacc.Coin, coinPerValidator) 226 } 227 assert.Equal(t, 1, len(genesisState.Developers)) 228 }