From 85458722a8b52d8b0bbd4f48760df4f4e346a4b5 Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:54:25 -0800 Subject: [PATCH] fix type:evm association when setting TokenHandler evm address --- .../contracts/bridge/FlowEVMBridgeConfig.cdc | 22 ++++++++++--------- .../tests/flow_evm_bridge_handler_tests.cdc | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc index 867c6314..95c3c745 100644 --- a/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc +++ b/cadence/contracts/bridge/FlowEVMBridgeConfig.cdc @@ -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() @@ -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(), diff --git a/cadence/tests/flow_evm_bridge_handler_tests.cdc b/cadence/tests/flow_evm_bridge_handler_tests.cdc index cae23e84..0405790b 100644 --- a/cadence/tests/flow_evm_bridge_handler_tests.cdc +++ b/cadence/tests/flow_evm_bridge_handler_tests.cdc @@ -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(