Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix concurrency issue in go test(x/lockup) #8765

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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