@@ -147,22 +147,32 @@ func RandomGenesisAccounts(simState *module.SimulationState) authtypes.GenesisAc
147
147
// TODO: replace secp256k1.GenPrivKeyFromSecret() with similar function in go-ethereum
148
148
func RandomAccounts (r * rand.Rand , n int ) []simtypes.Account {
149
149
accs := make ([]simtypes.Account , n )
150
-
151
- for i := 0 ; i < n ; i ++ {
150
+ idx := make (map [string ]struct {}, n )
151
+ var i int
152
+ for i < n {
152
153
// don't need that much entropy for simulation
153
154
privkeySeed := make ([]byte , 15 )
154
- _ , _ = r .Read (privkeySeed )
155
-
155
+ if _ , err := r .Read (privkeySeed ); err != nil {
156
+ panic (err )
157
+ }
156
158
prv := secp256k1 .GenPrivKeyFromSecret (privkeySeed )
157
159
ethPrv := & ethsecp256k1.PrivKey {}
158
160
_ = ethPrv .UnmarshalAmino (prv .Bytes ()) // UnmarshalAmino simply copies the bytes and assigns them to ethPrv.Key
159
- accs [i ].PrivKey = ethPrv
160
- accs [i ].PubKey = accs [i ].PrivKey .PubKey ()
161
- accs [i ].Address = sdk .AccAddress (accs [i ].PubKey .Address ())
162
-
163
- accs [i ].ConsKey = ed25519 .GenPrivKeyFromSecret (privkeySeed )
161
+ pubKey := ethPrv .PubKey ()
162
+ addr := sdk .AccAddress (pubKey .Address ())
163
+ if _ , exists := idx [string (addr .Bytes ())]; exists {
164
+ continue
165
+ }
166
+ idx [string (addr .Bytes ())] = struct {}{}
167
+ accs [i ] = simtypes.Account {
168
+ Address : addr ,
169
+ PrivKey : ethPrv ,
170
+ PubKey : pubKey ,
171
+ ConsKey : ed25519 .GenPrivKeyFromSecret (privkeySeed ),
172
+ AddressBech32 : addr .String (),
173
+ }
174
+ i ++
164
175
}
165
-
166
176
return accs
167
177
}
168
178
0 commit comments