Skip to content

Commit

Permalink
add test for contract names immutability
Browse files Browse the repository at this point in the history
  • Loading branch information
dsainati1 committed Feb 2, 2022
1 parent 1d6b965 commit 32d59bf
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions runtime/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,45 @@ func TestAuthAccountContracts(t *testing.T) {

assert.IsType(t, &sema.ExternalMutationError{}, errs[0])
})

t.Run("update names through reference", func(t *testing.T) {
t.Parallel()

rt := newTestInterpreterRuntime()

script := []byte(`
transaction {
prepare(signer: AuthAccount) {
var namesRef = &signer.contracts.names as &[String]
namesRef[0] = "baz"
assert(signer.contracts.names[0] == "foo")
}
}
`)

runtimeInterface := &testRuntimeInterface{
getSigningAccounts: func() ([]Address, error) {
return []Address{{42}}, nil
},
getAccountContractNames: func(_ Address) ([]string, error) {
return []string{"foo", "bar"}, nil
},
}

nextTransactionLocation := newTransactionLocationGenerator()

err := rt.ExecuteTransaction(
Script{
Source: script,
},
Context{
Interface: runtimeInterface,
Location: nextTransactionLocation(),
},
)
require.NoError(t, err)
})
}

func TestPublicAccountContracts(t *testing.T) {
Expand Down

0 comments on commit 32d59bf

Please sign in to comment.