Skip to content

Commit

Permalink
fix type:evm association when setting TokenHandler evm address
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Dec 21, 2024
1 parent 33ba50e commit 8545872
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions cadence/contracts/bridge/FlowEVMBridgeConfig.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ contract FlowEVMBridgeConfig {
access(account)
fun associateType(_ type: Type, with evmAddress: EVM.EVMAddress) {
pre {
self.getEVMAddressAssociated(with: type) == nil: "Type already associated with an EVMAddress"
self.getTypeAssociated(with: evmAddress) == nil: "EVMAddress already associated with a Type"
self.getEVMAddressAssociated(with: type) == nil:
"Type ".concat(type.identifier).concat(" already associated with an EVMAddress ")
.concat(self.registeredTypes[type]!.evmAddress.toString())
self.getTypeAssociated(with: evmAddress) == nil:
"EVMAddress ".concat(evmAddress.toString()).concat(" already associated with Type ")
.concat(self.evmAddressHexToType[evmAddress.toString()]!.identifier)
}
self.registeredTypes[type] = TypeEVMAssociation(associated: evmAddress)
let evmAddressHex = evmAddress.toString()
Expand Down Expand Up @@ -470,18 +474,16 @@ contract FlowEVMBridgeConfig {
FlowEVMBridgeConfig.getTypeAssociated(with: targetEVMAddress) == nil:
"EVM Address already associated with another Type"
}
post {
FlowEVMBridgeConfig.getEVMAddressAssociated(with: targetType)!.equals(targetEVMAddress):
"Problem associating target Type and target EVM Address"
}
FlowEVMBridgeConfig.associateType(targetType, with: targetEVMAddress)

let handler = FlowEVMBridgeConfig.borrowTokenHandlerAdmin(targetType)
?? panic("No handler found for target Type")
handler.setTargetEVMAddress(targetEVMAddress)

// Get the EVM address currently associated with the target Type. If the association does not exist or the
// EVM address is different, update the association
FlowEVMBridgeConfig.associateType(targetType, with: targetEVMAddress)
assert(
FlowEVMBridgeConfig.getEVMAddressAssociated(with: targetType)!.equals(targetEVMAddress),
message: "Problem associating target Type and target EVM Address"
)

emit HandlerConfigured(
targetType: targetType.identifier,
targetEVMAddress: targetEVMAddress.toString(),
Expand Down
2 changes: 1 addition & 1 deletion cadence/tests/flow_evm_bridge_handler_tests.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fun testDeployERC20Succeeds() {
}

// Set the TokenHandler's targetEVMAddress to the deployed ERC20 contract address
// This will filter requests to onboard the ERC20 to the bridge as the Cadence-nat
// This will filter requests to onboard the ERC20 to the bridge as the Cadence-native token
access(all)
fun testSetHandlerTargetEVMAddressSucceeds() {
let setHandlerTargetResult = executeTransaction(
Expand Down

0 comments on commit 8545872

Please sign in to comment.