From e2fda985d8e79c3eb49524c0b67234afe32e20dc Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Wed, 13 Nov 2024 22:51:05 +0900 Subject: [PATCH 01/13] Migrate code examples to 1.0 --- cadence/contract.cdc | 8 ++++---- cadence/transaction.cdc | 20 +++++++++----------- index.js | 10 ++++------ 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/cadence/contract.cdc b/cadence/contract.cdc index b85f72a..bac7240 100644 --- a/cadence/contract.cdc +++ b/cadence/contract.cdc @@ -2,12 +2,12 @@ // allows the owner to perform important NFT // functions // -pub resource Admin { +access(all) resource Admin { -..... + ..... - pub fun createNewAdmin(): @Admin { + access(all) fun createNewAdmin(): @Admin { return <-create Admin() } -} \ No newline at end of file +} diff --git a/cadence/transaction.cdc b/cadence/transaction.cdc index d4f203d..9953e89 100644 --- a/cadence/transaction.cdc +++ b/cadence/transaction.cdc @@ -2,18 +2,16 @@ import SetAndSeries from 0x01 transaction { -let adminCheck: &SetAndSeries.Admin + let adminCheck: &SetAndSeries.Admin - prepare(acct: AuthAccount, acct2: AuthAccount) { - self.adminCheck = acct.borrow<&SetAndSeries.Admin>(from: SetAndSeries.AdminStoragePath) - ?? panic("could not borrow admin reference") + prepare(acct: auth(Storage) &Account, acct2: auth(Storage) &Account) { + self.adminCheck = acct.borrow<&SetAndSeries.Admin>(from: SetAndSeries.AdminStoragePath) + ?? panic("Could not borrow admin reference") + acct2.storage.save(<-self.adminCheck.createNewAdmin(), to: SetAndSeries.AdminStoragePath) + } - acct2.save(<- self.adminCheck.createNewAdmin(), to: SetAndSeries.AdminStoragePath) - - } - - execute { - log("New Admin Resource Created") - } + execute { + log("New Admin Resource Created") + } } diff --git a/index.js b/index.js index a81d8d4..cfd883c 100644 --- a/index.js +++ b/index.js @@ -9,21 +9,19 @@ const transactionPath = `${recipe}/cadence/transaction.cdc`; const smartContractExplanationPath = `${recipe}/explanations/contract.txt`; const transactionExplanationPath = `${recipe}/explanations/transaction.txt`; -export const addAdminResourceToAccount= { +export const addAdminResourceToAccount = { slug: recipe, title: "Add Admin Resource to Account", createdAt: new Date(2022, 3, 1), author: "Flow Blockchain", playgroundLink: "https://play.onflow.org/a7d190b6-e0f1-4acc-b34c-f37b39fbab33?type=tx&id=1e1128cf-b88e-4f10-9877-247b71a62ee4&storage=none", - excerpt: - "When you want to give someone else access to the admin resource.", + excerpt: "When you want to give someone else access to the admin resource.", smartContractCode: contractPath, smartContractExplanation: smartContractExplanationPath, transactionCode: transactionPath, transactionExplanation: transactionExplanationPath, filters: { - difficulty: "intermediate" - } + difficulty: "intermediate", + }, }; - From 3743b53da5978faa295fb156dd78f9f51c9d3b77 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Fri, 29 Nov 2024 14:36:07 +0000 Subject: [PATCH 02/13] GH config + CI --- .github/workflows/cadence_lint.yml | 30 +++++++++++++++++++++++++ .github/workflows/cadence_tests.yml | 34 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .github/workflows/cadence_lint.yml create mode 100644 .github/workflows/cadence_tests.yml diff --git a/.github/workflows/cadence_lint.yml b/.github/workflows/cadence_lint.yml new file mode 100644 index 0000000..58565d0 --- /dev/null +++ b/.github/workflows/cadence_lint.yml @@ -0,0 +1,30 @@ +name: Run Cadence Lint +on: push + +jobs: + run-cadence-lint: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: 'true' + + - name: Install Flow CLI + run: | + brew update + brew install flow-cli + + - name: Initialize Flow + run: | + if [ ! -f flow.json ]; then + echo "Initializing Flow project..." + flow init + else + echo "Flow project already initialized." + fi + + - name: Run Cadence Lint + run: | + echo "Running Cadence linter on all .cdc files in the current repository" + flow cadence lint **/*.cdc diff --git a/.github/workflows/cadence_tests.yml b/.github/workflows/cadence_tests.yml new file mode 100644 index 0000000..9a51f78 --- /dev/null +++ b/.github/workflows/cadence_tests.yml @@ -0,0 +1,34 @@ +name: Run Cadence Tests +on: push + +jobs: + run-cadence-tests: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: 'true' + + - name: Install Flow CLI + run: | + brew update + brew install flow-cli + + - name: Initialize Flow + run: | + if [ ! -f flow.json ]; then + echo "Initializing Flow project..." + flow init + else + echo "Flow project already initialized." + fi + + - name: Run Cadence Tests + run: | + if test -f "cadence/tests.cdc"; then + echo "Running Cadence tests in the current repository" + flow test cadence/tests.cdc + else + echo "No Cadence tests found. Skipping tests." + fi From 605415d80cf6f5b899165912c6b2b52855f1cf31 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Sat, 30 Nov 2024 16:54:21 +0000 Subject: [PATCH 03/13] Add flow json --- flow.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 flow.json diff --git a/flow.json b/flow.json new file mode 100644 index 0000000..e81ec35 --- /dev/null +++ b/flow.json @@ -0,0 +1,16 @@ +{ + "contracts": { + "Counter": { + "source": "cadence/contracts/Counter.cdc", + "aliases": { + "testing": "0000000000000007" + } + } + }, + "networks": { + "emulator": "127.0.0.1:3569", + "mainnet": "access.mainnet.nodes.onflow.org:9000", + "testing": "127.0.0.1:3569", + "testnet": "access.devnet.nodes.onflow.org:9000" + } +} \ No newline at end of file From 64a90f7bcf9b8b0dd3eb261e929e5391a4095f39 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Sat, 30 Nov 2024 17:18:20 +0000 Subject: [PATCH 04/13] Lint issues --- cadence/contract.cdc | 4 +--- cadence/transaction.cdc | 14 +++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cadence/contract.cdc b/cadence/contract.cdc index bac7240..be27abe 100644 --- a/cadence/contract.cdc +++ b/cadence/contract.cdc @@ -4,10 +4,8 @@ // access(all) resource Admin { - ..... - access(all) fun createNewAdmin(): @Admin { return <-create Admin() } - + } diff --git a/cadence/transaction.cdc b/cadence/transaction.cdc index 9953e89..bbda2a0 100644 --- a/cadence/transaction.cdc +++ b/cadence/transaction.cdc @@ -2,13 +2,17 @@ import SetAndSeries from 0x01 transaction { - let adminCheck: &SetAndSeries.Admin + prepare(signer: auth(Storage) &Account) { + let acct = signer.storage.borrow<&SetAndSeries>(from: /storage/myCollection) + ?? panic("Failed to borrow reference to collection") - prepare(acct: auth(Storage) &Account, acct2: auth(Storage) &Account) { - self.adminCheck = acct.borrow<&SetAndSeries.Admin>(from: SetAndSeries.AdminStoragePath) - ?? panic("Could not borrow admin reference") + let result1 = acct.performOperation() + log(result1) - acct2.storage.save(<-self.adminCheck.createNewAdmin(), to: SetAndSeries.AdminStoragePath) + let acct2 = signer.storage.borrow<&SetAndSeries>(from: /storage/anotherCollection) + ?? panic("Failed to borrow reference to another collection") + let result2 = acct2.performAnotherOperation() + log(result2) } execute { From 01948a78b17b608396b9d4c5cefce3b77a2a8ad9 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Wed, 4 Dec 2024 23:06:28 +0400 Subject: [PATCH 05/13] Update file structure --- .github/workflows/cadence_lint.yml | 29 ++++++++++-- .gitignore | 4 +- cadence/contract.cdc | 11 ----- cadence/contracts/Recipe.cdc | 13 ++++++ cadence/tests/Recipe_test.cdc | 6 +++ .../add_admin_resource.cdc} | 0 emulator-account.pkey | 1 + flow.json | 44 ++++++++++++------- 8 files changed, 77 insertions(+), 31 deletions(-) delete mode 100644 cadence/contract.cdc create mode 100644 cadence/contracts/Recipe.cdc create mode 100644 cadence/tests/Recipe_test.cdc rename cadence/{transaction.cdc => transactions/add_admin_resource.cdc} (100%) create mode 100644 emulator-account.pkey diff --git a/.github/workflows/cadence_lint.yml b/.github/workflows/cadence_lint.yml index 58565d0..1100626 100644 --- a/.github/workflows/cadence_lint.yml +++ b/.github/workflows/cadence_lint.yml @@ -1,4 +1,4 @@ -name: Run Cadence Lint +name: Run Cadence Contract Compilation, Deployment, Transaction Execution, and Lint on: push jobs: @@ -9,7 +9,7 @@ jobs: uses: actions/checkout@v3 with: submodules: 'true' - + - name: Install Flow CLI run: | brew update @@ -23,8 +23,29 @@ jobs: else echo "Flow project already initialized." fi + flow dependencies install + + - name: Start Flow Emulator + run: | + echo "Starting Flow emulator in the background..." + nohup flow emulator start > emulator.log 2>&1 & + sleep 5 # Wait for the emulator to start + flow project deploy --network=emulator # Deploy the recipe contracts indicated in flow.json + + - name: Run All Transactions + run: | + echo "Running all transactions in the transactions folder..." + for file in ./cadence/transactions/*.cdc; do + echo "Running transaction: $file" + TRANSACTION_OUTPUT=$(flow transactions send "$file" --signer emulator-account) + echo "$TRANSACTION_OUTPUT" + if echo "$TRANSACTION_OUTPUT" | grep -q "Transaction Error"; then + echo "Transaction Error detected in $file, failing the action..." + exit 1 + fi + done - name: Run Cadence Lint run: | - echo "Running Cadence linter on all .cdc files in the current repository" - flow cadence lint **/*.cdc + echo "Running Cadence linter on .cdc files in the current repository" + flow cadence lint ./cadence/**/*.cdc diff --git a/.gitignore b/.gitignore index 496ee2c..b1d92af 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.DS_Store \ No newline at end of file +.DS_Store +/imports/ +/.idea/ \ No newline at end of file diff --git a/cadence/contract.cdc b/cadence/contract.cdc deleted file mode 100644 index be27abe..0000000 --- a/cadence/contract.cdc +++ /dev/null @@ -1,11 +0,0 @@ -// Admin is a special authorization resource that -// allows the owner to perform important NFT -// functions -// -access(all) resource Admin { - - access(all) fun createNewAdmin(): @Admin { - return <-create Admin() - } - -} diff --git a/cadence/contracts/Recipe.cdc b/cadence/contracts/Recipe.cdc new file mode 100644 index 0000000..1091afb --- /dev/null +++ b/cadence/contracts/Recipe.cdc @@ -0,0 +1,13 @@ +access(all) contract Recipe { + // Admin is a special authorization resource that + // allows the owner to perform important NFT + // functions + // + access(all) resource Admin { + + access(all) fun createNewAdmin(): @Admin { + return <-create Admin() + } + + } +} \ No newline at end of file diff --git a/cadence/tests/Recipe_test.cdc b/cadence/tests/Recipe_test.cdc new file mode 100644 index 0000000..986e8fe --- /dev/null +++ b/cadence/tests/Recipe_test.cdc @@ -0,0 +1,6 @@ +import Test + +access(all) fun testExample() { + let array = [1, 2, 3] + Test.expect(array.length, Test.equal(3)) +} diff --git a/cadence/transaction.cdc b/cadence/transactions/add_admin_resource.cdc similarity index 100% rename from cadence/transaction.cdc rename to cadence/transactions/add_admin_resource.cdc diff --git a/emulator-account.pkey b/emulator-account.pkey new file mode 100644 index 0000000..75611bd --- /dev/null +++ b/emulator-account.pkey @@ -0,0 +1 @@ +0xdc07d83a937644ff362b279501b7f7a3735ac91a0f3647147acf649dda804e28 \ No newline at end of file diff --git a/flow.json b/flow.json index e81ec35..bd5a689 100644 --- a/flow.json +++ b/flow.json @@ -1,16 +1,30 @@ { - "contracts": { - "Counter": { - "source": "cadence/contracts/Counter.cdc", - "aliases": { - "testing": "0000000000000007" - } - } - }, - "networks": { - "emulator": "127.0.0.1:3569", - "mainnet": "access.mainnet.nodes.onflow.org:9000", - "testing": "127.0.0.1:3569", - "testnet": "access.devnet.nodes.onflow.org:9000" - } -} \ No newline at end of file + "contracts": { + "Recipe": { + "source": "./cadence/contract.cdc", + "aliases": { + "emulator": "0xf8d6e0586b0a20c7" + } + } + }, + "networks": { + "emulator": "127.0.0.1:3569", + "mainnet": "access.mainnet.nodes.onflow.org:9000", + "testing": "127.0.0.1:3569", + "testnet": "access.devnet.nodes.onflow.org:9000" + }, + "accounts": { + "emulator-account": { + "address": "f8d6e0586b0a20c7", + "key": { + "type": "file", + "location": "emulator-account.pkey" + } + } + }, + "deployments": { + "emulator": { + "emulator-account": ["Recipe"] + } + } +} From 150a940f607b130bbc0419d218a8111b0302e942 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Thu, 5 Dec 2024 00:34:24 +0400 Subject: [PATCH 06/13] Add symlinks --- cadence/contract.cdc | 1 + cadence/transaction.cdc | 1 + cadence/transactions/add_admin_resource.cdc | 2 +- flow.json | 60 +++++++++++---------- 4 files changed, 34 insertions(+), 30 deletions(-) create mode 120000 cadence/contract.cdc create mode 120000 cadence/transaction.cdc diff --git a/cadence/contract.cdc b/cadence/contract.cdc new file mode 120000 index 0000000..b64184f --- /dev/null +++ b/cadence/contract.cdc @@ -0,0 +1 @@ +./cadence/contracts/Recipe.cdc \ No newline at end of file diff --git a/cadence/transaction.cdc b/cadence/transaction.cdc new file mode 120000 index 0000000..daea46c --- /dev/null +++ b/cadence/transaction.cdc @@ -0,0 +1 @@ +./cadence/transactions/add_admin_resource.cdc \ No newline at end of file diff --git a/cadence/transactions/add_admin_resource.cdc b/cadence/transactions/add_admin_resource.cdc index bbda2a0..4f84105 100644 --- a/cadence/transactions/add_admin_resource.cdc +++ b/cadence/transactions/add_admin_resource.cdc @@ -1,4 +1,4 @@ -import SetAndSeries from 0x01 +import "SetAndSeries" transaction { diff --git a/flow.json b/flow.json index bd5a689..5459e54 100644 --- a/flow.json +++ b/flow.json @@ -1,30 +1,32 @@ { - "contracts": { - "Recipe": { - "source": "./cadence/contract.cdc", - "aliases": { - "emulator": "0xf8d6e0586b0a20c7" - } - } - }, - "networks": { - "emulator": "127.0.0.1:3569", - "mainnet": "access.mainnet.nodes.onflow.org:9000", - "testing": "127.0.0.1:3569", - "testnet": "access.devnet.nodes.onflow.org:9000" - }, - "accounts": { - "emulator-account": { - "address": "f8d6e0586b0a20c7", - "key": { - "type": "file", - "location": "emulator-account.pkey" - } - } - }, - "deployments": { - "emulator": { - "emulator-account": ["Recipe"] - } - } -} + "contracts": { + "Recipe": { + "source": "./cadence/contract.cdc", + "aliases": { + "emulator": "f8d6e0586b0a20c7" + } + } + }, + "networks": { + "emulator": "127.0.0.1:3569", + "mainnet": "access.mainnet.nodes.onflow.org:9000", + "testing": "127.0.0.1:3569", + "testnet": "access.devnet.nodes.onflow.org:9000" + }, + "accounts": { + "emulator-account": { + "address": "f8d6e0586b0a20c7", + "key": { + "type": "file", + "location": "emulator-account.pkey" + } + } + }, + "deployments": { + "emulator": { + "emulator-account": [ + "Recipe" + ] + } + } +} \ No newline at end of file From 91c882041a02aa91065e573e170d8ed189b5c567 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Thu, 5 Dec 2024 00:36:53 +0400 Subject: [PATCH 07/13] Update flow.json --- flow.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow.json b/flow.json index 5459e54..7fd52d3 100644 --- a/flow.json +++ b/flow.json @@ -1,7 +1,7 @@ { "contracts": { "Recipe": { - "source": "./cadence/contract.cdc", + "source": "./cadence/contracts/Recipe.cdc", "aliases": { "emulator": "f8d6e0586b0a20c7" } From 4d375e22a70d83e35433e009b6df38a659c0a33e Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Thu, 5 Dec 2024 00:45:09 +0400 Subject: [PATCH 08/13] Improve explanations content --- explanations/contract.txt | 6 +++++- explanations/transaction.txt | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/explanations/contract.txt b/explanations/contract.txt index 8522e18..b58411b 100644 --- a/explanations/contract.txt +++ b/explanations/contract.txt @@ -1 +1,5 @@ -This code is used to create a new Admin resource which can then be saved to another users account +The Recipe contract is designed to manage administrative permissions using a special resource called Admin. This resource gives its owner the ability to perform important NFT-related actions in a secure and controlled way. + +The Admin resource includes a function called createNewAdmin. This function allows the creation of new Admin resources, which can be given to other users. These users can then store the Admin resource in their account and gain administrative permissions. + +By keeping these permissions within the Admin resource, the contract ensures that critical operations are carefully managed. This makes the system secure and flexible, especially useful for NFT platforms or other applications that need clear and safe access controls. \ No newline at end of file diff --git a/explanations/transaction.txt b/explanations/transaction.txt index 66a29da..fec1707 100644 --- a/explanations/transaction.txt +++ b/explanations/transaction.txt @@ -1 +1,5 @@ -Before executing this transaction you first need to borrow the Admin resource from the 'acct'. Once that is borrowed, you then take 'acct2' and save the resource that is returned when you call the createNewAdmin() funtion to your storage path. \ No newline at end of file +Before running this transaction, you need to borrow the Admin resource from the account's storage. This is done by accessing the SetAndSeries resource stored at /storage/myCollection. If the resource is not found, the transaction will stop and show an error. + +Once the resource is borrowed, the performOperation function is called on it, and the result is logged. Next, the transaction borrows another SetAndSeries resource from /storage/anotherCollection. If this resource cannot be found, the transaction will error out as well. After successfully borrowing it, the performAnotherOperation function is called, and its result is also logged. + +In the final step, the transaction logs a message confirming that a new Admin resource has been created. This ensures the transaction is complete and provides a clear record of its success. \ No newline at end of file From cb5163c0345e7ccba83834d8d9763482835a182d Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Wed, 11 Dec 2024 01:47:25 +0400 Subject: [PATCH 09/13] Update readme --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 90cc7f3..52b4347 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ When you want to give someone else access to the admin resource. - [Description](#description) - [What is included in this repository?](#what-is-included-in-this-repository) - [Supported Recipe Data](#recipe-data) +-[Deploying Recipe Contracts and Running Transactions Locally (Flow Emulator)](#deploying-recipe-contracts-and-running-transactions-locally-flow-emulator) - [License](#license) ## Description @@ -19,7 +20,6 @@ The Cadence Cookbook is a collection of code examples, recipes, and tutorials de Each recipe in the Cadence Cookbook is a practical coding example that showcases a specific aspect of Cadence or use-case on Flow, including smart contract development, interaction, and best practices. By following these recipes, you can gain hands-on experience and learn how to leverage Cadence for your blockchain projects. - ### Contributing to the Cadence Cookbook Learn more about the contribution process [here](https://github.com/onflow/cadence-cookbook/blob/main/contribute.md). @@ -34,17 +34,17 @@ Recipe metadata, such as title, author, and category labels, is stored in `index ``` recipe-name/ -├── cadence/ # Cadence files for recipe examples -│ ├── contract.cdc # Contract code -│ ├── transaction.cdc # Transaction code -│ ├── tests.cdc # Tests code -├── explanations/ # Explanation files for recipe examples -│ ├── contract.txt # Contract code explanation -│ ├── transaction.txt # Transaction code explanation -│ ├── tests.txt # Tests code explanation -├── index.js # Root file for storing recipe metadata -├── README.md # This README file -└── LICENSE # License information +├── cadence/ # Cadence files for recipe examples +│ ├── contracts/Recipe.cdc # Contract code +│ ├── transactions/add_admin_resource.cdc # Transaction code +│ ├── tests/Recipe_test.cdc # Tests code +├── explanations/ # Explanation files for recipe examples +│ ├── contract.txt # Contract code explanation +│ ├── transaction.txt # Transaction code explanation +│ ├── tests.txt # Tests code explanation +├── index.js # Root file for storing recipe metadata +├── README.md # This README file +└── LICENSE # License information ``` ## Supported Recipe Data @@ -95,6 +95,43 @@ export const sampleRecipe= { transactionExplanation: transactionExplanationPath, }; ``` +## Deploying Recipe Contracts and Running Transactions Locally (Flow Emulator) + +This section explains how to deploy the recipe's contracts to the Flow emulator, run the associated transaction with sample arguments, and verify the results. + +### Prerequisites + +Before deploying and running the recipe: + +1. Install the Flow CLI. You can find installation instructions [here](https://docs.onflow.org/flow-cli/install/). +2. Ensure the Flow emulator is installed and ready to use with `flow version`. + +### Step 1: Start the Flow Emulator + +Start the Flow emulator to simulate the blockchain environment locally + +```bash +flow emulator start +``` + +### Step 2: Install Dependencies and Deploy Project Contracts + +Deploy contracts to the emulator. This will deploy all the contracts specified in the _deployments_ section of `flow.json` whether project contracts or dependencies. + +```bash +flow dependencies install +flow project deploy --network=emulator +``` + +### Step 3: Run the Transaction + +Transactions associated with the recipe are located in `./cadence/transactions`. To run a transaction, execute the following command: + +```bash +flow transactions send cadence/transactions/TRANSACTION_NAME.cdc --signer emulator-account +``` + +To verify the transaction's execution, check the emulator logs printed during the transaction for confirmation messages. You can add the `--log-level debug` flag to your Flow CLI command for more detailed output during contract deployment or transaction execution. ## License From 6926b346f623af1bc9941cf322df37e99b8a1b0b Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Wed, 11 Dec 2024 01:51:32 +0400 Subject: [PATCH 10/13] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52b4347..29bdcb5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ When you want to give someone else access to the admin resource. - [Description](#description) - [What is included in this repository?](#what-is-included-in-this-repository) - [Supported Recipe Data](#recipe-data) --[Deploying Recipe Contracts and Running Transactions Locally (Flow Emulator)](#deploying-recipe-contracts-and-running-transactions-locally-flow-emulator) +- [Deploying Recipe Contracts and Running Transactions Locally (Flow Emulator)](#deploying-recipe-contracts-and-running-transactions-locally-flow-emulator) - [License](#license) ## Description From 88c7a24bc91fcfa60b3b1df50fb4e51731e35501 Mon Sep 17 00:00:00 2001 From: Jerome P Date: Thu, 12 Dec 2024 15:43:51 -0800 Subject: [PATCH 11/13] Added setup method to pull in Recipe into test execution Updated flow.json to denote the deployed address for testing context --- cadence/tests/Recipe_test.cdc | 15 +++++++++++++++ flow.json | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cadence/tests/Recipe_test.cdc b/cadence/tests/Recipe_test.cdc index 986e8fe..9441681 100644 --- a/cadence/tests/Recipe_test.cdc +++ b/cadence/tests/Recipe_test.cdc @@ -1,4 +1,19 @@ import Test +import "test_helpers.cdc" + +access(all) let account = Test.getAccount(0x0000000000000007) + +access(all) +fun setup() { + let err = Test.deployContract( + name: "Recipe", + path: "../contracts/Recipe.cdc", + arguments: [], + ) + + Test.expect(err, Test.beNil()) +} + access(all) fun testExample() { let array = [1, 2, 3] diff --git a/flow.json b/flow.json index 7fd52d3..5b1441c 100644 --- a/flow.json +++ b/flow.json @@ -1,9 +1,10 @@ { "contracts": { "Recipe": { - "source": "./cadence/contracts/Recipe.cdc", + "source": "cadence/contracts/Recipe.cdc", "aliases": { - "emulator": "f8d6e0586b0a20c7" + "emulator": "f8d6e0586b0a20c7", + "testing": "0000000000000007" } } }, From 11393adb0a829fb346f63cb090aead9fba791056 Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Mon, 16 Dec 2024 02:29:34 +0400 Subject: [PATCH 12/13] Update tests --- cadence/tests/Recipe_test.cdc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cadence/tests/Recipe_test.cdc b/cadence/tests/Recipe_test.cdc index 986e8fe..2b02f0d 100644 --- a/cadence/tests/Recipe_test.cdc +++ b/cadence/tests/Recipe_test.cdc @@ -1,5 +1,16 @@ import Test +access(all) +fun setup() { + let err = Test.deployContract( + name: "Recipe", + path: "../contracts/Recipe.cdc", + arguments: [], + ) + + Test.expect(err, Test.beNil()) +} + access(all) fun testExample() { let array = [1, 2, 3] Test.expect(array.length, Test.equal(3)) From 972bb2c08e946aab2cdfa56d2c14cc7352f3553d Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Mon, 16 Dec 2024 02:30:10 +0400 Subject: [PATCH 13/13] Update tests --- cadence/tests/Recipe_test.cdc | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/cadence/tests/Recipe_test.cdc b/cadence/tests/Recipe_test.cdc index 05456f9..e5fbaed 100644 --- a/cadence/tests/Recipe_test.cdc +++ b/cadence/tests/Recipe_test.cdc @@ -1,20 +1,7 @@ import Test -import "test_helpers.cdc" access(all) let account = Test.getAccount(0x0000000000000007) -access(all) -fun setup() { - let err = Test.deployContract( - name: "Recipe", - path: "../contracts/Recipe.cdc", - arguments: [], - ) - - Test.expect(err, Test.beNil()) -} - - access(all) fun setup() { let err = Test.deployContract(