Skip to content

Commit

Permalink
update to Cadence 1.0 RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Dec 19, 2023
1 parent e8284d6 commit 6361072
Show file tree
Hide file tree
Showing 11 changed files with 1,052 additions and 223 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ tidy:

test:
@echo "Running tests..."
go test ./...
go test -v ./...
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,34 @@ fmt.Println(prettyJSON)

```go
#interaction(
version: "1.1.0",
title: "Transfer Flow",
description: "Transfer Flow to account",
language: "en-US",
parameters: [
Parameter(
name: "amount",
title: "Amount",
description: "Amount of Flow to transfer"
),
Parameter(
name: "to",
title: "Reciever",
description: "Destination address to receive Flow Tokens"
)
],
)
version: "1.1.0",
title: "Transfer Flow",
description: "Transfer Flow to account",
language: "en-US",
parameters: [
Parameter(
name: "amount",
title: "Amount",
description: "Amount of Flow to transfer"
),
Parameter(
name: "to",
title: "Receiver",
description: "Destination address to receive Flow Tokens"
)
],
)

import "FlowToken"

transaction(amount: UFix64, to: Address) {

let vault: @FlowToken.Vault

import "FlowToken"
transaction(amount: UFix64, to: Address) {
let vault: @FlowToken.Vault
prepare(signer: AuthAccount) {
...
}
prepare(signer: &Account) {
// ...
}
`
}
```

The pragma describes the transaction parameters and reason for the transaction.
21 changes: 11 additions & 10 deletions flixkit/fcl_bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"testing"

"github.com/hexops/autogold/v2"
"github.com/stretchr/testify/assert"

v1 "github.com/onflow/flixkit-go/flixkit/v1"
v1_1 "github.com/onflow/flixkit-go/flixkit/v1_1"
"github.com/onflow/flixkit-go/internal/templates"
"github.com/stretchr/testify/assert"
)

var parsedTemplateTX = &v1.FlowInteractionTemplate{
Expand All @@ -30,7 +31,7 @@ var parsedTemplateTX = &v1.FlowInteractionTemplate{
},
},
},
Cadence: "import FungibleToken from 0xFUNGIBLETOKENADDRESS\ntransaction(amount: UFix64, to: Address) {\nlet vault: @FungibleToken.Vault\nprepare(signer: AuthAccount) {\nself.vault <- signer\n.borrow<&{FungibleToken.Provider}>(from: /storage/flowTokenVault)!\n.withdraw(amount: amount)\n}\nexecute {\ngetAccount(to)\n.getCapability(/public/flowTokenReceiver)!\n.borrow<&{FungibleToken.Receiver}>()!\n.deposit(from: <-self.vault)\n}\n}",
Cadence: "import FungibleToken from 0xFUNGIBLETOKENADDRESS\ntransaction(amount: UFix64, to: Address) {\nlet vault: @FungibleToken.Vault\nprepare(signer: auth(Storage) &Account) {\nself.vault <- signer.storage\n.borrow<&{FungibleToken.Provider}>(from: /storage/flowTokenVault)!\n.withdraw(amount: amount)\n}\nexecute {\ngetAccount(to).capabilities\n.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)!\n.deposit(from: <-self.vault)\n}\n}",
Dependencies: v1.Dependencies{
"0xFUNGIBLETOKENADDRESS": v1.Contracts{
"FungibleToken": v1.Networks{
Expand Down Expand Up @@ -99,7 +100,7 @@ var parsedTemplateScript = &v1.FlowInteractionTemplate{
},
},
},
Cadence: "pub fun main(x: Int, y: Int): Int { return x * y }",
Cadence: "access(all) fun main(x: Int, y: Int): Int { return x * y }",
Arguments: v1.Arguments{
"x": v1.Argument{
Index: 0,
Expand Down Expand Up @@ -148,7 +149,7 @@ var ArrayTypeScript = &v1.FlowInteractionTemplate{
},
},
},
Cadence: "pub fun main(numbers: [Int]): Int { var total = 1; for x in numbers { total = total * x }; return total }",
Cadence: "access(all) fun main(numbers: [Int]): Int { var total = 1; for x in numbers { total = total * x }; return total }",
Arguments: v1.Arguments{
"numbers": v1.Argument{
Index: 0,
Expand All @@ -173,7 +174,7 @@ var minimumTemplate = &v1.FlowInteractionTemplate{
Data: v1.Data{
Type: "script",
Interface: "",
Cadence: "pub fun main(numbers: [Int]): Int { var total = 1; for x in numbers { total = total * x }; return total }",
Cadence: "access(all) fun main(numbers: [Int]): Int { var total = 1; for x in numbers { total = total * x }; return total }",
Arguments: v1.Arguments{
"numbers": v1.Argument{
Index: 0,
Expand All @@ -190,7 +191,7 @@ var minimumNoParamTemplate = &v1.FlowInteractionTemplate{
Data: v1.Data{
Type: "script",
Interface: "",
Cadence: "pub fun main(): Int { return 1 }",
Cadence: "access(all) fun main(): Int { return 1 }",
},
}

Expand Down Expand Up @@ -277,7 +278,7 @@ var minimumNoParamTemplateTS_SCRIPT = &v1_1.InteractionTemplate{
Type: "script",
Interface: "",
Cadence: v1_1.Cadence{
Body: "pub fun main(): Int { return 1 }",
Body: "access(all) fun main(): Int { return 1 }",
NetworkPins: []v1_1.NetworkPin{},
},
Output: &v1_1.Parameter{
Expand Down Expand Up @@ -306,7 +307,7 @@ var minimumNoParamTemplateTS_TX = &v1_1.InteractionTemplate{
Type: "transaction",
Interface: "",
Cadence: v1_1.Cadence{
Body: "import \"HelloWorld\"\n\n#interaction (\n version: \"1.1.0\",\n\ttitle: \"Update Greeting\",\n\tdescription: \"Update the greeting on the HelloWorld contract\",\n\tlanguage: \"en-US\",\n)\ntransaction() {\n\n prepare(acct: AuthAccount) {\n }\n\n execute {\n \n }\n}\n",
Body: "import \"HelloWorld\"\n\n#interaction (\n version: \"1.1.0\",\n\ttitle: \"Update Greeting\",\n\tdescription: \"Update the greeting on the HelloWorld contract\",\n\tlanguage: \"en-US\",\n)\ntransaction() {\n\n prepare(acct: &Account) {\n }\n\n execute {\n \n }\n}\n",
NetworkPins: []v1_1.NetworkPin{},
},
},
Expand All @@ -320,7 +321,7 @@ var minimumParamTemplateTS_SCRIPT = &v1_1.InteractionTemplate{
Type: "script",
Interface: "",
Cadence: v1_1.Cadence{
Body: "pub fun main(someNumber Int): Int { return 1 + someNumber }",
Body: "access(all) fun main(someNumber Int): Int { return 1 + someNumber }",
NetworkPins: []v1_1.NetworkPin{},
},
Parameters: []v1_1.Parameter{
Expand Down Expand Up @@ -367,7 +368,7 @@ var minimumParamTemplateTS_TX = &v1_1.InteractionTemplate{
Type: "transaction",
Interface: "",
Cadence: v1_1.Cadence{
Body: "import \"HelloWorld\"\n\n#interaction (\n version: \"1.1.0\",\n\ttitle: \"Update Greeting\",\n\tdescription: \"Update the greeting on the HelloWorld contract\",\n\tlanguage: \"en-US\",\n\tparameters: [\n\t\tParameter(\n\t\t\tname: \"greeting\", \n\t\t\ttitle: \"Greeting\", \n\t\t\tdescription: \"The greeting to set on the HelloWorld contract\"\n\t\t)\n\t],\n)\ntransaction(greeting: String) {\n\n prepare(acct: AuthAccount) {\n log(acct.address)\n }\n\n execute {\n HelloWorld.updateGreeting(newGreeting: greeting)\n }\n}\n",
Body: "import \"HelloWorld\"\n\n#interaction (\n version: \"1.1.0\",\n\ttitle: \"Update Greeting\",\n\tdescription: \"Update the greeting on the HelloWorld contract\",\n\tlanguage: \"en-US\",\n\tparameters: [\n\t\tParameter(\n\t\t\tname: \"greeting\", \n\t\t\ttitle: \"Greeting\", \n\t\t\tdescription: \"The greeting to set on the HelloWorld contract\"\n\t\t)\n\t],\n)\ntransaction(greeting: String) {\n\n prepare(acct: &Account) {\n log(acct.address)\n }\n\n execute {\n HelloWorld.updateGreeting(newGreeting: greeting)\n }\n}\n",
NetworkPins: []v1_1.NetworkPin{},
},
Messages: []v1_1.Message{
Expand Down
7 changes: 4 additions & 3 deletions flixkit/flixkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"net/http/httptest"
"testing"

v1 "github.com/onflow/flixkit-go/flixkit/v1"
"github.com/stretchr/testify/assert"

v1 "github.com/onflow/flixkit-go/flixkit/v1"
)

var flix_template = `{
Expand All @@ -29,7 +30,7 @@ var flix_template = `{
}
}
},
"cadence": "import FungibleToken from 0xFUNGIBLETOKENADDRESS\ntransaction(amount: UFix64, to: Address) {\nlet vault: @FungibleToken.Vault\nprepare(signer: AuthAccount) {\nself.vault <- signer\n.borrow<&{FungibleToken.Provider}>(from: /storage/flowTokenVault)!\n.withdraw(amount: amount)\n}\nexecute {\ngetAccount(to)\n.getCapability(/public/flowTokenReceiver)!\n.borrow<&{FungibleToken.Receiver}>()!\n.deposit(from: <-self.vault)\n}\n}",
"cadence": "import FungibleToken from 0xFUNGIBLETOKENADDRESS\ntransaction(amount: UFix64, to: Address) {\nlet vault: @FungibleToken.Vault\nprepare(signer: auth(Storage) &Account) {\nself.vault <- signer.storage\n.borrow<&{FungibleToken.Provider}>(from: /storage/flowTokenVault)!\n.withdraw(amount: amount)\n}\nexecute {\ngetAccount(to).capabilities\n.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)!\n.deposit(from: <-self.vault)\n}\n}",
"dependencies": {
"0xFUNGIBLETOKENADDRESS": {
"FungibleToken": {
Expand Down Expand Up @@ -98,7 +99,7 @@ var parsedTemplate = &v1.FlowInteractionTemplate{
},
},
},
Cadence: "import FungibleToken from 0xFUNGIBLETOKENADDRESS\ntransaction(amount: UFix64, to: Address) {\nlet vault: @FungibleToken.Vault\nprepare(signer: AuthAccount) {\nself.vault <- signer\n.borrow<&{FungibleToken.Provider}>(from: /storage/flowTokenVault)!\n.withdraw(amount: amount)\n}\nexecute {\ngetAccount(to)\n.getCapability(/public/flowTokenReceiver)!\n.borrow<&{FungibleToken.Receiver}>()!\n.deposit(from: <-self.vault)\n}\n}",
Cadence: "import FungibleToken from 0xFUNGIBLETOKENADDRESS\ntransaction(amount: UFix64, to: Address) {\nlet vault: @FungibleToken.Vault\nprepare(signer: auth(Storage) &Account) {\nself.vault <- signer.storage\n.borrow<&{FungibleToken.Provider}>(from: /storage/flowTokenVault)!\n.withdraw(amount: amount)\n}\nexecute {\ngetAccount(to)\n.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)!\n.deposit(from: <-self.vault)\n}\n}",
Dependencies: v1.Dependencies{
"0xFUNGIBLETOKENADDRESS": v1.Contracts{
"FungibleToken": v1.Networks{
Expand Down
41 changes: 22 additions & 19 deletions flixkit/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"testing"

"github.com/hexops/autogold/v2"
v1_1 "github.com/onflow/flixkit-go/flixkit/v1_1"
"github.com/onflow/flixkit-go/internal/contracts"
"github.com/onflow/flow-cli/flowkit/config"
"github.com/stretchr/testify/assert"

v1_1 "github.com/onflow/flixkit-go/flixkit/v1_1"
"github.com/onflow/flixkit-go/internal/contracts"
)

func TestHelloScript(t *testing.T) {
Expand Down Expand Up @@ -46,11 +47,12 @@ func TestHelloScript(t *testing.T) {
language: "en-US",
parameters: [],
)
import "HelloWorld"
pub fun main(): String {
return HelloWorld.greeting
access(all)
fun main(): String {
return HelloWorld.greeting
}
`
ctx := context.Background()
Expand Down Expand Up @@ -95,20 +97,21 @@ func TestTransactionValue(t *testing.T) {
language: "en-US",
parameters: [
Parameter(
name: "greeting",
title: "Greeting",
name: "greeting",
title: "Greeting",
description: "The greeting to set on the HelloWorld contract"
)
],
)
import "HelloWorld"
transaction(greeting: String) {
prepare(acct: AuthAccount) {
prepare(acct: &Account) {
log(acct.address)
}
execute {
HelloWorld.updateGreeting(newGreeting: greeting)
}
Expand Down Expand Up @@ -150,24 +153,24 @@ func TestTransferFlowTransaction(t *testing.T) {
language: "en-US",
parameters: [
Parameter(
name: "amount",
title: "Amount",
name: "amount",
title: "Amount",
description: "Amount of Flow to transfer"
),
Parameter(
name: "to",
title: "Reciever",
name: "to",
title: "Receiver",
description: "Destination address to receive Flow Tokens"
)
],
)
import "FlowToken"
transaction(amount: UFix64, to: Address) {
let vault: @FlowToken.Vault
prepare(signer: AuthAccount) {
}
prepare(signer: &Account) {}
}
`
ctx := context.Background()
Expand Down
6 changes: 3 additions & 3 deletions flixkit/testdata/TestHelloScript.golden
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
}
],
"cadence": {
"body": "\n\t#interaction(\n\t\tversion: \"1.1.0\",\n\t\ttitle: \"Say Hello\",\n\t\tdescription: \"Read the greeting from the HelloWorld contract\",\n\t\tlanguage: \"en-US\",\n\t\tparameters: [],\n\t)\n\t\n\timport \"HelloWorld\"\n\n\tpub fun main(): String {\n\treturn HelloWorld.greeting\n\t}\n",
"body": "\n\t#interaction(\n\t\tversion: \"1.1.0\",\n\t\ttitle: \"Say Hello\",\n\t\tdescription: \"Read the greeting from the HelloWorld contract\",\n\t\tlanguage: \"en-US\",\n\t\tparameters: [],\n\t)\n\n\timport \"HelloWorld\"\n\n\taccess(all)\n\tfun main(): String {\n\t\treturn HelloWorld.greeting\n\t}\n",
"network_pins": [
{
"network": "mainnet",
"pin_self": "57d66cd2e8370ef74feec033e768dc460514091fc82ba1b4c42697b600288048"
"pin_self": "ab7702bc218a403fde58f290a89105f5c16d1462e1aedf19a73e2eb6d924245c"
},
{
"network": "testnet",
"pin_self": "57d66cd2e8370ef74feec033e768dc460514091fc82ba1b4c42697b600288048"
"pin_self": "ab7702bc218a403fde58f290a89105f5c16d1462e1aedf19a73e2eb6d924245c"
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions flixkit/testdata/TestTransactionValue.golden
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
}
],
"cadence": {
"body": "\n\t#interaction(\n\t\tversion: \"1.1.0\",\n\t\ttitle: \"Update Greeting\",\n\t\tdescription: \"Update the greeting on the HelloWorld contract\",\n\t\tlanguage: \"en-US\",\n\t\tparameters: [\n\t\t\tParameter(\n\t\t\t\tname: \"greeting\", \n\t\t\t\ttitle: \"Greeting\", \n\t\t\t\tdescription: \"The greeting to set on the HelloWorld contract\"\n\t\t\t)\n\t\t],\n\t)\n\t\n\timport \"HelloWorld\"\n\ttransaction(greeting: String) {\n\t\n\t\tprepare(acct: AuthAccount) {\n\t\t\tlog(acct.address)\n\t\t}\n\t\t\n\t\texecute {\n\t\t\tHelloWorld.updateGreeting(newGreeting: greeting)\n\t\t}\n\t}\n",
"body": "\n\t#interaction(\n\t\tversion: \"1.1.0\",\n\t\ttitle: \"Update Greeting\",\n\t\tdescription: \"Update the greeting on the HelloWorld contract\",\n\t\tlanguage: \"en-US\",\n\t\tparameters: [\n\t\t\tParameter(\n\t\t\t\tname: \"greeting\",\n\t\t\t\ttitle: \"Greeting\",\n\t\t\t\tdescription: \"The greeting to set on the HelloWorld contract\"\n\t\t\t)\n\t\t],\n\t)\n\n\timport \"HelloWorld\"\n\n\ttransaction(greeting: String) {\n\n\t\tprepare(acct: \u0026Account) {\n\t\t\tlog(acct.address)\n\t\t}\n\n\t\texecute {\n\t\t\tHelloWorld.updateGreeting(newGreeting: greeting)\n\t\t}\n\t}\n",
"network_pins": [
{
"network": "mainnet",
"pin_self": "0ad0659f79f7b8336a588e24326c26cf6cf7f74af81c0c8a35ee58e190988af2"
"pin_self": "7a7b3ffbc205913afdd4d48e60a96ad1e5ecd2f2d29c4a1331a72182f63c90ff"
},
{
"network": "testnet",
"pin_self": "0ad0659f79f7b8336a588e24326c26cf6cf7f74af81c0c8a35ee58e190988af2"
"pin_self": "7a7b3ffbc205913afdd4d48e60a96ad1e5ecd2f2d29c4a1331a72182f63c90ff"
}
]
},
Expand Down
10 changes: 5 additions & 5 deletions flixkit/testdata/TestTransferFlowTransaction.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
`{
"f_type": "InteractionTemplate",
"f_version": "1.1.0",
"id": "2233dc61f9e187efe089977e503a68024a6fd1d35e0971d8f36b1016ba032974",
"id": "3279de3e3dbd8ceeddb04b1489debcf03729f07fe5c67ef6dc68f2f6d46310ad",
"data": {
"type": "transaction",
"interface": "",
Expand All @@ -26,15 +26,15 @@
}
],
"cadence": {
"body": "\n\t#interaction(\n\t\tversion: \"1.1.0\",\n\t\ttitle: \"Transfer Flow\",\n\t\tdescription: \"Transfer Flow to account\",\n\t\tlanguage: \"en-US\",\n\t\tparameters: [\n\t\t\tParameter(\n\t\t\t\tname: \"amount\", \n\t\t\t\ttitle: \"Amount\", \n\t\t\t\tdescription: \"Amount of Flow to transfer\"\n\t\t\t),\n\t\t\tParameter(\n\t\t\t\tname: \"to\", \n\t\t\t\ttitle: \"Reciever\", \n\t\t\t\tdescription: \"Destination address to receive Flow Tokens\"\n\t\t\t)\n\t\t],\n\t)\n\t\n\timport \"FlowToken\"\n\ttransaction(amount: UFix64, to: Address) {\n\t\tlet vault: @FlowToken.Vault\n\t\tprepare(signer: AuthAccount) {\n\t\t\n\t\t}\n\t}\n",
"body": "\n\t#interaction(\n\t\tversion: \"1.1.0\",\n\t\ttitle: \"Transfer Flow\",\n\t\tdescription: \"Transfer Flow to account\",\n\t\tlanguage: \"en-US\",\n\t\tparameters: [\n\t\t\tParameter(\n\t\t\t\tname: \"amount\",\n\t\t\t\ttitle: \"Amount\",\n\t\t\t\tdescription: \"Amount of Flow to transfer\"\n\t\t\t),\n\t\t\tParameter(\n\t\t\t\tname: \"to\",\n\t\t\t\ttitle: \"Receiver\",\n\t\t\t\tdescription: \"Destination address to receive Flow Tokens\"\n\t\t\t)\n\t\t],\n\t)\n\n\timport \"FlowToken\"\n\n\ttransaction(amount: UFix64, to: Address) {\n\t\tlet vault: @FlowToken.Vault\n\n\t\tprepare(signer: \u0026Account) {}\n\t}\n",
"network_pins": [
{
"network": "mainnet",
"pin_self": "b11213cf3480f71989f7518791b976cfd80d43c7474495a6d5669b17b77e9346"
"pin_self": "8f51a4190c0b607f96eb65cc88e9335079aa659c4af7c858ef2de0a2171f7c4b"
},
{
"network": "testnet",
"pin_self": "d7c8bddb94f640478b573871dfc2c4e9d090c706ab2a7b8c3e8223e5f7f737be"
"pin_self": "76920dd3758b4ee3ee8a8929d05f3e4067f66a30b272f518a14bba504fefd4b1"
}
]
},
Expand Down Expand Up @@ -100,7 +100,7 @@
"i18n": [
{
"tag": "en-US",
"translation": "Reciever"
"translation": "Receiver"
}
]
},
Expand Down
Loading

0 comments on commit 6361072

Please sign in to comment.