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

Enable type removal during contract updates #3658

Merged
merged 2 commits into from
Oct 30, 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
2 changes: 0 additions & 2 deletions interpreter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ type Config struct {
CapabilityBorrowHandler CapabilityBorrowHandlerFunc
// LegacyContractUpgradeEnabled specifies whether to fall back to the old parser when attempting a contract upgrade
LegacyContractUpgradeEnabled bool
// ContractUpdateTypeRemovalEnabled specifies if type removal is enabled in contract updates
ContractUpdateTypeRemovalEnabled bool
// ValidateAccountCapabilitiesGetHandler is used to handle when a capability of an account is got.
ValidateAccountCapabilitiesGetHandler ValidateAccountCapabilitiesGetHandlerFunc
// ValidateAccountCapabilitiesPublishHandler is used to handle when a capability of an account is got.
Expand Down
2 changes: 0 additions & 2 deletions runtime/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ type Config struct {
CoverageReport *CoverageReport
// LegacyContractUpgradeEnabled enabled specifies whether to use the old parser when parsing an old contract
LegacyContractUpgradeEnabled bool
// ContractUpdateTypeRemovalEnabled specifies if type removal is enabled in contract updates
ContractUpdateTypeRemovalEnabled bool
}
135 changes: 27 additions & 108 deletions runtime/contract_update_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,31 +195,14 @@ func testWithValidatorsAndTypeRemovalEnabled(
withC1Upgrade := withC1Upgrade
name := name

for _, withTypeRemovalEnabled := range []bool{true, false} {
withTypeRemovalEnabled := withTypeRemovalEnabled
name := name

switch {
case withC1Upgrade && withTypeRemovalEnabled:
name = fmt.Sprintf("%s (with C1 validator and type removal enabled)", name)

case withC1Upgrade:
name = fmt.Sprintf("%s (with C1 validator)", name)

case withTypeRemovalEnabled:
name = fmt.Sprintf("%s (with type removal enabled)", name)
}

t.Run(name, func(t *testing.T) {
t.Parallel()
t.Run(name, func(t *testing.T) {
t.Parallel()

config := DefaultTestInterpreterConfig
config.LegacyContractUpgradeEnabled = withC1Upgrade
config.ContractUpdateTypeRemovalEnabled = withTypeRemovalEnabled
config := DefaultTestInterpreterConfig
config.LegacyContractUpgradeEnabled = withC1Upgrade

testFunc(t, config)
})
}
testFunc(t, config)
})
}
}

Expand Down Expand Up @@ -3248,13 +3231,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.TypeRemovalPragmaRemovalError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.TypeRemovalPragmaRemovalError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand All @@ -3280,13 +3258,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.TypeRemovalPragmaRemovalError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.TypeRemovalPragmaRemovalError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand Down Expand Up @@ -3331,13 +3304,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand All @@ -3360,13 +3328,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand All @@ -3386,14 +3349,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {

var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand All @@ -3413,13 +3370,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.InvalidTypeRemovalPragmaError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand All @@ -3440,13 +3392,7 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
require.NoError(t, err)
} else {
var expectedErr *stdlib.MissingDeclarationError
require.ErrorAs(t, err, &expectedErr)
}
require.NoError(t, err)
},
)

Expand All @@ -3469,13 +3415,7 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
require.NoError(t, err)
} else {
var expectedErr *stdlib.MissingDeclarationError
require.ErrorAs(t, err, &expectedErr)
}
require.NoError(t, err)
},
)

Expand Down Expand Up @@ -3544,13 +3484,7 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
require.NoError(t, err)
} else {
var expectedErr *stdlib.MissingDeclarationError
require.ErrorAs(t, err, &expectedErr)
}
require.NoError(t, err)
},
)

Expand Down Expand Up @@ -3592,13 +3526,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.UseOfRemovedTypeError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.UseOfRemovedTypeError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand All @@ -3620,13 +3549,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.UseOfRemovedTypeError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.UseOfRemovedTypeError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand All @@ -3648,13 +3572,8 @@ func TestTypeRemovalPragmaUpdates(t *testing.T) {
`

err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)

if config.ContractUpdateTypeRemovalEnabled {
var expectedErr *stdlib.UseOfRemovedTypeError
require.ErrorAs(t, err, &expectedErr)
} else {
require.NoError(t, err)
}
var expectedErr *stdlib.UseOfRemovedTypeError
require.ErrorAs(t, err, &expectedErr)
},
)

Expand Down
1 change: 0 additions & 1 deletion runtime/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ func (e *interpreterEnvironment) newInterpreterConfig() *interpreter.Config {
CapabilityBorrowHandler: e.newCapabilityBorrowHandler(),
CapabilityCheckHandler: e.newCapabilityCheckHandler(),
LegacyContractUpgradeEnabled: e.config.LegacyContractUpgradeEnabled,
ContractUpdateTypeRemovalEnabled: e.config.ContractUpdateTypeRemovalEnabled,
ValidateAccountCapabilitiesGetHandler: e.newValidateAccountCapabilitiesGetHandler(),
ValidateAccountCapabilitiesPublishHandler: e.newValidateAccountCapabilitiesPublishHandler(),
}
Expand Down
4 changes: 0 additions & 4 deletions stdlib/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,6 @@ func changeAccountContracts(

memoryGauge := invocation.Interpreter.SharedState.Config.MemoryGauge
legacyUpgradeEnabled := invocation.Interpreter.SharedState.Config.LegacyContractUpgradeEnabled
contractUpdateTypeRemovalEnabled := invocation.Interpreter.SharedState.Config.ContractUpdateTypeRemovalEnabled

var oldProgram *ast.Program

Expand Down Expand Up @@ -1731,9 +1730,6 @@ func changeAccountContracts(
)
}

validator = validator.
WithTypeRemovalEnabled(contractUpdateTypeRemovalEnabled)

err = validator.Validate()
handleContractUpdateError(err, newCode)
}
Expand Down
11 changes: 0 additions & 11 deletions stdlib/cadence_v0.42_to_v1_contract_upgrade_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ func (validator *CadenceV042ToV1ContractUpdateValidator) WithUserDefinedTypeChan
return validator
}

func (validator *CadenceV042ToV1ContractUpdateValidator) isTypeRemovalEnabled() bool {
return validator.underlyingUpdateValidator.isTypeRemovalEnabled()
}

func (validator *CadenceV042ToV1ContractUpdateValidator) WithTypeRemovalEnabled(
enabled bool,
) UpdateValidator {
validator.underlyingUpdateValidator.WithTypeRemovalEnabled(enabled)
return validator
}

func (validator *CadenceV042ToV1ContractUpdateValidator) getCurrentDeclaration() ast.Declaration {
return validator.underlyingUpdateValidator.getCurrentDeclaration()
}
Expand Down
Loading
Loading