Skip to content

Commit

Permalink
RandomAccounts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jan 6, 2025
1 parent e5d5c69 commit 50ffbaf
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions testutil/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,32 @@ func RandomGenesisAccounts(simState *module.SimulationState) authtypes.GenesisAc
// TODO: replace secp256k1.GenPrivKeyFromSecret() with similar function in go-ethereum
func RandomAccounts(r *rand.Rand, n int) []simtypes.Account {
accs := make([]simtypes.Account, n)

for i := 0; i < n; i++ {
idx := make(map[string]struct{}, n)
var i int
for i < n {

Check warning on line 152 in testutil/app.go

View check run for this annotation

Codecov / codecov/patch

testutil/app.go#L150-L152

Added lines #L150 - L152 were not covered by tests
// don't need that much entropy for simulation
privkeySeed := make([]byte, 15)
_, _ = r.Read(privkeySeed)

if _, err := r.Read(privkeySeed); err != nil {
panic(err)

Check warning on line 156 in testutil/app.go

View check run for this annotation

Codecov / codecov/patch

testutil/app.go#L155-L156

Added lines #L155 - L156 were not covered by tests
}
prv := secp256k1.GenPrivKeyFromSecret(privkeySeed)
ethPrv := &ethsecp256k1.PrivKey{}
_ = ethPrv.UnmarshalAmino(prv.Bytes()) // UnmarshalAmino simply copies the bytes and assigns them to ethPrv.Key
accs[i].PrivKey = ethPrv
accs[i].PubKey = accs[i].PrivKey.PubKey()
accs[i].Address = sdk.AccAddress(accs[i].PubKey.Address())

accs[i].ConsKey = ed25519.GenPrivKeyFromSecret(privkeySeed)
pubKey := ethPrv.PubKey()
addr := sdk.AccAddress(pubKey.Address())
if _, exists := idx[string(addr.Bytes())]; exists {
continue

Check warning on line 164 in testutil/app.go

View check run for this annotation

Codecov / codecov/patch

testutil/app.go#L161-L164

Added lines #L161 - L164 were not covered by tests
}
idx[string(addr.Bytes())] = struct{}{}
accs[i] = simtypes.Account{
Address: addr,
PrivKey: ethPrv,
PubKey: pubKey,
ConsKey: ed25519.GenPrivKeyFromSecret(privkeySeed),
AddressBech32: addr.String(),
}
i++

Check warning on line 174 in testutil/app.go

View check run for this annotation

Codecov / codecov/patch

testutil/app.go#L166-L174

Added lines #L166 - L174 were not covered by tests
}

return accs
}

Expand Down

0 comments on commit 50ffbaf

Please sign in to comment.