Skip to content

Commit

Permalink
Merge branch 'merge-test-fix-backup' into merge-test-fix-base
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Apr 1, 2024
2 parents 07aaf23 + fe07489 commit 3bf3f54
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 152 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cadence_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ jobs:
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.15.0-cadence-v1.0.0-preview.14
- name: Flow CLI Version
run: flow versiongit
run: flow version
- name: Update PATH
run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Run tests
run: sh local/run_cadence_tests.sh
- name: Normalize coverage report filepaths
run: sh ./local/normalize_coverage_report.sh
run : sh ./local/normalize_coverage_report.sh
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

2 changes: 1 addition & 1 deletion cadence/contracts/bridge/FlowEVMBridge.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ contract FlowEVMBridge : IFlowEVMNFTBridge {
) as! MetadataViews.NFTCollectionDisplay? {
name = collectionDisplay.name
let serializedDisplay = SerializeNFT.serializeFromDisplays(nftDisplay: nil, collectionDisplay: collectionDisplay)!
contractURI = "data:application/json;ascii,{".concat(serializedDisplay).concat("}")
contractURI = "data:application/json;utf8,{".concat(serializedDisplay).concat("}")
}
}

Expand Down
7 changes: 4 additions & 3 deletions cadence/contracts/bridge/FlowEVMBridgeUtils.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ contract FlowEVMBridgeUtils {
)
}

init(bridgeFactoryBytecode: String) {
init(bridgeFactoryBytecodeHex: String) {
self.delimiter = "_"
self.contractNamePrefixes = {
Type<@{NonFungibleToken.NFT}>(): {
Expand All @@ -700,9 +700,10 @@ contract FlowEVMBridgeUtils {
"bridged": "EVMVMBridgedToken"
}
}
// Deploy the FlowBridgeFactory.sol contract from provided bytecode and capture the deployed address
self.bridgeFactoryEVMAddress = self.borrowCOA().deploy(
code: bridgeFactoryBytecode.decodeHex(),
gasLimit: 12_000_000,
code: bridgeFactoryBytecodeHex.decodeHex(),
gasLimit: 15000000,
value: EVM.Balance(attoflow: 0)
)
}
Expand Down
30 changes: 15 additions & 15 deletions cadence/contracts/templates/testing/EVMBridgedNFTTemplate.cdc
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import NonFungibleToken from 0xf8d6e0586b0a20c7
import MetadataViews from 0xf8d6e0586b0a20c7
import ViewResolver from 0xf8d6e0586b0a20c7
import FungibleToken from 0xee82856bf20e2aa6
import FlowToken from 0x0ae53cb6e3f42a79

import EVM from 0xf8d6e0586b0a20c7

import ICrossVM from 0xf8d6e0586b0a20c7
import IEVMBridgeNFTMinter from 0xf8d6e0586b0a20c7
import FlowEVMBridgeNFTEscrow from 0xf8d6e0586b0a20c7
import FlowEVMBridgeConfig from 0xf8d6e0586b0a20c7
import FlowEVMBridgeUtils from 0xf8d6e0586b0a20c7
import FlowEVMBridge from 0xf8d6e0586b0a20c7
import CrossVMNFT from 0xf8d6e0586b0a20c7
import NonFungibleToken from 0x0000000000000001
import MetadataViews from 0x0000000000000001
import ViewResolver from 0x0000000000000001
import FungibleToken from 0x0000000000000002
import FlowToken from 0x0000000000000003

import EVM from 0x0000000000000001

import ICrossVM from 0x0000000000000007
import IEVMBridgeNFTMinter from 0x0000000000000007
import FlowEVMBridgeNFTEscrow from 0x0000000000000007
import FlowEVMBridgeConfig from 0x0000000000000007
import FlowEVMBridgeUtils from 0x0000000000000007
import FlowEVMBridge from 0x0000000000000007
import CrossVMNFT from 0x0000000000000007

/// This contract is a template used by FlowEVMBridge to define EVM-native NFTs bridged from Flow EVM to Flow.
/// Upon deployment of this contract, the contract name is derived as a function of the asset type (here an ERC721 aka
Expand Down
21 changes: 9 additions & 12 deletions cadence/contracts/test/EVMDeployer.cdc
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import "EVM"

/// This contract utilized for test purposes only for the sake of capturing the deployment address
/// of a contract for which one would otherwise have to inspect the event emitting on deployment.
/// Assumes a COA is already configured with sufficient balance to deploy the contract.
/// This contract is intended for testing purposes for the sake of capturing a deployed contract address while native
/// `evm.TransactionExecuted` event types are not available in Cadence testing framework. The deploying account should
/// already be configured with a `CadenceOwnedAccount` resource in storage at `/storage/evm`.
///
access(all) contract EVMDeployer {

access(all) let deployedContractAddress: EVM.EVMAddress
access(all) let deployedAddress: EVM.EVMAddress

init(bytecode: String, valueAmount: UFix64) {
init(bytecode: String, value: UInt) {
let coa = self.account.storage.borrow<auth(EVM.Deploy) &EVM.CadenceOwnedAccount>(from: /storage/evm)
?? panic("Could not borrow COA from deployment account storage")

let value = EVM.Balance(attoflow: 0)
value.setFLOW(flow: valueAmount)
self.deployedContractAddress = coa.deploy(
?? panic("No COA found in storage")
self.deployedAddress = coa.deploy(
code: bytecode.decodeHex(),
gasLimit: 12_000_000,
value: value
gasLimit: 15_000_000,
value: EVM.Balance(attoflow: value)
)
}
}
2 changes: 1 addition & 1 deletion cadence/contracts/utils/SerializeNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ access(all) contract SerializeNFT {
return ""
}
// Init the data format prefix & concatenate the serialized display & attributes
var serializedMetadata = "data:application/json;ascii,{"
var serializedMetadata = "data:application/json;utf8,{"
if display != nil {
serializedMetadata = serializedMetadata.concat(display!)
}
Expand Down
10 changes: 10 additions & 0 deletions cadence/scripts/test/get_deployed_erc721_address_string.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import "EVM"

import "EVMDeployer"

import "FlowEVMBridgeUtils"

access(all)
fun main(): String {
return FlowEVMBridgeUtils.getEVMAddressAsHexString(address: EVMDeployer.deployedAddress)
}
14 changes: 14 additions & 0 deletions cadence/scripts/test/is_bridge_router_configured.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import "EVMBridgeRouter"

access(all)
fun main(): Bool {
let serviceAccount = getAuthAccount<auth(Storage) &Account>(0x0000000000000001)
let router = serviceAccount.storage.borrow<&EVMBridgeRouter.Router>(
from: /storage/evmBridgeRouter
) ?? panic("Could not borrow Router")

assert(router.bridgeAddress == 0x0000000000000007)
assert(router.bridgeContractName == "FlowEVMBridge")

return true
}
22 changes: 22 additions & 0 deletions cadence/scripts/utils/is_owner.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import "EVM"

import "FlowEVMBridgeUtils"

/// Returns whether the given owner (hex-encoded EVM address - minus 0x prefix) is the owner of the given ERC721 NFT
/// defined at the hex-encoded EVM contract address
///
/// @param ofNFT: The ERC721 ID of the NFT
/// @param owner: The hex-encoded EVM address of the owner without the 0x prefix
/// @param evmContractAddress: The hex-encoded EVM contract address of the ERC721 contract without the 0x prefix
///
/// @return Whether the given owner is the owner of the given ERC721 NFT. Reverts on call failure.
///
access(all) fun main(ofNFT: UInt256, owner: String, evmContractAddress: String): Bool {
return FlowEVMBridgeUtils.isOwner(
ofNFT: ofNFT,
owner: FlowEVMBridgeUtils.getEVMAddressFromHexString(address: owner)
?? panic("Invalid owner address"),
evmContractAddress: FlowEVMBridgeUtils.getEVMAddressFromHexString(address: evmContractAddress)
?? panic("Invalid EVM contract address")
)
}
Loading

0 comments on commit 3bf3f54

Please sign in to comment.