diff --git a/x/stake/keeper_test.go b/x/stake/keeper_test.go index 6e232d4f9..0e62f0936 100644 --- a/x/stake/keeper_test.go +++ b/x/stake/keeper_test.go @@ -115,9 +115,9 @@ func TestValidatorBasics(t *testing.T) { resVals = keeper.GetValidatorsBonded(ctx) require.Equal(t, 3, len(resVals)) - assert.True(ValEq(t, validators[0], resVals[0])) // order doesn't matter here - assert.True(ValEq(t, validators[1], resVals[2])) - assert.True(ValEq(t, validators[2], resVals[1])) + assert.True(ValEq(t, validators[0], resVals[2])) // order doesn't matter here + assert.True(ValEq(t, validators[1], resVals[1])) + assert.True(ValEq(t, validators[2], resVals[0])) // remove a record keeper.removeValidator(ctx, validators[1].Owner) diff --git a/x/stake/test_common.go b/x/stake/test_common.go index 2c5785910..109112086 100644 --- a/x/stake/test_common.go +++ b/x/stake/test_common.go @@ -22,33 +22,8 @@ import ( // dummy addresses used for testing var ( - addrs = []sdk.Address{ - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6160", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctqyxjnwh"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6161", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6162", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctzhrnsa6"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6163", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctr2489qg"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6164", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctytvs4pd"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6165", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ct9k6yqul"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6166", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctxcf3kjq"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6167", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ct89l9r0j"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6168", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctg6jkls2"), - testAddr("A58856F0FD53BF058B4909A21AEC019107BA6169", "cosmosaccaddr:5ky9du8a2wlstz6fpx3p4mqpjyrm5ctf8yz2dc"), - } - - // dummy pubkeys used for testing - pks = []crypto.PubKey{ - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB50"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB51"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB52"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB53"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB54"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB55"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB56"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB57"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB58"), - newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB59"), - } - + addrs = createTestAddrs(100) + pks = createTestPubKeys(100) emptyAddr sdk.Address emptyPubkey crypto.PubKey ) @@ -168,10 +143,10 @@ func createTestAddrs(numAddrs int) []sdk.Address { var addresses []sdk.Address var buffer bytes.Buffer - //start at 10 to avoid changing 1 to 01, 2 to 02, etc - for i := 10; i < numAddrs; i++ { + // start at 100 so we can make up to 999 test addresses with valid test addresses + for i := 100; i < (numAddrs + 100); i++ { numString := strconv.Itoa(i) - buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA61") //base address string + buffer.WriteString("A58856F0FD53BF058B4909A21AEC019107BA6") //base address string buffer.WriteString(numString) //adding on final two digits to make addresses unique res, _ := sdk.GetAccAddressHex(buffer.String()) @@ -187,10 +162,10 @@ func createTestPubKeys(numPubKeys int) []crypto.PubKey { var buffer bytes.Buffer //start at 10 to avoid changing 1 to 01, 2 to 02, etc - for i := 10; i < numPubKeys; i++ { + for i := 100; i < (numPubKeys + 100); i++ { numString := strconv.Itoa(i) - buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB") //base pubkey string - buffer.WriteString(numString) //adding on final two digits to make pubkeys unique + buffer.WriteString("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AF") //base pubkey string + buffer.WriteString(numString) //adding on final two digits to make pubkeys unique publicKeys = append(publicKeys, newPubKey(buffer.String())) buffer.Reset() } diff --git a/x/stake/validator_test.go b/x/stake/validator_test.go index 1ca5ba2f7..98a82d1dc 100644 --- a/x/stake/validator_test.go +++ b/x/stake/validator_test.go @@ -148,7 +148,7 @@ func TestUpdateStatus(t *testing.T) { // TODO refactor this random setup // generate a random validator -func randomValidator(r *rand.Rand) Validator { +func randomValidator(r *rand.Rand, i int) Validator { poolSharesAmt := sdk.NewRat(int64(r.Int31n(10000))) delShares := sdk.NewRat(int64(r.Int31n(10000))) @@ -160,8 +160,8 @@ func randomValidator(r *rand.Rand) Validator { pShares = NewUnbondedShares(poolSharesAmt) } return Validator{ - Owner: addrs[0], - PubKey: pks[0], + Owner: addrs[i], + PubKey: pks[i], PoolShares: pShares, DelegatorShares: delShares, } @@ -173,7 +173,7 @@ func randomSetup(r *rand.Rand, numValidators int) (Pool, Validators) { validators := make([]Validator, numValidators) for i := 0; i < numValidators; i++ { - validator := randomValidator(r) + validator := randomValidator(r, i) if validator.Status() == sdk.Bonded { pool.BondedShares = pool.BondedShares.Add(validator.PoolShares.Bonded()) pool.BondedTokens += validator.PoolShares.Bonded().Evaluate()