From f14fb0e2c393fd660515557722877d40ef4fc19f Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:45:38 -0700 Subject: [PATCH 1/5] Remove line --- .../cadence/fork-testing/index.md | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md index 3475e1e2ff..a2de0c0ba2 100644 --- a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md +++ b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md @@ -56,8 +56,6 @@ You'll create a complete fork testing setup that demonstrates: - Executing transactions using impersonated mainnet accounts - A reusable pattern for integration testing your Flow applications -**Time Commitment:** Approximately 30 minutes - ### Reproducibility first Pin a specific block height when you need reproducible results: @@ -179,9 +177,9 @@ access(all) fun testFlowTokenSupplyIsPositive() { Test.readFile("../scripts/GetFlowTokenSupply.cdc"), [] ) - + Test.expect(scriptResult, Test.beSucceeded()) - + let supply = scriptResult.returnValue! as! UFix64 Test.assert(supply > 0.0, message: "FlowToken supply should be positive") } @@ -246,17 +244,17 @@ This creates `cadence/contracts/TokenChecker.cdc` and adds it to `flow.json`. No import "FlowToken" access(all) contract TokenChecker { - + access(all) fun checkBalance(address: Address): UFix64 { let account = getAccount(address) - + let vaultRef = account.capabilities .borrow<&FlowToken.Vault>(/public/flowTokenBalance) ?? panic("Could not borrow FlowToken Vault reference") - + return vaultRef.balance } - + access(all) fun hasMinimumBalance(address: Address, minimum: UFix64): Bool { return self.checkBalance(address: address) >= minimum } @@ -348,9 +346,9 @@ access(all) fun testCheckBalanceOnRealAccount() { Test.readFile("../scripts/CheckBalance.cdc"), [Address(0x1654653399040a61)] // Flow service account on mainnet ) - + Test.expect(scriptResult, Test.beSucceeded()) - + let balance = scriptResult.returnValue! as! UFix64 // The Flow service account should have a balance Test.assert(balance > 0.0, message: "Service account should have FLOW tokens") @@ -361,9 +359,9 @@ access(all) fun testHasMinimumBalance() { Test.readFile("../scripts/HasMinimumBalance.cdc"), [Address(0x1654653399040a61), 1.0] ) - + Test.expect(scriptResult, Test.beSucceeded()) - + let hasMinimum = scriptResult.returnValue! as! Bool Test.assert(hasMinimum == true, message: "Service account should have at least 1 FLOW") } @@ -444,7 +442,7 @@ access(all) fun testTransactionAsMainnetAccount() { // Impersonate the Flow service account (or any mainnet account) // No private keys needed - fork testing has built-in impersonation let serviceAccount = Test.getAccount(0x1654653399040a61) - + // Check initial balance let initialBalanceScript = Test.executeScript( Test.readFile("../scripts/CheckBalance.cdc"), @@ -452,10 +450,10 @@ access(all) fun testTransactionAsMainnetAccount() { ) Test.expect(initialBalanceScript, Test.beSucceeded()) let initialBalance = initialBalanceScript.returnValue! as! UFix64 - + // Create a test recipient account and set up FlowToken vault let recipient = Test.createAccount() - + // Set up the recipient's FlowToken vault let setupResult = Test.executeTransaction( Test.Transaction( @@ -466,7 +464,7 @@ access(all) fun testTransactionAsMainnetAccount() { ) ) Test.expect(setupResult, Test.beSucceeded()) - + // Execute transaction AS the mainnet service account // This works because fork testing allows impersonating any account let txResult = Test.executeTransaction( @@ -477,9 +475,9 @@ access(all) fun testTransactionAsMainnetAccount() { arguments: [10.0, recipient.address] ) ) - + Test.expect(txResult, Test.beSucceeded()) - + // Verify the sender's balance decreased let newBalanceScript = Test.executeScript( Test.readFile("../scripts/CheckBalance.cdc"), @@ -487,10 +485,10 @@ access(all) fun testTransactionAsMainnetAccount() { ) Test.expect(newBalanceScript, Test.beSucceeded()) let newBalance = newBalanceScript.returnValue! as! UFix64 - + // Balance should have decreased by exactly the transfer amount Test.assertEqual(initialBalance - 10.0, newBalance) - + // Verify the recipient received the tokens let recipientBalanceScript = Test.executeScript( Test.readFile("../scripts/CheckBalance.cdc"), @@ -614,5 +612,3 @@ Fork testing bridges the gap between local unit tests and testnet deployments, e [Flow Networks]: ../../../protocol/flow-networks/index.md [Testing Strategy on Flow]: ../../../build/cadence/smart-contracts/testing-strategy.md [Flow Emulator]: ../../../build/tools/emulator/index.md - - From 058898760f40ed53236423be3b50ad4e50b6a6b3 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:47:21 -0700 Subject: [PATCH 2/5] Format --- .../cadence/fork-testing/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md index a2de0c0ba2..d127adcb88 100644 --- a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md +++ b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md @@ -145,7 +145,7 @@ Your `flow.json` should now have the mainnet and testnet networks configured fro ## Test Reading Live State -Generate a script to read FlowToken supply: +Generate a script to read `FlowToken` supply: ```zsh flow generate script GetFlowTokenSupply From bbeb411c52b7990d1631c5cbadddb0ca53d1e176 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:48:01 -0700 Subject: [PATCH 3/5] Format --- .../cadence/fork-testing/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md index d127adcb88..f2e8fb8cd4 100644 --- a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md +++ b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md @@ -230,7 +230,7 @@ This will output the new account address. Use this address as the mainnet alias This creates a local account with a mainnet-format address for fork testing. When you're ready to deploy to actual mainnet, you'll use this same account—see the [Deploying Contracts guide](pathname:///build/cadence/smart-contracts/deploying) for details. ::: -### Create a Contract that Uses FlowToken +### Create a Contract that Uses `FlowToken` Generate a new contract: From 508b6b3be2dd31d1e3b65a4b225ef46ce866c52d Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:49:06 -0700 Subject: [PATCH 4/5] Format --- .../cadence/fork-testing/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md index f2e8fb8cd4..f4cc71c23a 100644 --- a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md +++ b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md @@ -286,7 +286,7 @@ Update your `flow.json` to include the contract with aliases, using the address } ``` -Note: No local private key is required for forked tests. The accounts entry above is included so you can copy/reference the address in your config; keys can be omitted for fork tests. Contracts deploy to the testing environment at `testing` alias, and transactions that interact with forked state can use impersonation. The `Test.deployContract` function will automatically deploy your contract to the testing environment during test execution. +**Note:** No local private key is required for forked tests. The accounts entry above is included so you can copy/reference the address in your config; keys can be omitted for fork tests. Contracts deploy to the testing environment at `testing` alias, and transactions that interact with forked state can use impersonation. The `Test.deployContract` function will automatically deploy your contract to the testing environment during test execution. ### Create Scripts for Testing From 1431dd4f5acd37e3848bb73e0483e5b9a1b93aaf Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Wed, 29 Oct 2025 20:49:41 -0700 Subject: [PATCH 5/5] Format --- .../cadence/fork-testing/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md index f4cc71c23a..9ab0fcf49e 100644 --- a/docs/blockchain-development-tutorials/cadence/fork-testing/index.md +++ b/docs/blockchain-development-tutorials/cadence/fork-testing/index.md @@ -548,7 +548,7 @@ Fork tests run against Flow chain state only: - For end-to-end, combine with `flow emulator --fork` and a local stub service ::: -### Select tests quickly +### Select Tests Quickly - Run specific files or directories: