/
migrator.go
61 lines (49 loc) · 1.18 KB
/
migrator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package setup
import (
appmigrations "github.com/cheqd/cheqd-node/app/migrations"
didtypes "github.com/cheqd/cheqd-node/x/did/types"
resourcetypes "github.com/cheqd/cheqd-node/x/resource/types"
)
type Migrator struct {
setup TestSetup
migrations []appmigrations.Migration
existingDataset ExistingDataset
expectedDataset ExpectedDataset
}
func NewMigrator(
setup TestSetup,
migrations []appmigrations.Migration,
existingDataset ExistingDataset,
expectedDataset ExpectedDataset,
) Migrator {
return Migrator{
setup: setup,
migrations: migrations,
existingDataset: existingDataset,
expectedDataset: expectedDataset,
}
}
func (m Migrator) Run() error {
err := m.existingDataset.FillStore()
if err != nil {
return err
}
migrationCtx := appmigrations.NewMigrationContext(
m.setup.Cdc,
m.setup.DidStoreKey,
getSubspace(didtypes.ModuleName, m.setup.ParamsKeeper),
m.setup.ResourceStoreKey,
getSubspace(resourcetypes.ModuleName, m.setup.ParamsKeeper),
)
for _, migration := range m.migrations {
err := migration(m.setup.SdkCtx, migrationCtx)
if err != nil {
return err
}
}
err = m.expectedDataset.CheckStore()
if err != nil {
return err
}
return nil
}