From ba3b353ee928e7308e3089c606a5ccc139ff676c Mon Sep 17 00:00:00 2001 From: Denali Marsh Date: Thu, 4 Jun 2020 18:27:54 -0700 Subject: [PATCH] [R4R] add bep3 module param to committee (#547) * update committee test * update committee params * update default deputy address to expected mainnet address * spelling in comment * fix bep3 sim values to 1 * bep3 sims:generate 32 length random number --- contrib/current/wip_genesis.json | 33 ++++++++++++++------------- migrate/v0_8/testdata/all-new.json | 2 +- x/bep3/simulation/genesis.go | 4 ++-- x/bep3/simulation/operations.go | 8 +++---- x/bep3/spec/05_params.md | 2 +- x/bep3/types/params.go | 2 +- x/committee/simulation/proposals.go | 2 +- x/committee/types/permissions_test.go | 10 ++++++++ 8 files changed, 36 insertions(+), 27 deletions(-) diff --git a/contrib/current/wip_genesis.json b/contrib/current/wip_genesis.json index 8a672089..669d6f2a 100644 --- a/contrib/current/wip_genesis.json +++ b/contrib/current/wip_genesis.json @@ -47,7 +47,7 @@ "assets_supplies": [], "atomic_swaps": [], "params": { - "bnb_deputy_address": "kava1tfvn5t8qwngqd2q427za2mel48pcus3z9u73fl", + "bnb_deputy_address": "kava1r4v2zdhdalfj2ydazallqvrus9fkphmglhn6u6", "bnb_deputy_fixed_fee": "1000", "min_amount": "0", "max_amount": "1000000000000", @@ -172,6 +172,22 @@ "subspace": "auction", "key": "IncrementCollateral" }, + { + "subspace": "bep3", + "key": "BnbDeputyAddress" + }, + { + "subspace": "bep3", + "key": "BnbDeputyFixedFee" + }, + { + "subspace": "bep3", + "key": "MinAmount" + }, + { + "subspace": "bep3", + "key": "MaxAmount" + }, { "subspace": "bep3", "key": "SupportedAssets" @@ -231,21 +247,6 @@ ], "vote_threshold": "0.750000000000000000", "proposal_duration": "604800000000000" - }, - { - "id": "1", - "description": "This committee is for testnet", - "members": [ - "kava109fpwjvq6un86tw8f8emav2l0e0dha924scrj9" - ], - "permissions": [ - { - "type": "kava/GodPermission", - "value": {} - } - ], - "vote_threshold": "0.750000000000000000", - "proposal_duration": "604800000000000" } ], "proposals": [], diff --git a/migrate/v0_8/testdata/all-new.json b/migrate/v0_8/testdata/all-new.json index efef2fef..61485dbf 100644 --- a/migrate/v0_8/testdata/all-new.json +++ b/migrate/v0_8/testdata/all-new.json @@ -304,7 +304,7 @@ }, "bep3": { "params": { - "bnb_deputy_address": "kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj", + "bnb_deputy_address": "kava1r4v2zdhdalfj2ydazallqvrus9fkphmglhn6u6", "bnb_deputy_fixed_fee": "1000", "min_amount": "0", "max_amount": "1000000000000", diff --git a/x/bep3/simulation/genesis.go b/x/bep3/simulation/genesis.go index 0a6603fd..9ab107cb 100644 --- a/x/bep3/simulation/genesis.go +++ b/x/bep3/simulation/genesis.go @@ -41,7 +41,7 @@ func GenRandBnbDeputy(r *rand.Rand) simulation.Account { // GenRandBnbDeputyFixedFee randomized BnbDeputyFixedFee in range [2, 10000] func GenRandBnbDeputyFixedFee(r *rand.Rand) sdk.Int { - min := int(2) + min := int(1) max := types.DefaultBnbDeputyFixedFee.Int64() return sdk.NewInt(int64(r.Intn(int(max)-min) + min)) } @@ -62,7 +62,7 @@ func GenMaxAmount(r *rand.Rand, minAmount sdk.Int) sdk.Int { // GenMinBlockLock randomized MinBlockLock func GenMinBlockLock(r *rand.Rand) uint64 { - min := 20 + min := int(1) max := int(types.DefaultMaxBlockLock) return uint64(r.Intn(max-min) + min) } diff --git a/x/bep3/simulation/operations.go b/x/bep3/simulation/operations.go index 8845d80d..a907d8a7 100644 --- a/x/bep3/simulation/operations.go +++ b/x/bep3/simulation/operations.go @@ -2,7 +2,6 @@ package simulation import ( "fmt" - "math" "math/rand" "github.com/cosmos/cosmos-sdk/baseapp" @@ -100,13 +99,12 @@ func SimulateMsgCreateAtomicSwap(ak types.AccountKeeper, k keeper.Keeper) simula senderOtherChain := simulation.RandStringOfLength(r, 43) // Generate cryptographically strong pseudo-random number - randomNumber, err := simulation.RandPositiveInt(r, sdk.NewInt(math.MaxInt64)) + randomNumber, err := types.GenerateSecureRandomNumber() if err != nil { return noOpMsg, nil, err } - // Must use current blocktime instead of 'now' since initial blocktime was randomly generated timestamp := ctx.BlockTime().Unix() - randomNumberHash := types.CalculateRandomHash(randomNumber.BigInt().Bytes(), timestamp) + randomNumberHash := types.CalculateRandomHash(randomNumber, timestamp) // Check that the sender has coins for fee senderAcc := ak.GetAccount(ctx, sender.Address) @@ -171,7 +169,7 @@ func SimulateMsgCreateAtomicSwap(ak types.AccountKeeper, k keeper.Keeper) simula executionBlock := uint64(ctx.BlockHeight()) + msg.HeightSpan/2 futureOp = simulation.FutureOperation{ BlockHeight: int(executionBlock), - Op: operationClaimAtomicSwap(ak, k, swapID, randomNumber.BigInt().Bytes()), + Op: operationClaimAtomicSwap(ak, k, swapID, randomNumber), } } else { // Refund future operation diff --git a/x/bep3/spec/05_params.md b/x/bep3/spec/05_params.md index 9d39e89a..5082fb67 100644 --- a/x/bep3/spec/05_params.md +++ b/x/bep3/spec/05_params.md @@ -8,7 +8,7 @@ The bep3 module contains the following parameters: | Key | Type | Example | Description | |-------------------|-------------------------|-----------------------------------------------|-------------------------------| -| BnbDeputyAddress | string (sdk.AccAddress) | "kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj" | deputy's Kava address | +| BnbDeputyAddress | string (sdk.AccAddress) | "kava1r4v2zdhdalfj2ydazallqvrus9fkphmglhn6u6" | deputy's Kava address | | BnbDeputyFixedFee | sdk.Int | sdk.NewInt(1000) | deputy's fixed bnb fee | | MinAmount | sdk.Int | sdk.NewInt(0) | minimum swap amount | | MaxAmount | sdk.Int | sdk.NewInt(1000000000000) | maximum swap amount | diff --git a/x/bep3/types/params.go b/x/bep3/types/params.go index 0e5b86d3..0725daac 100644 --- a/x/bep3/types/params.go +++ b/x/bep3/types/params.go @@ -80,7 +80,7 @@ func NewParams(bnbDeputyAddress sdk.AccAddress, bnbDeputyFixedFee, minAmount, // DefaultParams returns default params for bep3 module func DefaultParams() Params { - defaultBnbDeputyAddress, err := sdk.AccAddressFromBech32("kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj") + defaultBnbDeputyAddress, err := sdk.AccAddressFromBech32("kava1r4v2zdhdalfj2ydazallqvrus9fkphmglhn6u6") if err != nil { panic(err) } diff --git a/x/committee/simulation/proposals.go b/x/committee/simulation/proposals.go index 6d68ddf9..b0eb3a7a 100644 --- a/x/committee/simulation/proposals.go +++ b/x/committee/simulation/proposals.go @@ -79,7 +79,7 @@ func SimulateCommitteeChangeProposalContent(k keeper.Keeper, paramChanges []simu // update members if r.Intn(100) < 50 { if len(accs) == 0 { - panic("must have at least one account availabel to use as committee member") + panic("must have at least one account available to use as committee member") } var members []sdk.AccAddress for len(members) < 1 { diff --git a/x/committee/types/permissions_test.go b/x/committee/types/permissions_test.go index bc2dddf1..6a4cf16c 100644 --- a/x/committee/types/permissions_test.go +++ b/x/committee/types/permissions_test.go @@ -36,6 +36,10 @@ func (suite *PermissionsTestSuite) SetupTest() { Subspace: "auction", Key: "BidDuration", }, + { + Subspace: "bep3", + Key: "MinAmount", + }, } } @@ -82,6 +86,12 @@ func (suite *PermissionsTestSuite) TestSimpleParamChangePermission_Allows() { Value: `[]`, }, + { + Subspace: "bep3", + Key: "MinAmount", + + Value: `2000`, + }, }, ), expectAllowed: true,