Skip to content

Commit

Permalink
Merge pull request #536 from onflow/feature/stable-cadence
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Dec 18, 2023
2 parents 473f20f + 53d4cdd commit 9116c41
Show file tree
Hide file tree
Showing 26 changed files with 1,103 additions and 359 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ name: CI
# events but only for the master branch
on:
push:
branches: [ master ]
branches:
- master
- 'feature/**'
tags:
- "v*"
pull_request:
branches: [ master ]
branches:
- master
- 'feature/**'

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion convert/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSDKAccountToFlowAndBack(t *testing.T) {

t.Parallel()

contract := []byte("pub contract Test {}")
contract := []byte("access(all) contract Test {}")
var keys []*sdk.AccountKey

keys = append(keys, &sdk.AccountKey{
Expand Down
120 changes: 0 additions & 120 deletions emulator/accountlinking_test.go

This file was deleted.

38 changes: 21 additions & 17 deletions emulator/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/onflow/flow-emulator/emulator"
)

const testContract = "pub contract Test {}"
const testContract = "access(all) contract Test {}"

func setupAccountTests(t *testing.T, opts ...emulator.Option) (
*emulator.Blockchain,
Expand Down Expand Up @@ -361,15 +361,15 @@ func TestCreateAccount(t *testing.T) {
b, adapter := setupAccountTests(t)

codeA := `
pub contract Test1 {
pub fun a(): Int {
access(all) contract Test1 {
access(all) fun a(): Int {
return 1
}
}
`
codeB := `
pub contract Test2 {
pub fun b(): Int {
access(all) contract Test2 {
access(all) fun b(): Int {
return 2
}
}
Expand Down Expand Up @@ -875,16 +875,16 @@ func TestUpdateAccountCode(t *testing.T) {
t.Parallel()

const codeA = `
pub contract Test {
pub fun a(): Int {
access(all) contract Test {
access(all) fun a(): Int {
return 1
}
}
`

const codeB = `
pub contract Test {
pub fun b(): Int {
access(all) contract Test {
access(all) fun b(): Int {
return 2
}
}
Expand Down Expand Up @@ -1027,8 +1027,8 @@ func TestImportAccountCode(t *testing.T) {
{
Name: "Computer",
Source: `
pub contract Computer {
pub fun answer(): Int {
access(all) contract Computer {
access(all) fun answer(): Int {
return 42
}
}
Expand Down Expand Up @@ -1087,7 +1087,7 @@ func TestAccountAccess(t *testing.T) {
{
Name: "A",
Source: `
pub contract A {
access(all) contract A {
access(account) let a: Int
init() {
Expand Down Expand Up @@ -1120,8 +1120,8 @@ func TestAccountAccess(t *testing.T) {
Source: fmt.Sprintf(`
import A from 0x%s
pub contract B {
pub fun use() {
access(all) contract B {
access(all) fun use() {
let b = A.a
}
}
Expand Down Expand Up @@ -1176,8 +1176,8 @@ func TestAccountAccess(t *testing.T) {
Source: fmt.Sprintf(`
import A from 0x%s
pub contract C {
pub fun use() {
access(all) contract C {
access(all) fun use() {
let b = A.a
}
}
Expand Down Expand Up @@ -1208,5 +1208,9 @@ func TestAccountAccess(t *testing.T) {
require.False(t, result.Succeeded())
require.Error(t, result.Error)

require.Contains(t, result.Error.Error(), "error: cannot access `a`: field has account access")
require.Contains(
t,
result.Error.Error(),
"error: cannot access `a`: field requires `account` authorization",
)
}
6 changes: 3 additions & 3 deletions emulator/attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func TestAttachments(t *testing.T) {
require.NoError(t, err)

script := `
pub resource R {}
access(all) resource R {}
pub attachment A for R {}
access(all) attachment A for R {}
pub fun main() {
access(all) fun main() {
let r <- create R()
r[A]
destroy r
Expand Down
2 changes: 1 addition & 1 deletion emulator/block_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestBlockInfo(t *testing.T) {

t.Run("works as script", func(t *testing.T) {
script := []byte(`
pub fun main() {
access(all) fun main() {
let block = getCurrentBlock()
log(block)
Expand Down
8 changes: 3 additions & 5 deletions emulator/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,9 @@ func configureFVM(blockchain *Blockchain, conf config, blocks *blocks) (*fvm.Vir
cadenceLogger := conf.Logger.Hook(CadenceHook{MainLogger: &conf.ServerLogger}).Level(zerolog.DebugLevel)

runtimeConfig := runtime.Config{
Debugger: blockchain.debugger,
AccountLinkingEnabled: true,
AttachmentsEnabled: true,
CapabilityControllersEnabled: true,
CoverageReport: conf.CoverageReport,
Debugger: blockchain.debugger,
AttachmentsEnabled: true,
CoverageReport: conf.CoverageReport,
}
coverageReportedRuntime := &CoverageReportedRuntime{
Runtime: runtime.NewInterpreterRuntime(runtimeConfig),
Expand Down
29 changes: 16 additions & 13 deletions emulator/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ import (

const counterScript = `
pub contract Counting {
access(all) contract Counting {
pub event CountIncremented(count: Int)
access(all) event CountIncremented(count: Int)
pub resource Counter {
pub var count: Int
access(all) resource Counter {
access(all) var count: Int
init() {
self.count = 0
}
pub fun add(_ count: Int) {
access(all) fun add(_ count: Int) {
self.count = self.count + count
emit CountIncremented(count: self.count)
}
}
pub fun createCounter(): @Counter {
access(all) fun createCounter(): @Counter {
return <-create Counter()
}
}
Expand All @@ -69,12 +69,15 @@ func GenerateAddTwoToCounterScript(counterAddress flowsdk.Address) string {
import 0x%s
transaction {
prepare(signer: AuthAccount) {
var counter = signer.borrow<&Counting.Counter>(from: /storage/counter)
prepare(signer: auth(Storage, Capabilities) &Account) {
var counter = signer.storage.borrow<&Counting.Counter>(from: /storage/counter)
if counter == nil {
signer.save(<-Counting.createCounter(), to: /storage/counter)
signer.link<&Counting.Counter>(/public/counter, target: /storage/counter)
counter = signer.borrow<&Counting.Counter>(from: /storage/counter)
signer.storage.save(<-Counting.createCounter(), to: /storage/counter)
counter = signer.storage.borrow<&Counting.Counter>(from: /storage/counter)
// Also publish this for others to borrow.
let cap = signer.capabilities.storage.issue<&Counting.Counter>(/storage/counter)
signer.capabilities.publish(cap, at: /public/counter)
}
counter?.add(2)
}
Expand Down Expand Up @@ -108,8 +111,8 @@ func GenerateGetCounterCountScript(counterAddress flowsdk.Address, accountAddres
`
import 0x%s
pub fun main(): Int {
return getAccount(0x%s).getCapability(/public/counter)!.borrow<&Counting.Counter>()?.count ?? 0
access(all) fun main(): Int {
return getAccount(0x%s).capabilities.borrow<&Counting.Counter>(/public/counter)?.count ?? 0
}
`,
counterAddress,
Expand Down
2 changes: 1 addition & 1 deletion emulator/capcons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCapabilityControllers(t *testing.T) {
require.NoError(t, err)

script := `
pub fun main() {
access(all) fun main() {
getAccount(0x1).capabilities.get
}
`
Expand Down
Loading

0 comments on commit 9116c41

Please sign in to comment.