Skip to content

Commit

Permalink
Wrap deployedContarct with optional. Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Sep 11, 2023
1 parent 741185b commit 41e9f5a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
11 changes: 9 additions & 2 deletions runtime/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
`)
Expand Down
2 changes: 1 addition & 1 deletion runtime/interpreter/value_deployment_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var deploymentResultFieldNames []string = nil

func NewDeploymentResultValue(
gauge common.MemoryGauge,
deployedContract Value,
deployedContract OptionalValue,
) Value {

return NewSimpleCompositeValue(
Expand Down
7 changes: 5 additions & 2 deletions runtime/stdlib/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions runtime/tests/checker/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 41e9f5a

Please sign in to comment.