Skip to content

Commit

Permalink
Merge branch 'feature/stable-cadence' into bastian/verbose-log-staged…
Browse files Browse the repository at this point in the history
…-update-failures
  • Loading branch information
turbolent committed Apr 12, 2024
2 parents 70204dd + a3493b9 commit 8b748b2
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 142 deletions.
5 changes: 2 additions & 3 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,8 @@ func NewCadence1ContractsMigrations(
log,
rwf,
stagedContractsMigrationOptions,
).WithContractUpdateValidation()

stagedContractsMigration.RegisterContractUpdates(opts.StagedContracts)
).WithContractUpdateValidation().
WithStagedContractUpdates(opts.StagedContracts)

toAccountBasedMigration := func(migration AccountBasedMigration) ledger.Migration {
return NewAccountBasedMigration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func NewSystemContractsMigration(
options.StagedContractsMigrationOptions,
)
for _, change := range SystemContractChanges(options.ChainID, options) {
migration.RegisterContractChange(change)
migration.registerContractChange(change)
}
return migration
}
170 changes: 85 additions & 85 deletions cmd/util/ledger/migrations/change_contract_code_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -54,8 +55,17 @@ type logWriter struct {

var _ io.Writer = &logWriter{}

const errorLogPrefix = "{\"level\":\"error\""

func (l *logWriter) Write(bytes []byte) (int, error) {
l.logs = append(l.logs, string(bytes))
logStr := string(bytes)

// Ignore non-error logs
if !strings.HasPrefix(logStr, errorLogPrefix) {
return 0, nil
}

l.logs = append(l.logs, logStr)
return len(bytes), nil
}

Expand Down Expand Up @@ -154,21 +164,20 @@ func TestChangeContractCodeMigration(t *testing.T) {
ChainID: flow.Emulator,
VerboseErrorOutput: true,
}
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options)
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options).
WithStagedContractUpdates([]migrations.StagedContract{
{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
})

err := migration.InitMigration(log, nil, 0)
require.NoError(t, err)

migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
)

payloads, err := migration.MigrateAccount(
ctx,
common.Address(address1),
Expand Down Expand Up @@ -203,21 +212,20 @@ func TestChangeContractCodeMigration(t *testing.T) {
ChainID: flow.Emulator,
VerboseErrorOutput: true,
}
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options)
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options).
WithStagedContractUpdates([]migrations.StagedContract{
{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
})

err := migration.InitMigration(log, nil, 0)
require.NoError(t, err)

migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
)

payloads, err := migration.MigrateAccount(
ctx,
common.Address(address1),
Expand Down Expand Up @@ -250,30 +258,27 @@ func TestChangeContractCodeMigration(t *testing.T) {
ChainID: flow.Emulator,
VerboseErrorOutput: true,
}
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options)
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options).
WithStagedContractUpdates([]migrations.StagedContract{
{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "B",
Code: []byte(updatedContractB),
},
},
})

err := migration.InitMigration(log, nil, 0)
require.NoError(t, err)

migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
)
migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "B",
Code: []byte(updatedContractB),
},
},
)

payloads, err := migration.MigrateAccount(
ctx,
common.Address(address1),
Expand Down Expand Up @@ -306,21 +311,20 @@ func TestChangeContractCodeMigration(t *testing.T) {
ChainID: flow.Emulator,
VerboseErrorOutput: true,
}
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options)
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options).
WithStagedContractUpdates([]migrations.StagedContract{
{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
})

err := migration.InitMigration(log, nil, 0)
require.NoError(t, err)

migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
)

payloads, err := migration.MigrateAccount(
ctx,
common.Address(address1),
Expand Down Expand Up @@ -357,30 +361,27 @@ func TestChangeContractCodeMigration(t *testing.T) {
ChainID: flow.Emulator,
VerboseErrorOutput: true,
}
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options)
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options).
WithStagedContractUpdates([]migrations.StagedContract{
{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "B",
Code: []byte(updatedContractB),
},
},
})

err := migration.InitMigration(log, nil, 0)
require.NoError(t, err)

migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
)
migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address1),
Contract: migrations.Contract{
Name: "B",
Code: []byte(updatedContractB),
},
},
)

_, err = migration.MigrateAccount(
ctx,
common.Address(address1),
Expand Down Expand Up @@ -410,21 +411,20 @@ func TestChangeContractCodeMigration(t *testing.T) {
ChainID: flow.Emulator,
VerboseErrorOutput: true,
}
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options)
migration := migrations.NewStagedContractsMigration("test", "test", log, rwf, options).
WithStagedContractUpdates([]migrations.StagedContract{
{
Address: common.Address(address2),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
})

err := migration.InitMigration(log, nil, 0)
require.NoError(t, err)

migration.RegisterContractChange(
migrations.StagedContract{
Address: common.Address(address2),
Contract: migrations.Contract{
Name: "A",
Code: []byte(updatedContractA),
},
},
)

_, err = migration.MigrateAccount(
ctx,
common.Address(address1),
Expand Down
Loading

0 comments on commit 8b748b2

Please sign in to comment.