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

SDK simulation doesn't support custom keys #7129

Closed
4 tasks
fedekunze opened this issue Aug 21, 2020 · 0 comments · Fixed by #7135
Closed
4 tasks

SDK simulation doesn't support custom keys #7129

fedekunze opened this issue Aug 21, 2020 · 0 comments · Fixed by #7135
Assignees
Labels
C:Keys Keybase, KMS and HSMs C:Simulations T:Bug

Comments

@fedekunze
Copy link
Collaborator

fedekunze commented Aug 21, 2020

Summary of Bug

The sdk sims have the secp256k1 key hardcoded for generating random accounts, preventing from running sims on other chains which use custom keys.

// types/simulation/account.go

// RandomAccounts generates n random accounts
func RandomAccounts(r *rand.Rand, n int) []Account {
	accs := make([]Account, n)

	for i := 0; i < n; i++ {
		// don't need that much entropy for simulation
		privkeySeed := make([]byte, 15)
		r.Read(privkeySeed)

		accs[i].PrivKey = secp256k1.GenPrivKeyFromSecret(privkeySeed)
		accs[i].PubKey = accs[i].PrivKey.PubKey()
		accs[i].Address = sdk.AccAddress(accs[i].PubKey.Address())

		accs[i].ConsKey = ed25519.GenPrivKeyFromSecret(privkeySeed)
	}

	return accs
}

The easy solution I see is to pass in an argument to the SimulateFromSeed that generates a random account:

type RandomAccountFn func(r *rand.Rand, n int) []Account
func SimulateFromSeed(
	tb testing.TB, w io.Writer, app *baseapp.BaseApp,
	appStateFn simulation.AppStateFn, randAccFn simulation.RandomAccountFn,
	ops WeightedOperations,
	blackListedAccs map[string]bool, config simulation.Config,
) (stopEarly bool, exportedParams Params, err error) {

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@fedekunze fedekunze added T:Bug C:Keys Keybase, KMS and HSMs C:Simulations labels Aug 21, 2020
@fedekunze fedekunze self-assigned this Aug 21, 2020
@fedekunze fedekunze mentioned this issue Aug 21, 2020
9 tasks
@mergify mergify bot closed this as completed in #7135 Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Keys Keybase, KMS and HSMs C:Simulations T:Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant