Skip to content

Commit

Permalink
fix test to be determinitic
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 3, 2024
1 parent f16b7fc commit 8d32d97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions x/gov/keeper/custom_grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ func Test_CustomGrpcQuerier_Proposal(t *testing.T) {
func Test_CustomGrpcQuerier_TallyResult(t *testing.T) {
ctx, input := createDefaultTestInput(t)

setupVesting(t, ctx, input)
now := time.Now().UTC()
setupVesting(t, ctx, input, now)

proposal, err := input.GovKeeper.SubmitProposal(ctx, nil, "", "test", "description", addrs[0], false)
require.NoError(t, err)
Expand Down Expand Up @@ -188,7 +189,7 @@ func Test_CustomGrpcQuerier_TallyResult(t *testing.T) {
require.NoError(t, err)

// 15 minutes passed
ctx = ctx.WithBlockTime(time.Now().UTC().Add(time.Minute * 15))
ctx = ctx.WithBlockTime(now.Add(time.Minute * 15))
cacheCtx, _ := ctx.CacheContext()

quorumReached, passed, burnDeposits, tallyResults, err := input.GovKeeper.Tally(cacheCtx, params, proposal)
Expand Down
8 changes: 4 additions & 4 deletions x/gov/keeper/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Test_isLowThresholdProposal(t *testing.T) {
require.False(t, keeper.IsLowThresholdProposal(params, proposal))
}

func setupVesting(t *testing.T, ctx sdk.Context, input TestKeepers) {
func setupVesting(t *testing.T, ctx sdk.Context, input TestKeepers, now time.Time) {
err := input.MoveKeeper.PublishModuleBundle(ctx, vmtypes.TestAddress, vmtypes.NewModuleBundle(vmtypes.NewModule(vestingModule)), movetypes.UpgradePolicy_COMPATIBLE)
require.NoError(t, err)

Expand All @@ -68,7 +68,6 @@ func setupVesting(t *testing.T, ctx sdk.Context, input TestKeepers) {
err = input.MoveKeeper.ExecuteEntryFunctionJSON(ctx, creatorAddr, moduleAddr, moduleName, "create_vesting_store", []vmtypes.TypeTag{}, []string{fmt.Sprintf("\"%s\"", metadata)})
require.NoError(t, err)

now := time.Now().UTC()
ctx = ctx.WithBlockTime(now)

// add vesting
Expand Down Expand Up @@ -104,7 +103,8 @@ func setupVesting(t *testing.T, ctx sdk.Context, input TestKeepers) {
func Test_Tally(t *testing.T) {
ctx, input := createDefaultTestInput(t)

setupVesting(t, ctx, input)
now := time.Now().UTC()
setupVesting(t, ctx, input, now)

proposal, err := input.GovKeeper.SubmitProposal(ctx, nil, "", "test", "description", addrs[0], false)
require.NoError(t, err)
Expand Down Expand Up @@ -168,7 +168,7 @@ func Test_Tally(t *testing.T) {
require.NoError(t, err)

// 15 minutes passed
ctx = ctx.WithBlockTime(time.Now().UTC().Add(time.Minute * 15))
ctx = ctx.WithBlockTime(now.Add(time.Minute * 15))

quorumReached, passed, burnDeposits, tallyResults, err := input.GovKeeper.Tally(ctx, params, proposal)
require.NoError(t, err)
Expand Down

0 comments on commit 8d32d97

Please sign in to comment.