Skip to content

Commit 189fd62

Browse files
authored
Merge testing refactor (#52)
* refactor and enhance testing utilities * fix WormholeOverride.sign() by using provided params * enable decodeDeposit from bytes directly * further cleanup refactor and extend README * fix formating
1 parent fa2dc15 commit 189fd62

30 files changed

+1285
-1370
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ forge install wormhole-foundation/[email protected]
2828

2929
**EVM Version**
3030

31-
One hazard of developing EVM contracts in a cross-chain environment is that different chains have varying levels EVM-equivalence. This means you have to ensure that all chains that you are planning to deploy to support all EIPs/opcodes that you rely on.
31+
One hazard of developing EVM contracts in a cross-chain environment is that different chains have varying levels of "EVM-equivalence". This means you have to ensure that all chains that you are planning to deploy to support all EIPs/opcodes that you rely on.
3232

3333
For example, if you are using a solc version newer than `0.8.19` and are planning to deploy to a chain that does not support [PUSH0 opcode](https://eips.ethereum.org/EIPS/eip-3855) (introduced as part of the Shanghai hardfork), you should set `evm_version = "paris"` in your `foundry.toml`, since the default EVM version of solc was advanced from Paris to Shanghai as part of solc's `0.8.20` release.
3434

35+
**Testing**
36+
37+
It is strongly recommended that you run the forge test suite of this SDK with your own compiler version to catch potential errors that stem from differences in compiler versions early. Yes, strictly speaking the Solidity version pragma should prevent these issues, but better to be safe than sorry, especially given that some components make extensive use of inline assembly.
38+
39+
**IERC20 Remapping**
40+
41+
This SDK comes with its own IERC20 interface. Given that projects tend to combine different SDKs, there's often this annoying issue of clashes of IERC20 interfaces, even though the are effectively the same. We handle this issue by importing `IERC20/IERC20.sol` which allows remapping the `IERC20/` prefix to whatever directory contains `IERC20.sol` in your project, thus providing an override mechanism that should allow dealing with this problem seamlessly until forge allows remapping of individual files.
42+
3543
## Philosophy/Creeds
3644

3745
In This House We Believe:

foundry.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ out = "out"
66
libs = ["lib"]
77
via_ir = true
88

9+
#currently, forge does not allow remapping of individual files
10+
# (see here: https://github.com/foundry-rs/foundry/issues/7527#issuecomment-2269444829)
11+
#so for now we are using the IERC20 prefix as a workaround that allows users
12+
# to override the IERC20 interface with whatever they use in their project
13+
# (well, as long as their file is also called IERC20.sol and is interface compatible)
914
remappings = [
1015
"ds-test/=lib/forge-std/lib/ds-test/src/",
1116
"forge-std/=lib/forge-std/src/",
1217
"wormhole-sdk/=src/",
18+
"IERC20/=src/interfaces/token/",
1319
]
1420

1521
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

src/WormholeRelayer/CCTPAndTokenBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: Apache 2
22
pragma solidity ^0.8.19;
33

4+
import "IERC20/IERC20.sol";
45
import "wormhole-sdk/interfaces/IWormholeReceiver.sol";
56
import "wormhole-sdk/interfaces/IWormholeRelayer.sol";
67
import "wormhole-sdk/interfaces/ITokenBridge.sol";
7-
import "wormhole-sdk/interfaces/token/IERC20.sol";
88
import "wormhole-sdk/interfaces/cctp/ITokenMessenger.sol";
99
import "wormhole-sdk/interfaces/cctp/IMessageTransmitter.sol";
1010
import "wormhole-sdk/Utils.sol";

src/WormholeRelayer/CCTPBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// SPDX-License-Identifier: Apache 2
22
pragma solidity ^0.8.19;
33

4+
import "IERC20/IERC20.sol";
45
import "wormhole-sdk/interfaces/IWormholeReceiver.sol";
56
import "wormhole-sdk/interfaces/IWormholeRelayer.sol";
6-
import "wormhole-sdk/interfaces/token/IERC20.sol";
77
import "wormhole-sdk/interfaces/cctp/ITokenMessenger.sol";
88
import "wormhole-sdk/interfaces/cctp/IMessageTransmitter.sol";
99
import "wormhole-sdk/Utils.sol";

src/WormholeRelayer/TokenBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: Apache 2
22
pragma solidity ^0.8.19;
33

4+
import "IERC20/IERC20.sol";
45
import "wormhole-sdk/interfaces/IWormholeReceiver.sol";
56
import "wormhole-sdk/interfaces/IWormholeRelayer.sol";
67
import "wormhole-sdk/interfaces/ITokenBridge.sol";
7-
import "wormhole-sdk/interfaces/token/IERC20.sol";
88
import "wormhole-sdk/Utils.sol";
99

1010
import {Base} from "./Base.sol";

src/interfaces/ITokenBridge.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
pragma solidity ^0.8.0;
55

6-
import "./token/IWETH.sol";
76
import "./IWormhole.sol";
87

98
interface ITokenBridge {
@@ -149,7 +148,7 @@ interface ITokenBridge {
149148

150149
function tokenImplementation() external view returns (address);
151150

152-
function WETH() external view returns (IWETH);
151+
function WETH() external view returns (address);
153152

154153
function outstandingBridged(address token) external view returns (uint256);
155154

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,76 @@
1-
/*
2-
* Copyright (c) 2022, Circle Internet Financial Limited.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
// SPDX-License-Identifier: Apache 2
2+
// Copyright (c) 2022, Circle Internet Financial Limited.
3+
//
4+
// stripped, flattened version of:
5+
// https://github.com/circlefin/evm-cctp-contracts/blob/master/src/MessageTransmitter.sol
6+
167
pragma solidity ^0.8.0;
178

18-
import "./IRelayer.sol";
19-
import "./IReceiver.sol";
9+
import {IOwnable2Step} from "./shared/IOwnable2Step.sol";
10+
import {IPausable} from "./shared/IPausable.sol";
11+
12+
interface IAttestable {
13+
event AttesterEnabled(address indexed attester);
14+
event AttesterDisabled(address indexed attester);
15+
16+
event SignatureThresholdUpdated(uint256 oldSignatureThreshold, uint256 newSignatureThreshold);
17+
event AttesterManagerUpdated(
18+
address indexed previousAttesterManager,
19+
address indexed newAttesterManager
20+
);
21+
22+
function attesterManager() external view returns (address);
23+
function isEnabledAttester(address attester) external view returns (bool);
24+
function getNumEnabledAttesters() external view returns (uint256);
25+
function getEnabledAttester(uint256 index) external view returns (address);
26+
27+
function updateAttesterManager(address newAttesterManager) external;
28+
function setSignatureThreshold(uint256 newSignatureThreshold) external;
29+
function enableAttester(address attester) external;
30+
function disableAttester(address attester) external;
31+
}
32+
33+
interface IMessageTransmitter is IAttestable, IPausable, IOwnable2Step {
34+
event MessageSent(bytes message);
35+
36+
event MessageReceived(
37+
address indexed caller,
38+
uint32 sourceDomain,
39+
uint64 indexed nonce,
40+
bytes32 sender,
41+
bytes messageBody
42+
);
43+
44+
function localDomain() external view returns (uint32);
45+
function version() external view returns (uint32);
46+
function maxMessageBodySize() external view returns (uint256);
47+
function nextAvailableNonce() external view returns (uint64);
48+
function usedNonces(bytes32 nonce) external view returns (bool);
49+
50+
function sendMessage(
51+
uint32 destinationDomain,
52+
bytes32 recipient,
53+
bytes calldata messageBody
54+
) external returns (uint64);
55+
56+
function sendMessageWithCaller(
57+
uint32 destinationDomain,
58+
bytes32 recipient,
59+
bytes32 destinationCaller,
60+
bytes calldata messageBody
61+
) external returns (uint64);
62+
63+
function replaceMessage(
64+
bytes calldata originalMessage,
65+
bytes calldata originalAttestation,
66+
bytes calldata newMessageBody,
67+
bytes32 newDestinationCaller
68+
) external;
2069

21-
/**
22-
* @title IMessageTransmitter
23-
* @notice Interface for message transmitters, which both relay and receive messages.
24-
*/
25-
interface IMessageTransmitter is IRelayer, IReceiver {
70+
function receiveMessage(
71+
bytes calldata message,
72+
bytes calldata attestation
73+
) external returns (bool success);
2674

75+
function setMaxMessageBodySize(uint256 newMaxMessageBodySize) external;
2776
}

src/interfaces/cctp/IReceiver.sol

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/interfaces/cctp/IRelayer.sol

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)