Skip to content

Commit

Permalink
[1607]: Remove the bank balances output when generating randomized ge…
Browse files Browse the repository at this point in the history
…nesis state.
  • Loading branch information
SpicyLemon committed Aug 18, 2023
1 parent 8b1946d commit 8aae788
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 82 deletions.
8 changes: 2 additions & 6 deletions x/hold/simulation/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@ package simulation
// This file is available only to unit tests and houses functions for doing
// things with private simulation package stuff.

var (
// HoldsString exposes the holdsString function for unit tests.
HoldsString = holdsString
// BalancesString exposes the balancesString function for unit tests.
BalancesString = balancesString
)
// HoldsString exposes the holdsString function for unit tests.
var HoldsString = holdsString
11 changes: 0 additions & 11 deletions x/hold/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ func holdsString(holds []*hold.AccountHold) string {
)
}

// balancesString creates a JSON object string of address -> amount for each balance.
func balancesString(balances []banktypes.Balance) string {
return addrCoinsStringsObjJSON(balances,
func(bal banktypes.Balance) string {
return bal.Address
},
banktypes.Balance.GetCoins,
)
}

// RandomizedGenState generates a random GenesisState for the hold module.
func RandomizedGenState(simState *module.SimulationState) {
holdGenState := hold.DefaultGenesisState()
Expand All @@ -121,6 +111,5 @@ func RandomizedGenState(simState *module.SimulationState) {
bankGenState := banktypes.GetGenesisStateFromAppState(simState.Cdc, simState.GenState)
UpdateBankGenStateForHolds(bankGenState, holdGenState)
simState.GenState[banktypes.ModuleName] = simState.Cdc.MustMarshalJSON(bankGenState)
fmt.Printf("Bank balances after update due to randomly generated holds:\n%s\n", balancesString(bankGenState.Balances))
}
}
65 changes: 0 additions & 65 deletions x/hold/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,62 +367,6 @@ func TestHoldsString(t *testing.T) {
}
}

func TestBalancesString(t *testing.T) {
denom := "carp"
bal := func(addr sdk.AccAddress, amt int64) banktypes.Balance {
return banktypes.Balance{
Address: addr.String(),
Coins: sdk.NewCoins(sdk.NewInt64Coin(denom, amt)),
}
}

addr1 := sdk.AccAddress("addr1_______________")
addr2 := sdk.AccAddress("addr2_______________")
addr3 := sdk.AccAddress("addr3_______________")
addr4 := sdk.AccAddress("addr4_______________")

tests := []struct {
name string
bals []banktypes.Balance
}{
{name: "nil holds", bals: nil},
{name: "one hold", bals: []banktypes.Balance{bal(addr1, 11)}},
{name: "two holds", bals: []banktypes.Balance{bal(addr1, 11), bal(addr2, 22)}},
{name: "two holds reversed", bals: []banktypes.Balance{bal(addr2, 22), bal(addr1, 11)}},
{
name: "four holds",
bals: []banktypes.Balance{bal(addr1, 11), bal(addr2, 22), bal(addr3, 33), bal(addr4, 44)},
},
{
name: "four shuffled holds",
bals: []banktypes.Balance{bal(addr3, 33), bal(addr1, 11), bal(addr4, 44), bal(addr2, 22)},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var expected []string
if len(tc.bals) == 0 {
expected = []string{"{}"}
} else {
expected = make([]string, len(tc.bals)+2)
expected[0] = "{"
for i, h := range tc.bals {
expected[i+1] = ` "` + h.Address + `":"` + h.Coins.String() + `"`
if i < len(tc.bals)-1 {
expected[i+1] = expected[i+1] + ","
}
}
expected[len(expected)-1] = "}"
}

result := simulation.BalancesString(tc.bals)
lines := strings.Split(result, "\n")
assert.Equal(t, expected, lines, "BalancesString result lines")
})
}
}

func TestRandomizedGenState(t *testing.T) {
accs := simtypes.RandomAccounts(rand.New(rand.NewSource(0)), 3)

Expand Down Expand Up @@ -614,15 +558,6 @@ func TestRandomizedGenState(t *testing.T) {
expStdoutHolds := fmt.Sprintf("Selected %d randomly generated holds:\n", len(tc.expHoldGen.Holds)) +
simulation.HoldsString(tc.expHoldGen.Holds) + "\n"
assert.Contains(t, stdout, expStdoutHolds, "stdout message about holds\nExpected:\n%s", expStdoutHolds)

// Make sure stdout has the bank genesis state message if it's expected.
if len(tc.expHoldGen.Holds) == 0 {
assert.NotContains(t, stdout, "balances", "stdout message")
} else {
expStdoutBals := "Bank balances after update due to randomly generated holds:\n" +
simulation.BalancesString(tc.expBankGen.Balances) + "\n"
assert.Contains(t, stdout, expStdoutBals, "stdout message about updated balances:\nExpected:\n%s", expStdoutBals)
}
})
}
}

0 comments on commit 8aae788

Please sign in to comment.