Skip to content

Commit 24510b1

Browse files
authored
Merge pull request #1549 from onflow/cf/remove-line
Misc formatting fixes on tutorial
2 parents 08148e5 + 1431dd4 commit 24510b1

File tree

1 file changed

+22
-26
lines changed
  • docs/blockchain-development-tutorials/cadence/fork-testing

1 file changed

+22
-26
lines changed

docs/blockchain-development-tutorials/cadence/fork-testing/index.md

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ You'll create a complete fork testing setup that demonstrates:
5656
- Executing transactions using impersonated mainnet accounts
5757
- A reusable pattern for integration testing your Flow applications
5858

59-
**Time Commitment:** Approximately 30 minutes
60-
6159
### Reproducibility first
6260

6361
Pin a specific block height when you need reproducible results:
@@ -147,7 +145,7 @@ Your `flow.json` should now have the mainnet and testnet networks configured fro
147145

148146
## Test Reading Live State
149147

150-
Generate a script to read FlowToken supply:
148+
Generate a script to read `FlowToken` supply:
151149

152150
```zsh
153151
flow generate script GetFlowTokenSupply
@@ -179,9 +177,9 @@ access(all) fun testFlowTokenSupplyIsPositive() {
179177
Test.readFile("../scripts/GetFlowTokenSupply.cdc"),
180178
[]
181179
)
182-
180+
183181
Test.expect(scriptResult, Test.beSucceeded())
184-
182+
185183
let supply = scriptResult.returnValue! as! UFix64
186184
Test.assert(supply > 0.0, message: "FlowToken supply should be positive")
187185
}
@@ -232,7 +230,7 @@ This will output the new account address. Use this address as the mainnet alias
232230
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.
233231
:::
234232

235-
### Create a Contract that Uses FlowToken
233+
### Create a Contract that Uses `FlowToken`
236234

237235
Generate a new contract:
238236

@@ -246,17 +244,17 @@ This creates `cadence/contracts/TokenChecker.cdc` and adds it to `flow.json`. No
246244
import "FlowToken"
247245
248246
access(all) contract TokenChecker {
249-
247+
250248
access(all) fun checkBalance(address: Address): UFix64 {
251249
let account = getAccount(address)
252-
250+
253251
let vaultRef = account.capabilities
254252
.borrow<&FlowToken.Vault>(/public/flowTokenBalance)
255253
?? panic("Could not borrow FlowToken Vault reference")
256-
254+
257255
return vaultRef.balance
258256
}
259-
257+
260258
access(all) fun hasMinimumBalance(address: Address, minimum: UFix64): Bool {
261259
return self.checkBalance(address: address) >= minimum
262260
}
@@ -288,7 +286,7 @@ Update your `flow.json` to include the contract with aliases, using the address
288286
}
289287
```
290288

291-
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.
289+
**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.
292290

293291
### Create Scripts for Testing
294292

@@ -348,9 +346,9 @@ access(all) fun testCheckBalanceOnRealAccount() {
348346
Test.readFile("../scripts/CheckBalance.cdc"),
349347
[Address(0x1654653399040a61)] // Flow service account on mainnet
350348
)
351-
349+
352350
Test.expect(scriptResult, Test.beSucceeded())
353-
351+
354352
let balance = scriptResult.returnValue! as! UFix64
355353
// The Flow service account should have a balance
356354
Test.assert(balance > 0.0, message: "Service account should have FLOW tokens")
@@ -361,9 +359,9 @@ access(all) fun testHasMinimumBalance() {
361359
Test.readFile("../scripts/HasMinimumBalance.cdc"),
362360
[Address(0x1654653399040a61), 1.0]
363361
)
364-
362+
365363
Test.expect(scriptResult, Test.beSucceeded())
366-
364+
367365
let hasMinimum = scriptResult.returnValue! as! Bool
368366
Test.assert(hasMinimum == true, message: "Service account should have at least 1 FLOW")
369367
}
@@ -444,18 +442,18 @@ access(all) fun testTransactionAsMainnetAccount() {
444442
// Impersonate the Flow service account (or any mainnet account)
445443
// No private keys needed - fork testing has built-in impersonation
446444
let serviceAccount = Test.getAccount(0x1654653399040a61)
447-
445+
448446
// Check initial balance
449447
let initialBalanceScript = Test.executeScript(
450448
Test.readFile("../scripts/CheckBalance.cdc"),
451449
[serviceAccount.address]
452450
)
453451
Test.expect(initialBalanceScript, Test.beSucceeded())
454452
let initialBalance = initialBalanceScript.returnValue! as! UFix64
455-
453+
456454
// Create a test recipient account and set up FlowToken vault
457455
let recipient = Test.createAccount()
458-
456+
459457
// Set up the recipient's FlowToken vault
460458
let setupResult = Test.executeTransaction(
461459
Test.Transaction(
@@ -466,7 +464,7 @@ access(all) fun testTransactionAsMainnetAccount() {
466464
)
467465
)
468466
Test.expect(setupResult, Test.beSucceeded())
469-
467+
470468
// Execute transaction AS the mainnet service account
471469
// This works because fork testing allows impersonating any account
472470
let txResult = Test.executeTransaction(
@@ -477,20 +475,20 @@ access(all) fun testTransactionAsMainnetAccount() {
477475
arguments: [10.0, recipient.address]
478476
)
479477
)
480-
478+
481479
Test.expect(txResult, Test.beSucceeded())
482-
480+
483481
// Verify the sender's balance decreased
484482
let newBalanceScript = Test.executeScript(
485483
Test.readFile("../scripts/CheckBalance.cdc"),
486484
[serviceAccount.address]
487485
)
488486
Test.expect(newBalanceScript, Test.beSucceeded())
489487
let newBalance = newBalanceScript.returnValue! as! UFix64
490-
488+
491489
// Balance should have decreased by exactly the transfer amount
492490
Test.assertEqual(initialBalance - 10.0, newBalance)
493-
491+
494492
// Verify the recipient received the tokens
495493
let recipientBalanceScript = Test.executeScript(
496494
Test.readFile("../scripts/CheckBalance.cdc"),
@@ -550,7 +548,7 @@ Fork tests run against Flow chain state only:
550548
- For end-to-end, combine with `flow emulator --fork` and a local stub service
551549
:::
552550

553-
### Select tests quickly
551+
### Select Tests Quickly
554552

555553
- Run specific files or directories:
556554

@@ -614,5 +612,3 @@ Fork testing bridges the gap between local unit tests and testnet deployments, e
614612
[Flow Networks]: ../../../protocol/flow-networks/index.md
615613
[Testing Strategy on Flow]: ../../../build/cadence/smart-contracts/testing-strategy.md
616614
[Flow Emulator]: ../../../build/tools/emulator/index.md
617-
618-

0 commit comments

Comments
 (0)