-
Notifications
You must be signed in to change notification settings - Fork 84
Update to Latest Emulator & Test Framework Changes #2188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f4e17a6
Update to Cadence v1.8.3
jribbink b19b3f9
Update to latest Fork Testing Changes (#2171)
jribbink b8721c3
upgrade emulator (#2184)
janezpodhostnik c9f3b97
Fix CI Test Failure
jribbink be63c18
Update docs
jribbink 2e8f5bb
Update dependency addresses
jribbink dfb1168
Cleanup TX for simplicity
jribbink da381a5
Fix dependencies
jribbink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
internal/super/generator/templates/test_incrementfi_swap_on_fork.cdc.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Fork Testing Example | ||
| // | ||
| // The #test_fork pragma configures this test to run against a snapshot of mainnet state. | ||
| // This allows testing against real deployed contracts and production data without deploying | ||
| // anything to a live network. All mutations happen locally in your test environment. | ||
| // | ||
| // To run this test: flow test cadence/tests/test_incrementfi_swap_on_fork.cdc | ||
| // | ||
| // Learn more about fork testing in the README.md file or at: | ||
| // https://developers.flow.com/blockchain-development-tutorials/cadence/fork-testing | ||
| #test_fork(network: "mainnet", height: nil) | ||
|
|
||
| import Test | ||
| import "DeFiActions" | ||
| import "FlowToken" | ||
| import "stFlowToken" | ||
|
|
||
| // Executes a minimal swap from FLOW -> stFlow using IncrementFi on a forked mainnet. | ||
| // Withdraws a tiny amount from a known FLOW holder and swaps via IncrementFi router. | ||
| access(all) fun testIncrementFi_SwapOnFork() { | ||
| // Arbitrary mainnet account that has FLOW balance and vaults already setup | ||
| // Fork testing allows impersonating any mainnet account for testing | ||
| let HOLDER = Test.getAccount(0x42a06f24a1049154) | ||
| let AMOUNT_IN: UFix64 = 0.001 | ||
|
|
||
| let txCode = Test.readFile("../transactions/incrementfi_swap.cdc") | ||
|
|
||
| // Define vault types for FLOW -> stFlow swap | ||
| let flowVaultType = Type<@FlowToken.Vault>() | ||
| let stFlowVaultType = Type<@stFlowToken.Vault>() | ||
|
|
||
| let res = Test.executeTransaction( | ||
| Test.Transaction( | ||
| code: txCode, | ||
| authorizers: [HOLDER.address], | ||
| signers: [HOLDER], | ||
| arguments: [AMOUNT_IN, flowVaultType, stFlowVaultType] | ||
| ) | ||
| ) | ||
|
|
||
| Test.expect(res, Test.beSucceeded()) | ||
|
|
||
| // Log all swap events emitted during the transaction | ||
| let swapEvents = Test.eventsOfType(Type<DeFiActions.Swapped>()) | ||
| log("Swap events:") | ||
| for event in swapEvents { | ||
| log(event) | ||
| } | ||
| } | ||
|
|
||
|
|
||
42 changes: 42 additions & 0 deletions
42
internal/super/generator/templates/transaction_incrementfi_swap.cdc.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Transaction to swap tokens using IncrementFi's DeFi Actions connector. | ||
| // This demonstrates using IncrementFi's Swapper connector to execute a token swap. | ||
| // | ||
| // Arguments: | ||
| // - amountIn: The amount of input tokens to swap | ||
| // - inVaultType: The vault type for the input token (e.g., Type<@FlowToken.Vault>()) | ||
| // - outVaultType: The vault type for the output token (e.g., Type<@stFlowToken.Vault>()) | ||
| // | ||
| // This transaction is used by the fork test to demonstrate real DeFi protocol integration. | ||
|
|
||
| import "DeFiActions" | ||
| import "FungibleToken" | ||
| import "FlowToken" | ||
| import "IncrementFiSwapConnectors" | ||
| import "SwapConfig" | ||
|
|
||
| transaction(amountIn: UFix64, inVaultType: Type, outVaultType: Type) { | ||
| prepare(acct: auth(BorrowValue) &Account) { | ||
| let opID = DeFiActions.createUniqueIdentifier() | ||
|
|
||
| // Construct swap path from vault types | ||
| let swapPath = [ | ||
| SwapConfig.SliceTokenTypeIdentifierFromVaultType(vaultTypeIdentifier: inVaultType.identifier), | ||
| SwapConfig.SliceTokenTypeIdentifierFromVaultType(vaultTypeIdentifier: outVaultType.identifier) | ||
| ] | ||
|
|
||
| let swapper = IncrementFiSwapConnectors.Swapper( | ||
| path: swapPath, | ||
| inVault: inVaultType, | ||
| outVault: outVaultType, | ||
| uniqueID: opID | ||
| ) | ||
| let flowVaultRef = acct.storage.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault) | ||
| ?? panic("Holder missing FlowToken vault") | ||
| let payment <- flowVaultRef.withdraw(amount: amountIn) | ||
| let out <- swapper.swap(quote: nil, inVault: <-payment) | ||
| assert(out.balance > 0.0, message: "Expected positive output") | ||
| destroy out | ||
| } | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.