Skip to content

Commit

Permalink
do not use t.Run for steps
Browse files Browse the repository at this point in the history
steps are not individual tests, and failures do not propagateb between subtests
  • Loading branch information
turbolent committed Apr 1, 2024
1 parent 4810dfa commit df308bb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 51 deletions.
30 changes: 18 additions & 12 deletions migrations/entitlements/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3108,7 +3108,8 @@ func TestRehash(t *testing.T) {
sema.Conjunction,
)

t.Run("prepare", func(t *testing.T) {
// Prepare
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -3169,9 +3170,10 @@ func TestRehash(t *testing.T) {

err = storage.CheckHealth()
require.NoError(t, err)
})
})()

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -3236,9 +3238,10 @@ func TestRehash(t *testing.T) {
},
reporter.migrated,
)
})
})()

t.Run("load", func(t *testing.T) {
// Load
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -3278,7 +3281,7 @@ func TestRehash(t *testing.T) {
newTestValue(),
value.(*interpreter.StringValue),
)
})
})()
}

func TestIntersectionTypeWithIntersectionLegacyType(t *testing.T) {
Expand Down Expand Up @@ -3324,7 +3327,8 @@ func TestIntersectionTypeWithIntersectionLegacyType(t *testing.T) {
return storage, inter
}

t.Run("prepare", func(t *testing.T) {
// Prepare
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -3367,9 +3371,10 @@ func TestIntersectionTypeWithIntersectionLegacyType(t *testing.T) {

err = storage.CheckHealth()
require.NoError(t, err)
})
})()

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -3426,9 +3431,10 @@ func TestIntersectionTypeWithIntersectionLegacyType(t *testing.T) {
},
reporter.migrated,
)
})
})()

t.Run("load", func(t *testing.T) {
// Load
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -3460,5 +3466,5 @@ func TestIntersectionTypeWithIntersectionLegacyType(t *testing.T) {
)

require.Equal(t, expectedType, typeValue.Type)
})
})()
}
15 changes: 8 additions & 7 deletions migrations/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ func TestMigrationPanic(t *testing.T) {

// Assert

assert.Len(t, reporter.errors, 1)
require.Len(t, reporter.errors, 1)

var migrationError StorageMigrationError
require.ErrorAs(t, reporter.errors[0], &migrationError)
Expand Down Expand Up @@ -2550,8 +2550,8 @@ func TestDictionaryKeyConflict(t *testing.T) {
return storage, inter
}

t.Run("prepare", func(t *testing.T) {

// Prepare
(func() {
storage, inter := newStorageAndInterpreter(t)

storageMap := storage.GetStorageMap(
Expand Down Expand Up @@ -2693,9 +2693,10 @@ func TestDictionaryKeyConflict(t *testing.T) {

err = storage.CheckHealth()
require.NoError(t, err)
})
})()

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand All @@ -2716,7 +2717,7 @@ func TestDictionaryKeyConflict(t *testing.T) {

// Assert

assert.Len(t, reporter.errors, 1)
require.Len(t, reporter.errors, 1)

var migrationError StorageMigrationError
require.ErrorAs(t, reporter.errors[0], &migrationError)
Expand Down Expand Up @@ -2747,5 +2748,5 @@ func TestDictionaryKeyConflict(t *testing.T) {
// as one of the arrays is still stored, but no longer referenced
err = storage.CheckHealth()
require.ErrorContains(t, err, "slabs not referenced from account Storage: [0x1.3]")
})
})()
}
46 changes: 27 additions & 19 deletions migrations/statictypes/intersection_type_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ func TestIntersectionTypeRehash(t *testing.T) {
return storage, inter
}

t.Run("prepare", func(t *testing.T) {
// Prepare
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -560,9 +561,10 @@ func TestIntersectionTypeRehash(t *testing.T) {

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

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -603,9 +605,10 @@ func TestIntersectionTypeRehash(t *testing.T) {
},
reporter.migrated,
)
})
})()

t.Run("load", func(t *testing.T) {
// Load
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -633,7 +636,7 @@ func TestIntersectionTypeRehash(t *testing.T) {
newTestValue(),
value.(*interpreter.StringValue),
)
})
})()
}

// TestRehashNestedIntersectionType stores a dictionary in storage,
Expand Down Expand Up @@ -669,7 +672,8 @@ func TestRehashNestedIntersectionType(t *testing.T) {

ledger := NewTestLedger(nil, nil)

t.Run("prepare", func(t *testing.T) {
// Prepare
(func() {

storage, inter := newStorageAndInterpreter(t, ledger)

Expand Down Expand Up @@ -727,9 +731,10 @@ func TestRehashNestedIntersectionType(t *testing.T) {

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

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t, ledger)

Expand Down Expand Up @@ -770,9 +775,10 @@ func TestRehashNestedIntersectionType(t *testing.T) {
},
reporter.migrated,
)
})
})()

t.Run("load", func(t *testing.T) {
// Load
(func() {

storage, inter := newStorageAndInterpreter(t, ledger)

Expand Down Expand Up @@ -802,15 +808,16 @@ func TestRehashNestedIntersectionType(t *testing.T) {
newTestValue(),
value.(*interpreter.StringValue),
)
})
})()
})

t.Run("dictionary type", func(t *testing.T) {
t.Parallel()

ledger := NewTestLedger(nil, nil)

t.Run("prepare", func(t *testing.T) {
//
(func() {

storage, inter := newStorageAndInterpreter(t, ledger)

Expand Down Expand Up @@ -869,9 +876,10 @@ func TestRehashNestedIntersectionType(t *testing.T) {

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

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t, ledger)

Expand Down Expand Up @@ -912,10 +920,10 @@ func TestRehashNestedIntersectionType(t *testing.T) {
},
reporter.migrated,
)
})

t.Run("load", func(t *testing.T) {
})()

// Load
(func() {
storage, inter := newStorageAndInterpreter(t, ledger)

storageMap := storage.GetStorageMap(testAddress, common.PathDomainStorage.Identifier(), false)
Expand Down Expand Up @@ -948,7 +956,7 @@ func TestRehashNestedIntersectionType(t *testing.T) {
newTestValue(),
value.(*interpreter.StringValue),
)
})
})()
})
}

Expand Down
31 changes: 18 additions & 13 deletions migrations/string_normalization/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ func TestStringValueRehash(t *testing.T) {
return storage, inter
}

t.Run("prepare", func(t *testing.T) {
// Prepare
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -434,9 +435,10 @@ func TestStringValueRehash(t *testing.T) {

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

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand All @@ -456,9 +458,10 @@ func TestStringValueRehash(t *testing.T) {
require.NoError(t, err)

require.Empty(t, reporter.errors)
})
})()

t.Run("load", func(t *testing.T) {
// Load
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -487,7 +490,7 @@ func TestStringValueRehash(t *testing.T) {
newTestValue(),
value.(interpreter.IntValue),
)
})
})()
}

// TestCharacterValueRehash stores a dictionary in storage,
Expand Down Expand Up @@ -525,8 +528,8 @@ func TestCharacterValueRehash(t *testing.T) {
return storage, inter
}

t.Run("prepare", func(t *testing.T) {

// Prepare
(func() {
storage, inter := newStorageAndInterpreter(t)

dictionaryStaticType := interpreter.NewDictionaryStaticType(
Expand Down Expand Up @@ -577,9 +580,10 @@ func TestCharacterValueRehash(t *testing.T) {

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

t.Run("migrate", func(t *testing.T) {
// Migrate
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand All @@ -599,9 +603,10 @@ func TestCharacterValueRehash(t *testing.T) {
require.NoError(t, err)

require.Empty(t, reporter.errors)
})
})()

t.Run("load", func(t *testing.T) {
// Load
(func() {

storage, inter := newStorageAndInterpreter(t)

Expand Down Expand Up @@ -630,7 +635,7 @@ func TestCharacterValueRehash(t *testing.T) {
newTestValue(),
value.(interpreter.IntValue),
)
})
})()
}

func TestCanSkipStringNormalizingMigration(t *testing.T) {
Expand Down

0 comments on commit df308bb

Please sign in to comment.