-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x/participationrewards/keeper: fuzz CalcUserValidatorSelectionAllocat…
…ions (#1261) This change adds a fuzzer for CalcUserValidatorSelectionAllocations as it seems like a spot for which more panel beating is needed.
- Loading branch information
Showing
6 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
icstypes "github.com/quicksilver-zone/quicksilver/x/interchainstaking/types" | ||
"github.com/quicksilver-zone/quicksilver/x/participationrewards/types" | ||
) | ||
|
||
func FuzzCalcUserScores(f *testing.F) { | ||
if testing.Short() { | ||
f.Skip("In -short") | ||
} | ||
|
||
files, err := filepath.Glob(filepath.Join("testdata", "fuzz-corpus-CalcUserValidatorSectionAllocations-*")) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
|
||
type corpusData struct { | ||
Ctx sdk.Context `json:"ctx"` | ||
Zone *icstypes.Zone `json:"zone"` | ||
ZoneScore types.ZoneScore `json:"zs"` | ||
} | ||
|
||
// 1. Add the corpus. | ||
for _, filename := range files { | ||
corpusData, err := os.ReadFile(filename) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
f.Add(corpusData) | ||
} | ||
|
||
ste := new(KeeperTestSuite) | ||
ste.SetupTest() | ||
appA := ste.GetQuicksilverApp(ste.chainA) | ||
|
||
// 2. Run the fuzzers. | ||
f.Fuzz(func(t *testing.T, input []byte) { | ||
cj := new(corpusData) | ||
if err := json.Unmarshal(input, cj); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_ = appA.ParticipationRewardsKeeper.CalcUserValidatorSelectionAllocations(cj.Ctx, cj.Zone, cj.ZoneScore) | ||
}) | ||
} |
1 change: 1 addition & 0 deletions
1
...ewards/keeper/testdata/fuzz-corpus-CalcUserValidatorSectionAllocations-no allocation.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"ctx":{},"zone":{"connection_id":"connection-0","chain_id":"testchain2","withdrawal_address":{"address":"cosmos1ymnsdscyzwkw6hv5rl02mz9cxz2d95ekmenh0c88jvea9xgm62ms57gpn8","balance":[],"port_name":"testchain2.withrawal","withdrawal_address":"cosmos1ymnsdscyzwkw6hv5rl02mz9cxz2d95ekmenh0c88jvea9xgm62ms57gpn8"},"performance_address":{"address":"cosmos14f0cff8mv9ctl8ye6a0f9q45ajcgn78xwg6rj254ftw6mpednvxqsqenc4","balance":[],"port_name":"icacontroller-testchain2.performance","withdrawal_address":"cosmos14f0cff8mv9ctl8ye6a0f9q45ajcgn78xwg6rj254ftw6mpednvxqsqenc4"},"account_prefix":"cosmos","local_denom":"uqatom","base_denom":"uatom","redemption_rate":"0.000000000000000000","last_redemption_rate":"0.000000000000000000","liquidity_module":true,"holdings_allocation":"524585","tvl":"150000000.000000000000000000","deposits_enabled":true,"is_118":true},"zs":{"ZoneID":"testchain2","TotalVotingPower":"0","ValidatorScores":null}} |
1 change: 1 addition & 0 deletions
1
...ionAllocations-unit weight intents - default validator scores - different validators.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"ctx":{},"zone":{"connection_id":"connection-0","chain_id":"testchain2","withdrawal_address":{"address":"cosmos1dc7xdwzqa5xf93tuzatx03chsn6hs8ggw300qys8hg8s6rfkrygszzy8fl","balance":[],"port_name":"testchain2.withrawal","withdrawal_address":"cosmos1dc7xdwzqa5xf93tuzatx03chsn6hs8ggw300qys8hg8s6rfkrygszzy8fl"},"performance_address":{"address":"cosmos1acmscqnqy6t8l0zkw5h4zd7ls22aj0zqk6lwxlzmt9n6ueaq4zcsnntrg3","balance":[],"port_name":"icacontroller-testchain2.performance","withdrawal_address":"cosmos1acmscqnqy6t8l0zkw5h4zd7ls22aj0zqk6lwxlzmt9n6ueaq4zcsnntrg3"},"account_prefix":"cosmos","local_denom":"uqatom","base_denom":"uatom","redemption_rate":"0.000000000000000000","last_redemption_rate":"0.000000000000000000","liquidity_module":true,"validator_selection_allocation":"5000","holdings_allocation":"524585","tvl":"150000000.000000000000000000","deposits_enabled":true,"is_118":true},"zs":{"ZoneID":"testchain2","TotalVotingPower":"0","ValidatorScores":{"cosmosvaloper1hgfyy9ujf27dgmjsfha02vqjr949rqvrpv6hp2":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1hgfyy9ujf27dgmjsfha02vqjr949rqvrpv6hp2","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1rz5ufx63ef6qpgka24zq0taqs6rgssu7a95j57":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1rz5ufx63ef6qpgka24zq0taqs6rgssu7a95j57","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1xjrr5jee7ww2kmrt3xfuu26rm6g4sv5ypqtdcf":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1xjrr5jee7ww2kmrt3xfuu26rm6g4sv5ypqtdcf","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1zvx38ht3fhx0ymsfv98qg07tgel79k3uf8qvk4":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1zvx38ht3fhx0ymsfv98qg07tgel79k3uf8qvk4","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"}}}} |
1 change: 1 addition & 0 deletions
1
...ectionAllocations-unit weight intents - default validator scores - same valopaddress.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"ctx":{},"zone":{"connection_id":"connection-0","chain_id":"testchain2","withdrawal_address":{"address":"cosmos1phe57ldq837un36xqc9rcl6jnnu26gnmp5nkthgz6d6pyf5d0tvqrmu2w2","balance":[],"port_name":"testchain2.withrawal","withdrawal_address":"cosmos1phe57ldq837un36xqc9rcl6jnnu26gnmp5nkthgz6d6pyf5d0tvqrmu2w2"},"performance_address":{"address":"cosmos1mr0gthtygdayp36ercvu3nnelsx4p46daw9vthzum24t0dsteqmsnxymw6","balance":[],"port_name":"icacontroller-testchain2.performance","withdrawal_address":"cosmos1mr0gthtygdayp36ercvu3nnelsx4p46daw9vthzum24t0dsteqmsnxymw6"},"account_prefix":"cosmos","local_denom":"uqatom","base_denom":"uatom","redemption_rate":"0.000000000000000000","last_redemption_rate":"0.000000000000000000","liquidity_module":true,"validator_selection_allocation":"5000","holdings_allocation":"524585","tvl":"150000000.000000000000000000","deposits_enabled":true,"is_118":true},"zs":{"ZoneID":"testchain2","TotalVotingPower":"0","ValidatorScores":{"cosmosvaloper156e0nv0f6jwu0gkj6aftvwltknat92y0jfdz8m":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper156e0nv0f6jwu0gkj6aftvwltknat92y0jfdz8m","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1cje9scxzv5lhrzlnv6ulkf9jwukrj5scqkpwvq":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1cje9scxzv5lhrzlnv6ulkf9jwukrj5scqkpwvq","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1j6hw60ytpa3p2x6jd0dhevy2m64gdvsu4s8vsd":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1j6hw60ytpa3p2x6jd0dhevy2m64gdvsu4s8vsd","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1xnf33uep7xk85xuchp8wr72ujen5maqgchusuh":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1xnf33uep7xk85xuchp8wr72ujen5maqgchusuh","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"}}}} |
1 change: 1 addition & 0 deletions
1
...atorSectionAllocations-weighted intents - default validator scores - same validators.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"ctx":{},"zone":{"connection_id":"connection-0","chain_id":"testchain2","withdrawal_address":{"address":"cosmos18v9l9v5d5ckxxzrgfrgms3ajn2ct25xaeg880uf9g3p4kd9ezfksc2hu56","balance":[],"port_name":"testchain2.withrawal","withdrawal_address":"cosmos18v9l9v5d5ckxxzrgfrgms3ajn2ct25xaeg880uf9g3p4kd9ezfksc2hu56"},"performance_address":{"address":"cosmos1gf30z4lqskvdh8q567y8dtxpjkc3vyg6ed9rth0ky9atwm4ytjssu7z3kg","balance":[],"port_name":"icacontroller-testchain2.performance","withdrawal_address":"cosmos1gf30z4lqskvdh8q567y8dtxpjkc3vyg6ed9rth0ky9atwm4ytjssu7z3kg"},"account_prefix":"cosmos","local_denom":"uqatom","base_denom":"uatom","redemption_rate":"0.000000000000000000","last_redemption_rate":"0.000000000000000000","liquidity_module":true,"validator_selection_allocation":"5000","holdings_allocation":"524585","tvl":"150000000.000000000000000000","deposits_enabled":true,"is_118":true},"zs":{"ZoneID":"testchain2","TotalVotingPower":"0","ValidatorScores":{"cosmosvaloper12sdnkz0yhnzea8srtamk5avdj8d4urgzjzdcyf":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper12sdnkz0yhnzea8srtamk5avdj8d4urgzjzdcyf","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper143ny04dsar850pnh2cf3st4x97mfysjrg8wz4m":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper143ny04dsar850pnh2cf3st4x97mfysjrg8wz4m","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1et3zvvml8e4f6k73luvgmxgyjtp4mdauga6jpc":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1et3zvvml8e4f6k73luvgmxgyjtp4mdauga6jpc","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1wsxqcdlz0du9ch8zlsm867q2q683pe3dhwse4k":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1wsxqcdlz0du9ch8zlsm867q2q683pe3dhwse4k","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"}}}} |
1 change: 1 addition & 0 deletions
1
...z-corpus-CalcUserValidatorSectionAllocations-zero weight intents, no user allocation.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"ctx":{},"zone":{"connection_id":"connection-0","chain_id":"testchain2","withdrawal_address":{"address":"cosmos1gr39t4m3w5hv8tec3vm59sxh7tkfkgmdlxrjswrr8g56jrss7mmsfc0ecq","balance":[],"port_name":"testchain2.withrawal","withdrawal_address":"cosmos1gr39t4m3w5hv8tec3vm59sxh7tkfkgmdlxrjswrr8g56jrss7mmsfc0ecq"},"performance_address":{"address":"cosmos1v6nxr87lyjwtkyg2ukjh2ljwtdn9fnm8nzemhu3y77m3jwa6alvqrzalre","balance":[],"port_name":"icacontroller-testchain2.performance","withdrawal_address":"cosmos1v6nxr87lyjwtkyg2ukjh2ljwtdn9fnm8nzemhu3y77m3jwa6alvqrzalre"},"account_prefix":"cosmos","local_denom":"uqatom","base_denom":"uatom","redemption_rate":"0.000000000000000000","last_redemption_rate":"0.000000000000000000","liquidity_module":true,"validator_selection_allocation":"5000","holdings_allocation":"524585","tvl":"150000000.000000000000000000","deposits_enabled":true,"is_118":true},"zs":{"ZoneID":"testchain2","TotalVotingPower":"0","ValidatorScores":{"cosmosvaloper124qtz3q4nckv7ruy7srwg0487cgr6smankst48":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper124qtz3q4nckv7ruy7srwg0487cgr6smankst48","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper18k53nuj2zxy9dwunq3pefcnkexgpex673t44aq":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper18k53nuj2zxy9dwunq3pefcnkexgpex673t44aq","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1qeydm2e49j70eypqhn67sap22paey2w3ks56cw":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1qeydm2e49j70eypqhn67sap22paey2w3ks56cw","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"},"cosmosvaloper1sc7uav6t5un7hxysc33qugdz9vm4et5mssgt0x":{"PowerPercentage":"1.000000000000000000","PerformanceScore":"1.000000000000000000","DistributionScore":"1.000000000000000000","valoper_address":"cosmosvaloper1sc7uav6t5un7hxysc33qugdz9vm4et5mssgt0x","commission_rate":"0.000000000000000000","delegator_shares":"1.000000000000000000","voting_power":"1000000","score":"1.000000000000000000","status":"BOND_STATUS_BONDED","jailed_since":"0001-01-01T00:00:00Z"}}}} |