Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x/ecocredit): add basket simulations #769

Merged
merged 31 commits into from
Feb 23, 2022
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3c4f955
wip: add simulations
aleem1314 Feb 14, 2022
449f5d0
feat: implement simulate msg-create-basket
aleem1314 Feb 14, 2022
b08d3cf
Merge branch 'release/v2.2.x' into aleem/basket-sims
aleem1314 Feb 15, 2022
83a23d2
feat: add put into basket sim
aleem1314 Feb 15, 2022
8abdf8b
wip: sims
aleem1314 Feb 15, 2022
a5bdfc3
wip: try fix sims
aleem1314 Feb 15, 2022
b7fa656
feat: add msg-take
aleem1314 Feb 15, 2022
1719045
chore: cleanup
aleem1314 Feb 15, 2022
d17301c
chore: inc basket sims gas
aleem1314 Feb 15, 2022
1b08beb
Merge branch 'release/v2.2.x' into aleem/basket-sims
aleem1314 Feb 16, 2022
c4ca68d
add logs
aleem1314 Feb 16, 2022
a15a783
fix error
aleem1314 Feb 16, 2022
b7f0d56
add basket fee check
aleem1314 Feb 16, 2022
ec8c8f9
try fix sims
aleem1314 Feb 17, 2022
adf93eb
Merge branch 'release/v3.0.x' into aleem/basket-sims
aaronc Feb 17, 2022
1996c2f
convert basket decimal to integer using string
aaronc Feb 17, 2022
d1c0eca
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 18, 2022
eeb3525
cleanup
aleem1314 Feb 18, 2022
876e156
update app/app.go
aleem1314 Feb 18, 2022
74cbc4d
fix random amt issue
aleem1314 Feb 18, 2022
7d10eb4
fix sim error
aleem1314 Feb 18, 2022
116082e
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 18, 2022
ec18dc2
chore: create helpers
aleem1314 Feb 18, 2022
ac7826f
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 18, 2022
246ac8d
add date criteria
aleem1314 Feb 18, 2022
fdfa386
Merge branch 'release/v3.0.x' into aleem/basket-sims
robert-zaremba Feb 18, 2022
361a49a
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 20, 2022
0e9c364
fix supply invariant
ryanchristo Feb 22, 2022
a5c9594
chore: review changes
aleem1314 Feb 23, 2022
df30c09
Merge branch 'release/v3.0.x' into aleem/basket-sims
aleem1314 Feb 23, 2022
c23a926
Merge branch 'release/v3.0.x' into aleem/basket-sims
robert-zaremba Feb 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
try fix sims
  • Loading branch information
aleem1314 committed Feb 17, 2022
commit ec8c8f93baaa8672852a32332b40c7ea08d15c58
23 changes: 13 additions & 10 deletions x/ecocredit/simulation/basket/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ func SimulateMsgCreate(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper,
return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgCreate, err.Error()), nil, nil
}

fmt.Println("++++++++++++++++MsgCreate+++++++++++++++++++++++++++++++++")
fmt.Println(msg.String())
fmt.Println("+++++++++++++++++++++++++++++++++++++++++++++++++")
if strings.Contains(err.Error(), "insufficient funds") {
return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgCreate, err.Error()), nil, nil
}
return simtypes.NoOpMsg(ecocredit.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
}

Expand Down Expand Up @@ -306,7 +306,7 @@ func SimulateMsgPut(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper,

}
}
if count == 4 {
if count == 3 {
break
}
count++
Expand Down Expand Up @@ -350,11 +350,8 @@ func SimulateMsgPut(ak ecocredit.AccountKeeper, bk ecocredit.BankKeeper,
return simtypes.NoOpMsg(ecocredit.ModuleName, msg.Type(), "class is not allowed"), nil, nil
}

if strings.Contains(err.Error(), "greater than max") {
fmt.Println("++++++++++++++++MsgPut+++++++++++++++++++++++++++++++++")
if strings.Contains(err.Error(), "message index") {
fmt.Println(msg.String())
fmt.Println("+++++++++++++++++++++++++++++++++++++++++++++++++")
return simtypes.NoOpMsg(ecocredit.ModuleName, msg.Type(), "class is not allowed"), nil, nil
}

return simtypes.NoOpMsg(ecocredit.ModuleName, msg.Type(), "unable to deliver tx"), nil, err
Expand Down Expand Up @@ -473,8 +470,7 @@ func randomClasses(r *rand.Rand, ctx regentypes.Context, qryClient ecocredit.Que
return []string{classes[0].ClassId}, nil
}

max := simtypes.RandIntBetween(r, 1, len(classes))

max := simtypes.RandIntBetween(r, 1, min(5, len(classes)))
r.Shuffle(len(classes), func(i, j int) { classes[i], classes[j] = classes[j], classes[i] })
classIds := make([]string, max)
for i := 0; i < max; i++ {
Expand All @@ -484,6 +480,13 @@ func randomClasses(r *rand.Rand, ctx regentypes.Context, qryClient ecocredit.Que
return classIds, nil
}

func min(x, y int) int {
if x > y {
return y
}
return x
}

func randomCreditType(r *rand.Rand, ctx regentypes.Context, qryClient ecocredit.QueryClient) (*ecocredit.CreditType, error) {
res, err := qryClient.CreditTypes(ctx, &ecocredit.QueryCreditTypesRequest{})
if err != nil {
Expand Down