Skip to content

Commit

Permalink
fix concurrency issue in go test(x/lockup) (#8765)
Browse files Browse the repository at this point in the history
* fix concurrency issue in go test

* Add changelog
  • Loading branch information
mattverse authored Oct 10, 2024
1 parent db971ee commit 15021f2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#8731](https://github.com/osmosis-labs/osmosis/pull/8731) fix: in place testnet logs
* [#8728](https://github.com/osmosis-labs/osmosis/pull/8728) fix unsupported sign-mode issue
* [#8743](https://github.com/osmosis-labs/osmosis/pull/8743) chore: bump sdk and cometbft
* [#8765](https://github.com/osmosis-labs/osmosis/pull/8765) fix concurrency issue in go test(x/lockup)

### State Machine Breaking

Expand Down
21 changes: 19 additions & 2 deletions x/lockup/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,44 @@ func TestExportGenesis(t *testing.T) {
}

func TestMarshalUnmarshalGenesis(t *testing.T) {
dirName := fmt.Sprintf("%d", rand.Int())
// Create a unique temporary directory for each test
dirName, err := os.MkdirTemp("", "osmoapp_test")
require.NoError(t, err)

// Ensure the directory is cleaned up after the test completes
defer os.RemoveAll(dirName)

// Setup the app with the custom directory
app := osmoapp.SetupWithCustomHome(false, dirName)

// Continue with the rest of your test setup
ctx := app.BaseApp.NewContextLegacy(false, tmproto.Header{})
ctx = ctx.WithBlockTime(now.Add(time.Second))

encodingConfig := osmoapp.MakeEncodingConfig()
appCodec := encodingConfig.Marshaler
am := lockup.NewAppModule(*app.LockupKeeper, app.AccountKeeper, app.BankKeeper)

err := testutil.FundAccount(ctx, app.BankKeeper, acc2, sdk.Coins{sdk.NewInt64Coin("foo", 5000000)})
// Fund account and create lock
err = testutil.FundAccount(ctx, app.BankKeeper, acc2, sdk.Coins{sdk.NewInt64Coin("foo", 5000000)})
require.NoError(t, err)
_, err = app.LockupKeeper.CreateLock(ctx, acc2, sdk.Coins{sdk.NewInt64Coin("foo", 5000000)}, time.Second*5)
require.NoError(t, err)

// Export genesis state
genesisExported := am.ExportGenesis(ctx, appCodec)

// After removing the temp directory, the app should no longer have access to it
os.RemoveAll(dirName)

// Ensure no panic occurs when initializing genesis in a fresh app
assert.NotPanics(t, func() {
// Setup a new app instance
app := osmoapp.Setup(false)
ctx := app.BaseApp.NewContextLegacy(false, tmproto.Header{})
ctx = ctx.WithBlockTime(now.Add(time.Second))

// Initialize genesis with the exported state
am := lockup.NewAppModule(*app.LockupKeeper, app.AccountKeeper, app.BankKeeper)
am.InitGenesis(ctx, appCodec, genesisExported)
})
Expand Down

0 comments on commit 15021f2

Please sign in to comment.