Skip to content

Commit

Permalink
Merge pull request #3464 from onflow/bastian/3459-emit-capcon-issue-e…
Browse files Browse the repository at this point in the history
…vents-2
  • Loading branch information
turbolent authored Jul 12, 2024
2 parents 80f0dba + df519bd commit dfa3208
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 73 deletions.
13 changes: 8 additions & 5 deletions migrations/capcons/linkmigration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type LinkMigrationReporter interface {
// LinkValueMigration migrates all links to capability controllers.
type LinkValueMigration struct {
CapabilityMapping *CapabilityMapping
Handler stdlib.CapabilityControllerIssueHandler
IssueHandler stdlib.CapabilityControllerIssueHandler
Handler stdlib.CapabilityControllerHandler
Reporter LinkMigrationReporter
}

Expand Down Expand Up @@ -98,7 +99,7 @@ func (m *LinkValueMigration) Migrate(
}

reporter := m.Reporter
handler := m.Handler
issueHandler := m.IssueHandler

locationRange := interpreter.EmptyLocationRange

Expand Down Expand Up @@ -180,7 +181,7 @@ func (m *LinkValueMigration) Migrate(
capabilityID, _ = stdlib.IssueStorageCapabilityController(
inter,
locationRange,
handler,
issueHandler,
accountAddress,
borrowType,
targetPath,
Expand All @@ -190,7 +191,7 @@ func (m *LinkValueMigration) Migrate(
capabilityID, _ = stdlib.IssueAccountCapabilityController(
inter,
locationRange,
handler,
issueHandler,
accountAddress,
borrowType,
)
Expand Down Expand Up @@ -253,6 +254,7 @@ func (m *LinkValueMigration) getPathCapabilityFinalTarget(
authorization interpreter.Authorization,
err error,
) {
handler := m.Handler

locationRange := interpreter.EmptyLocationRange

Expand Down Expand Up @@ -342,11 +344,12 @@ func (m *LinkValueMigration) getPathCapabilityFinalTarget(
// just get target address/path
reference := stdlib.GetCheckedCapabilityControllerReference(
inter,
locationRange,
value.Address,
value.ID,
wantedBorrowType,
capabilityBorrowType,
locationRange,
handler,
)
if reference == nil {
return nil, interpreter.UnauthorizedAccess, nil
Expand Down
22 changes: 13 additions & 9 deletions migrations/capcons/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ import (
"github.com/onflow/cadence/runtime/tests/utils"
)

type testCapConIssueHandler struct {
type testCapConHandler struct {
ids map[common.Address]uint64
events []cadence.Event
}

var _ stdlib.CapabilityControllerIssueHandler = &testCapConIssueHandler{}
var _ stdlib.CapabilityControllerIssueHandler = &testCapConHandler{}

func (g *testCapConIssueHandler) GenerateAccountID(address common.Address) (uint64, error) {
func (g *testCapConHandler) GenerateAccountID(address common.Address) (uint64, error) {
if g.ids == nil {
g.ids = make(map[common.Address]uint64)
}
g.ids[address]++
return g.ids[address], nil
}

func (g *testCapConIssueHandler) EmitEvent(
func (g *testCapConHandler) EmitEvent(
inter *interpreter.Interpreter,
locationRange interpreter.LocationRange,
eventType *sema.CompositeType,
values []interpreter.Value,
locationRange interpreter.LocationRange,
) {
runtime.EmitEventFields(
inter,
Expand Down Expand Up @@ -489,13 +489,14 @@ func testPathCapabilityValueMigration(

capabilityMapping := &CapabilityMapping{}

handler := &testCapConIssueHandler{}
handler := &testCapConHandler{}

migration.Migrate(
migration.NewValueMigrationsPathMigrator(
reporter,
&LinkValueMigration{
CapabilityMapping: capabilityMapping,
IssueHandler: handler,
Handler: handler,
Reporter: reporter,
},
Expand Down Expand Up @@ -1480,13 +1481,14 @@ func testLinkMigration(

capabilityMapping := &CapabilityMapping{}

handler := &testCapConIssueHandler{}
handler := &testCapConHandler{}

migration.Migrate(
migration.NewValueMigrationsPathMigrator(
reporter,
&LinkValueMigration{
CapabilityMapping: capabilityMapping,
IssueHandler: handler,
Handler: handler,
Reporter: reporter,
},
Expand Down Expand Up @@ -2301,13 +2303,14 @@ func TestPublishedPathCapabilityValueMigration(t *testing.T) {

capabilityMapping := &CapabilityMapping{}

handler := &testCapConIssueHandler{}
handler := &testCapConHandler{}

migration.Migrate(
migration.NewValueMigrationsPathMigrator(
reporter,
&LinkValueMigration{
CapabilityMapping: capabilityMapping,
IssueHandler: handler,
Handler: handler,
Reporter: reporter,
},
Expand Down Expand Up @@ -2551,13 +2554,14 @@ func TestUntypedPathCapabilityValueMigration(t *testing.T) {

capabilityMapping := &CapabilityMapping{}

handler := &testCapConIssueHandler{}
handler := &testCapConHandler{}

migration.Migrate(
migration.NewValueMigrationsPathMigrator(
reporter,
&LinkValueMigration{
CapabilityMapping: capabilityMapping,
IssueHandler: handler,
Handler: handler,
Reporter: reporter,
},
Expand Down
Loading

0 comments on commit dfa3208

Please sign in to comment.