diff --git a/runtime/contract_test.go b/runtime/contract_test.go index 2c1250f866..f188075382 100644 --- a/runtime/contract_test.go +++ b/runtime/contract_test.go @@ -1060,10 +1060,17 @@ func TestRuntimeContractTryUpdate(t *testing.T) { updateTx := []byte(` transaction { prepare(signer: auth(UpdateContract) &Account) { - signer.contracts.tryUpdate( + let code = "access(all) contract Foo { access(all) fun sayHello(): String {return \"hello\"} }".utf8 + + let deploymentResult = signer.contracts.tryUpdate( name: "Foo", - code: "access(all) contract Foo { access(all) fun sayHello(): String {return \"hello\"} }".utf8, + code: code, ) + + let deployedContract = deploymentResult.deployedContract! + assert(deployedContract.name == "Foo") + assert(deployedContract.address == 0x1) + assert(deployedContract.code == code) } } `) diff --git a/runtime/interpreter/value_deployment_result.go b/runtime/interpreter/value_deployment_result.go index 21e8116b08..c39f2a25ed 100644 --- a/runtime/interpreter/value_deployment_result.go +++ b/runtime/interpreter/value_deployment_result.go @@ -31,7 +31,7 @@ var deploymentResultFieldNames []string = nil func NewDeploymentResultValue( gauge common.MemoryGauge, - deployedContract Value, + deployedContract OptionalValue, ) Value { return NewSimpleCompositeValue( diff --git a/runtime/stdlib/account.go b/runtime/stdlib/account.go index bbd14d105c..57a0071593 100644 --- a/runtime/stdlib/account.go +++ b/runtime/stdlib/account.go @@ -1664,11 +1664,14 @@ func newAccountContractsTryUpdateFunction( } } + var optionalDeployedContract interpreter.OptionalValue if deployedContract == nil { - deployedContract = interpreter.Nil + optionalDeployedContract = interpreter.NilOptionalValue + } else { + optionalDeployedContract = interpreter.NewSomeValueNonCopying(invocation.Interpreter, deployedContract) } - deploymentResult = interpreter.NewDeploymentResultValue(gauge, deployedContract) + deploymentResult = interpreter.NewDeploymentResultValue(gauge, optionalDeployedContract) }() deployedContract = changeAccountContracts(invocation, handler, addressValue, true) diff --git a/runtime/tests/checker/account_test.go b/runtime/tests/checker/account_test.go index 8699daf001..971d74d377 100644 --- a/runtime/tests/checker/account_test.go +++ b/runtime/tests/checker/account_test.go @@ -1110,6 +1110,18 @@ func TestCheckAccountContractsUpdate(t *testing.T) { `) require.NoError(t, err) }) + + t.Run("deployment result fields", func(t *testing.T) { + t.Parallel() + + _, err := ParseAndCheck(t, ` + fun test(contracts: auth(Contracts) &Account.Contracts) { + let deploymentResult: DeploymentResult = contracts.tryUpdate(name: "foo", code: "012".decodeHex()) + let deployedContract: DeployedContract? = deploymentResult.deployedContract + } + `) + require.NoError(t, err) + }) } func TestCheckAccountContractsRemove(t *testing.T) {