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

Prevent migration tests from using out-of-sync data #3597

Merged
merged 1 commit into from
Oct 15, 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
85 changes: 58 additions & 27 deletions migrations/capcons/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,18 +511,20 @@ func testPathCapabilityValueMigration(
)

// Create and store path and account links
{
// Create new runtime.Storage used for storing path and account links
storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)
storeTestPathLinks(t, pathLinks, storage, inter)

storeTestPathLinks(t, pathLinks, storage, inter)
storeTestAccountLinks(accountLinks, storage, inter)

storeTestAccountLinks(accountLinks, storage, inter)

err = storage.Commit(inter, false)
require.NoError(t, err)
err = storage.Commit(inter, false)
require.NoError(t, err)
}

// Save capability values into account

Expand Down Expand Up @@ -557,6 +559,15 @@ func testPathCapabilityValueMigration(

// Migrate

// Create new runtime.Storage for migration.
// WARNING: don't reuse old storage (created for storing path and account links)
// because it has outdated cache after ExecuteTransaction() commits new data
// to underlying ledger.
storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

migration, err := migrations.NewStorageMigration(inter, storage, "test", testAddress)
require.NoError(t, err)

Expand Down Expand Up @@ -2410,16 +2421,17 @@ func TestPublishedPathCapabilityValueMigration(t *testing.T) {
)

// Create and store path links
{
storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

storeTestPathLinks(t, pathLinks, storage, inter)
storeTestPathLinks(t, pathLinks, storage, inter)

err = storage.Commit(inter, false)
require.NoError(t, err)
err = storage.Commit(inter, false)
require.NoError(t, err)
}

// Save capability values into account

Expand All @@ -2432,7 +2444,7 @@ func TestPublishedPathCapabilityValueMigration(t *testing.T) {
}
`

err = rt.ExecuteTransaction(
err := rt.ExecuteTransaction(
runtime.Script{
Source: []byte(setupTx),
},
Expand All @@ -2446,6 +2458,15 @@ func TestPublishedPathCapabilityValueMigration(t *testing.T) {

// Migrate

// Create new runtime.Storage for migration.
// WARNING: don't reuse old storage (created for storing path links)
// because it has outdated cache after ExecuteTransaction() commits new data
// to underlying ledger.
storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

migration, err := migrations.NewStorageMigration(inter, storage, "test", testAddress)
require.NoError(t, err)

Expand Down Expand Up @@ -2663,16 +2684,17 @@ func TestUntypedPathCapabilityValueMigration(t *testing.T) {
)

// Create and store path links
{
storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

storeTestPathLinks(t, pathLinks, storage, inter)
storeTestPathLinks(t, pathLinks, storage, inter)

err = storage.Commit(inter, false)
require.NoError(t, err)
err = storage.Commit(inter, false)
require.NoError(t, err)
}

// Save capability values into account

Expand All @@ -2686,7 +2708,7 @@ func TestUntypedPathCapabilityValueMigration(t *testing.T) {
}
`

err = rt.ExecuteTransaction(
err := rt.ExecuteTransaction(
runtime.Script{
Source: []byte(setupTx),
},
Expand All @@ -2700,6 +2722,15 @@ func TestUntypedPathCapabilityValueMigration(t *testing.T) {

// Migrate

// Create new runtime.Storage for migration.
// WARNING: don't reuse old storage (created for storing path links)
// because it has outdated cache after ExecuteTransaction() commits new data
// to underlying ledger.
storage, inter, err := rt.Storage(runtime.Context{
Interface: runtimeInterface,
})
require.NoError(t, err)

migration, err := migrations.NewStorageMigration(inter, storage, "test", testAddress)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading