Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
TEST_DIR := ./cadence/tests
COVER_CODE := contracts
COVER_OUT := coverage.lcov
TEST_FILES := $(shell find $(TEST_DIR) -name "*_test.cdc")

.PHONY: test
test:
flow test --cover --covercode="contracts" --coverprofile="coverage.lcov" ./cadence/tests/*_test.cdc
@echo "Running Cadence tests..."
flow test --cover --covercode="$(COVER_CODE)" --coverprofile="$(COVER_OUT)" $(TEST_FILES)

.PHONY: ci
ci: test
2 changes: 0 additions & 2 deletions cadence/contracts/connectors/FungibleTokenConnectors.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import "FungibleToken"
import "FungibleTokenMetadataViews"

import "DeFiActionsUtils"
import "DeFiActions"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import "Burner"
import "FungibleToken"
import "FlowToken"
import "BandOracle"

import "DeFiActions"

/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand Down Expand Up @@ -103,7 +101,7 @@ access(all) contract BandOracleConnectors {
// check price data has not gone stale based on last updated timestamp
let now = UInt64(getCurrentBlock().timestamp)
if self.staleThreshold != nil {
assert(now < priceData.baseTimestamp + self.staleThreshold!,
assert(now < priceData.baseTimestamp + self.staleThreshold!,
message: "Price data's base timestamp \(priceData.baseTimestamp) exceeds the staleThreshold "
.concat("\(priceData.baseTimestamp + self.staleThreshold!) at current timestamp \(now)"))
assert(now < priceData.quoteTimestamp + self.staleThreshold!,
Expand Down
2 changes: 0 additions & 2 deletions cadence/contracts/connectors/evm/EVMNativeFLOWConnectors.cdc
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import "EVM"
import "Burner"
import "FlowToken"
import "FungibleToken"
import "DeFiActions"
import "DeFiActionsUtils"

/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/// THIS CONTRACT IS IN BETA AND IS NOT FINALIZED - INTERFACES MAY CHANGE AND/OR PENDING CHANGES MAY REQUIRE REDEPLOYMENT
Expand Down
4 changes: 1 addition & 3 deletions cadence/contracts/connectors/evm/UniswapV2SwapConnectors.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import "Burner"
import "EVM"
import "FlowEVMBridgeUtils"
import "FlowEVMBridgeConfig"
import "FlowEVMBridge"

import "DeFiActions"
import "SwapConnectors"

Expand Down Expand Up @@ -53,7 +51,7 @@ access(all) contract UniswapV2SwapConnectors {
FlowEVMBridgeConfig.getTypeAssociated(with: path[0]) == inVault:
"Provided inVault \(inVault.identifier) is not associated with ERC20 at path[0] \(path[0].toString()) - "
.concat("Ensure the type & ERC20 contracts are associated via the VM bridge")
FlowEVMBridgeConfig.getTypeAssociated(with: path[path.length - 1]) == outVault:
FlowEVMBridgeConfig.getTypeAssociated(with: path[path.length - 1]) == outVault:
"Provided outVault \(outVault.identifier) is not associated with ERC20 at path[\(path.length - 1)] \(path[path.length - 1].toString()) - "
.concat("Ensure the type & ERC20 contracts are associated via the VM bridge")
coaCapability.check():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "FungibleToken"
import "SwapConnectors"
import "DeFiActions"

import "SwapRouter"
import "SwapConfig"
import "SwapFactory"
import "StableSwapFactory"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import "FungibleToken"
import "Burner"

import "SwapInterfaces"
import "SwapConfig"
import "SwapFactory"
import "SwapRouter"
import "SwapConnectors"
import "DeFiActions"
Expand Down
3 changes: 1 addition & 2 deletions cadence/contracts/utils/ERC4626Utils.cdc
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import "EVM"
import "FlowEVMBridgeUtils"
import "FlowEVMBridgeConfig"

/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/// THIS CONTRACT IS IN BETA AND IS NOT FINALIZED - INTERFACES MAY CHANGE AND/OR PENDING CHANGES MAY REQUIRE REDEPLOYMENT
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
///
/// ERC4626Utils
///
/// Utility methods commonly used across ERC4626 integrating contracts. The included methods are built on top of the
/// Utility methods commonly used across ERC4626 integrating contracts. The included methods are built on top of the
/// OpenZeppelin ERC4626 implementation and support view methods on the underlying ERC4626 contract.
///
access(all) contract ERC4626Utils {
Expand Down
2 changes: 0 additions & 2 deletions cadence/scripts/auto-balance-adapter/get_balance.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "FungibleToken"

import "DeFiActions"

/// Returns the balance of tokens contained by an AutoBalancer at the specified address via the Capability published
Expand Down
2 changes: 0 additions & 2 deletions cadence/scripts/auto-balance-adapter/get_current_value.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "FungibleToken"

import "DeFiActions"

/// Returns the current value of the tokens contained by an AutoBalancer at the specified address via the Capability
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "FungibleToken"

import "DeFiActions"

/// Returns the historical value of deposits maintained by an AutoBalancer at the specified address via the Capability
Expand Down
1 change: 0 additions & 1 deletion cadence/scripts/erc4626-price-oracles/price.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "EVM"
import "FlowEVMBridgeConfig"

import "ERC4626PriceOracles"

access(all)
Expand Down
1 change: 0 additions & 1 deletion cadence/scripts/evm/get_evm_token_balance_as_ufix64.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "EVM"

import "FlowEVMBridgeUtils"

/// Returns the balance of the owner (hex-encoded EVM address) of a given ERC20 fungible token defined
Expand Down
2 changes: 0 additions & 2 deletions cadence/scripts/evm/has_coa.cdc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import "EVM"

/// Returns true if the given address has a COA at /storage/evm
///
access(all)
Expand Down
19 changes: 8 additions & 11 deletions cadence/tests/AutoBalancer_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ access(all) let autoBalancerPublicPath = /public/autoBalancerTest

access(all) var snapshot: UInt64 = 0

access(all) fun beforeEach() {
if snapshot != getCurrentBlockHeight() {
Test.reset(to: snapshot)
}
}

access(all) fun setup() {
log("================== Setting up AutoBalancer test ==================")
var err = Test.deployContract(
Expand Down Expand Up @@ -102,7 +108,6 @@ access(all) fun test_SetupAutoBalancerSucceeds() {
}

access(all) fun test_SetRebalanceSinkSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
let lowerThreshold = 0.9
let upperThreshold = 1.1
Expand All @@ -128,7 +133,6 @@ access(all) fun test_SetRebalanceSinkSucceeds() {
}

access(all) fun test_SetRebalanceSourceSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
let lowerThreshold = 0.9
let upperThreshold = 1.1
Expand Down Expand Up @@ -162,7 +166,6 @@ access(all) fun test_SetRebalanceSourceSucceeds() {
}

access(all) fun test_ForceRebalanceToSinkSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
let lowerThreshold = 0.9
let upperThreshold = 1.1
Expand Down Expand Up @@ -242,7 +245,6 @@ access(all) fun test_ForceRebalanceToSinkSucceeds() {
}

access(all) fun test_UnforcedRebalanceToSinkSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
let lowerThreshold = 0.9
let upperThreshold = 1.1
Expand Down Expand Up @@ -322,7 +324,6 @@ access(all) fun test_UnforcedRebalanceToSinkSucceeds() {
}

access(all) fun test_ForceRebalanceFromSourceSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
let lowerThreshold = 0.9
let upperThreshold = 1.1
Expand Down Expand Up @@ -421,7 +422,6 @@ access(all) fun test_ForceRebalanceFromSourceSucceeds() {
}

access(all) fun test_UnforcedRebalanceFromSourceSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
let lowerThreshold = 0.9
let upperThreshold = 1.1
Expand Down Expand Up @@ -520,7 +520,6 @@ access(all) fun test_UnforcedRebalanceFromSourceSucceeds() {
}

access(all) fun test_RecurringRebalanceToSinkSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
transferFlow(signer: serviceAccount, recipient: user.address, amount: 100.0)
let lowerThreshold = 0.9
Expand Down Expand Up @@ -628,7 +627,7 @@ access(all) fun test_RecurringRebalanceToSinkSucceeds() {
now = getCurrentBlockTimestamp()
schedEvts = Test.eventsOfType(Type<FlowTransactionScheduler.Scheduled>())
Test.assertEqual(2, schedEvts.length)

schedEvts = Test.eventsOfType(Type<FlowTransactionScheduler.Scheduled>())
schedEvt = schedEvts[schedEvts.length - 1] as! FlowTransactionScheduler.Scheduled
Test.assertEqual(user.address, schedEvt.transactionHandlerOwner)
Expand All @@ -645,7 +644,6 @@ access(all) fun test_RecurringRebalanceToSinkSucceeds() {
}

access(all) fun test_RecurringRebalanceFromSourceSucceeds() {
Test.reset(to: snapshot)
let user = Test.createAccount()
transferFlow(signer: serviceAccount, recipient: user.address, amount: 100.0)
let lowerThreshold = 0.9
Expand Down Expand Up @@ -760,7 +758,7 @@ access(all) fun test_RecurringRebalanceFromSourceSucceeds() {
now = getCurrentBlockTimestamp()
schedEvts = Test.eventsOfType(Type<FlowTransactionScheduler.Scheduled>())
Test.assertEqual(2, schedEvts.length)

schedEvts = Test.eventsOfType(Type<FlowTransactionScheduler.Scheduled>())
schedEvt = schedEvts[schedEvts.length - 1] as! FlowTransactionScheduler.Scheduled
Test.assertEqual(user.address, schedEvt.transactionHandlerOwner)
Expand All @@ -777,7 +775,6 @@ access(all) fun test_RecurringRebalanceFromSourceSucceeds() {
}

access(all) fun test_AttemptToSetRecurringConfigForDifferentAutoBalancerFails() {
Test.reset(to: snapshot)
let user = Test.createAccount()
transferFlow(signer: serviceAccount, recipient: user.address, amount: 100.0)
let lowerThreshold = 0.9
Expand Down
9 changes: 9 additions & 0 deletions cadence/tests/BandOracleConnectors_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import "test_helpers.cdc"

access(all) let serviceAccount = Test.serviceAccount()

access(all) var snapshot: UInt64 = 0

access(all) fun beforeEach() {
if snapshot != getCurrentBlockHeight() {
Test.reset(to: snapshot)
}
}

access(all) fun setup() {
log("================== Setting up BandOracleConnectors test ==================")
var err = Test.deployContract(
Expand All @@ -30,6 +38,7 @@ access(all) fun setup() {
arguments: [],
)
Test.expect(err, Test.beNil())
snapshot = getCurrentBlockHeight()
}

access(all) fun testSetupSuccess() {
Expand Down
10 changes: 9 additions & 1 deletion cadence/tests/ERC4626PriceOracles_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "test_helpers.cdc"
import "FlowToken"
import "DeFiActions"
import "EVM"
import "ERC4626Utils"

access(all) let serviceAccount = Test.serviceAccount()
access(all) let deployerAccount = Test.createAccount()
Expand All @@ -25,6 +24,14 @@ access(all) var vaultDeploymentInfo = MoreVaultDeploymentResult(
vault: EVM.addressFromString("0x0000000000000000000000000000000000000000")
)

access(all) var snapshot: UInt64 = 0

access(all) fun beforeEach() {
if snapshot != getCurrentBlockHeight() {
Test.reset(to: snapshot)
}
}

access(all) fun setup() {
log("================== Setting up ERC4626PriceOracles test ==================")
wflowHex = getEVMAddressAssociated(withType: Type<@FlowToken.Vault>().identifier)!
Expand Down Expand Up @@ -83,6 +90,7 @@ access(all) fun setup() {
arguments: [],
)
Test.expect(err, Test.beNil())
snapshot = getCurrentBlockHeight()
}

access(all) fun testSetupSuccess() {
Expand Down
11 changes: 9 additions & 2 deletions cadence/tests/ERC4626SinkConnectors_test.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import BlockchainHelpers
import "test_helpers.cdc"

import "FlowToken"
import "DeFiActions"
import "EVM"
import "ERC4626Utils"

access(all) let serviceAccount = Test.serviceAccount()
access(all) let deployerAccount = Test.createAccount()
Expand All @@ -28,6 +26,14 @@ access(all) var vaultDeploymentInfo = MoreVaultDeploymentResult(
vault: EVM.addressFromString("0x0000000000000000000000000000000000000000")
)

access(all) var snapshot: UInt64 = 0

access(all) fun beforeEach() {
if snapshot != getCurrentBlockHeight() {
Test.reset(to: snapshot)
}
}

access(all) fun setup() {
log("================== Setting up ERC4626SinkConnectors test ==================")
wflowHex = getEVMAddressAssociated(withType: Type<@FlowToken.Vault>().identifier)!
Expand Down Expand Up @@ -115,6 +121,7 @@ access(all) fun setup() {
deployerAccount
)
Test.expect(bridgeRes, Test.beSucceeded())
snapshot = getCurrentBlockHeight()
}

access(all) fun testDepositToERC4626ViaSinkSucceeds() {
Expand Down
Loading