Skip to content

Commit 7ad9a4f

Browse files
committed
Remove legacy contract update
1 parent 5c376e1 commit 7ad9a4f

File tree

6 files changed

+10
-179
lines changed

6 files changed

+10
-179
lines changed

interpreter/config.go

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ type Config struct {
7070
CapabilityCheckHandler CapabilityCheckHandlerFunc
7171
// CapabilityBorrowHandler is used to borrow ID capabilities
7272
CapabilityBorrowHandler CapabilityBorrowHandlerFunc
73-
// LegacyContractUpgradeEnabled specifies whether to fall back to the old parser when attempting a contract upgrade
74-
LegacyContractUpgradeEnabled bool
7573
// ValidateAccountCapabilitiesGetHandler is used to handle when a capability of an account is got.
7674
ValidateAccountCapabilitiesGetHandler ValidateAccountCapabilitiesGetHandlerFunc
7775
// ValidateAccountCapabilitiesPublishHandler is used to handle when a capability of an account is got.

runtime/config.go

-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ type Config struct {
3535
ResourceOwnerChangeHandlerEnabled bool
3636
// CoverageReport enables and collects coverage reporting metrics
3737
CoverageReport *CoverageReport
38-
// LegacyContractUpgradeEnabled enabled specifies whether to use the old parser when parsing an old contract
39-
LegacyContractUpgradeEnabled bool
4038
// StorageFormatV2Enabled specifies whether storage format V2 is enabled
4139
StorageFormatV2Enabled bool
4240
}

runtime/contract_update_test.go

-117
Original file line numberDiff line numberDiff line change
@@ -682,123 +682,6 @@ func TestRuntimeContractRedeploymentInSeparateTransactions(t *testing.T) {
682682
require.NoError(t, err)
683683
}
684684

685-
func TestRuntimeLegacyContractUpdate(t *testing.T) {
686-
t.Parallel()
687-
688-
t.SkipNow()
689-
690-
runtime := NewTestInterpreterRuntimeWithConfig(Config{
691-
AtreeValidationEnabled: true,
692-
LegacyContractUpgradeEnabled: true,
693-
})
694-
695-
accountCodes := map[common.Location][]byte{}
696-
signerAccount := common.MustBytesToAddress([]byte{0x1})
697-
fooLocation := common.AddressLocation{
698-
Address: signerAccount,
699-
Name: "Foo",
700-
}
701-
var checkGetAndSetProgram, getProgramCalled bool
702-
703-
programs := map[Location]*interpreter.Program{}
704-
clearPrograms := func() {
705-
for l := range programs {
706-
delete(programs, l)
707-
}
708-
}
709-
710-
runtimeInterface := &TestRuntimeInterface{
711-
OnGetCode: func(location Location) (bytes []byte, err error) {
712-
return accountCodes[location], nil
713-
},
714-
Storage: NewTestLedger(nil, nil),
715-
OnGetSigningAccounts: func() ([]Address, error) {
716-
return []Address{signerAccount}, nil
717-
},
718-
OnResolveLocation: NewSingleIdentifierLocationResolver(t),
719-
OnGetAccountContractCode: func(location common.AddressLocation) (code []byte, err error) {
720-
return accountCodes[location], nil
721-
},
722-
OnGetAccountContractNames: func(_ Address) ([]string, error) {
723-
return []string{"Foo"}, nil
724-
},
725-
OnUpdateAccountContractCode: func(location common.AddressLocation, code []byte) error {
726-
accountCodes[location] = code
727-
return nil
728-
},
729-
OnEmitEvent: func(event cadence.Event) error {
730-
return nil
731-
},
732-
OnDecodeArgument: func(b []byte, t cadence.Type) (value cadence.Value, err error) {
733-
return json.Decode(nil, b)
734-
},
735-
OnGetAndSetProgram: func(
736-
location Location,
737-
load func() (*interpreter.Program, error),
738-
) (
739-
program *interpreter.Program,
740-
err error,
741-
) {
742-
_, isTransactionLocation := location.(common.TransactionLocation)
743-
if checkGetAndSetProgram && !isTransactionLocation {
744-
require.Equal(t, location, fooLocation)
745-
require.False(t, getProgramCalled)
746-
}
747-
748-
var ok bool
749-
program, ok = programs[location]
750-
if ok {
751-
return
752-
}
753-
754-
program, err = load()
755-
756-
// NOTE: important: still set empty program,
757-
// even if error occurred
758-
759-
programs[location] = program
760-
761-
return
762-
},
763-
}
764-
765-
nextTransactionLocation := NewTransactionLocationGenerator()
766-
767-
const fooContractV1 = `
768-
pub contract Foo {
769-
init() {}
770-
pub fun hello() {}
771-
}
772-
`
773-
774-
const fooContractV2 = `
775-
access(all) contract Foo {
776-
init() {}
777-
access(all) fun hello() {}
778-
}
779-
`
780-
781-
// Mock the deployment of the old 'Foo' contract
782-
accountCodes[fooLocation] = []byte(fooContractV1)
783-
784-
// Programs are only valid during the transaction
785-
clearPrograms()
786-
787-
// Update 'Foo' contract to Cadence 1.0 version
788-
789-
signerAccount = common.MustBytesToAddress([]byte{0x1})
790-
err := runtime.ExecuteTransaction(
791-
Script{
792-
Source: UpdateTransaction("Foo", []byte(fooContractV2)),
793-
},
794-
Context{
795-
Interface: runtimeInterface,
796-
Location: nextTransactionLocation(),
797-
},
798-
)
799-
require.NoError(t, err)
800-
}
801-
802685
func TestRuntimeContractUpdateWithOldProgramError(t *testing.T) {
803686
t.Parallel()
804687

runtime/contract_update_validation_test.go

+10-30
Original file line numberDiff line numberDiff line change
@@ -168,42 +168,23 @@ func testDeployAndRemove(t *testing.T, name string, code string, config Config)
168168
}
169169

170170
func testWithValidators(t *testing.T, name string, testFunc func(t *testing.T, config Config)) {
171-
for _, withC1Upgrade := range []bool{true, false} {
172-
withC1Upgrade := withC1Upgrade
173-
name := name
174-
175-
if withC1Upgrade {
176-
name = fmt.Sprintf("%s (with C1 validator)", name)
177-
}
178-
179-
t.Run(name, func(t *testing.T) {
180-
t.Parallel()
181-
182-
config := DefaultTestInterpreterConfig
183-
config.LegacyContractUpgradeEnabled = withC1Upgrade
184-
testFunc(t, config)
185-
})
186-
}
171+
t.Run(name, func(t *testing.T) {
172+
t.Parallel()
173+
config := DefaultTestInterpreterConfig
174+
testFunc(t, config)
175+
})
187176
}
188177

189178
func testWithValidatorsAndTypeRemovalEnabled(
190179
t *testing.T,
191180
name string,
192181
testFunc func(t *testing.T, config Config),
193182
) {
194-
for _, withC1Upgrade := range []bool{true, false} {
195-
withC1Upgrade := withC1Upgrade
196-
name := name
197-
198-
t.Run(name, func(t *testing.T) {
199-
t.Parallel()
200-
201-
config := DefaultTestInterpreterConfig
202-
config.LegacyContractUpgradeEnabled = withC1Upgrade
203-
204-
testFunc(t, config)
205-
})
206-
}
183+
t.Run(name, func(t *testing.T) {
184+
t.Parallel()
185+
config := DefaultTestInterpreterConfig
186+
testFunc(t, config)
187+
})
207188
}
208189

209190
func TestRuntimeContractUpdateValidation(t *testing.T) {
@@ -2063,7 +2044,6 @@ func TestRuntimeContractUpdateValidation(t *testing.T) {
20632044
`
20642045

20652046
config := DefaultTestInterpreterConfig
2066-
config.LegacyContractUpgradeEnabled = true
20672047
err := testDeployAndUpdate(t, "Test", oldCode, newCode, config)
20682048
require.NoError(t, err)
20692049
})

runtime/environment.go

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ func (e *interpreterEnvironment) NewInterpreterConfig() *interpreter.Config {
195195
OnInvokedFunctionReturn: e.newOnInvokedFunctionReturnHandler(),
196196
CapabilityBorrowHandler: e.newCapabilityBorrowHandler(),
197197
CapabilityCheckHandler: e.newCapabilityCheckHandler(),
198-
LegacyContractUpgradeEnabled: e.config.LegacyContractUpgradeEnabled,
199198
ValidateAccountCapabilitiesGetHandler: e.newValidateAccountCapabilitiesGetHandler(),
200199
ValidateAccountCapabilitiesPublishHandler: e.newValidateAccountCapabilitiesPublishHandler(),
201200
}

stdlib/account.go

-27
Original file line numberDiff line numberDiff line change
@@ -1673,28 +1673,13 @@ func changeAccountContracts(
16731673
handleContractUpdateError(err, newCode)
16741674

16751675
memoryGauge := invocation.InvocationContext
1676-
//legacyUpgradeEnabled := invocation.InvocationContext.SharedState.Config.LegacyContractUpgradeEnabled
1677-
1678-
//var oldProgram *ast.Program
1679-
1680-
// It is not always possible to determine whether the old code is pre-1.0 or not,
1681-
// only based on the parser errors. Therefore, always rely on the flag only.
1682-
// If the legacy contract upgrades are enabled, then use the old parser.
1683-
//if legacyUpgradeEnabled {
1684-
// oldProgram, err = old_parser.ParseProgram(
1685-
// memoryGauge,
1686-
// oldCode,
1687-
// old_parser.Config{},
1688-
// )
1689-
//} else {
16901676
oldProgram, err := parser.ParseProgram(
16911677
memoryGauge,
16921678
oldCode,
16931679
parser.Config{
16941680
IgnoreLeadingIdentifierEnabled: true,
16951681
},
16961682
)
1697-
//}
16981683

16991684
if err != nil && !ignoreUpdatedProgramParserError(err) {
17001685
// NOTE: Errors are usually in the new program / new code,
@@ -1706,25 +1691,13 @@ func changeAccountContracts(
17061691
handleContractUpdateError(err, oldCode)
17071692
}
17081693

1709-
//var validator UpdateValidator
1710-
//if legacyUpgradeEnabled {
1711-
// validator = NewCadenceV042ToV1ContractUpdateValidator(
1712-
// location,
1713-
// contractName,
1714-
// handler,
1715-
// oldProgram,
1716-
// program,
1717-
// inter.AllElaborations(),
1718-
// )
1719-
//} else {
17201694
validator := NewContractUpdateValidator(
17211695
location,
17221696
contractName,
17231697
handler,
17241698
oldProgram,
17251699
program.Program,
17261700
)
1727-
//}
17281701

17291702
err = validator.Validate()
17301703
handleContractUpdateError(err, newCode)

0 commit comments

Comments
 (0)