Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 92dbc20

Browse files
authored
Forge tests faster (#117)
* fast tests * forge fmt * add --via-ir to build * remove forge test-fast; just run forge test for the same effect * remove outdated and unused folder
1 parent db355a2 commit 92dbc20

9 files changed

+66
-360
lines changed

ethereum/Makefile

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SOURCE_FILES:=$(shell find contracts -name "*.sol")
22

3-
.PHONY: dependencies forge_dependencies wormhole_dependencies unit-test integration-test clean all
3+
.PHONY: dependencies forge_dependencies unit-test integration-test clean all
44

55
all: build
66

@@ -25,13 +25,7 @@ lib/forge-std:
2525
lib/openzeppelin-contracts:
2626
forge install openzeppelin/openzeppelin-contracts@0457042d93d9dfd760dbaa06a4d2f1216fdbe297 --no-git --no-commit
2727

28-
.PHONY: wormhole_dependencies
29-
wormhole_dependencies: wormhole
30-
31-
wormhole:
32-
git clone --depth 1 --branch feat/batch_vaa_alternative --single-branch https://github.com/wormhole-foundation/wormhole.git
33-
34-
dependencies: node_modules forge_dependencies wormhole_dependencies
28+
dependencies: node_modules forge_dependencies
3529

3630
build: dependencies
3731
npm run build
@@ -41,16 +35,16 @@ build: dependencies
4135
cp $< $@
4236

4337
.PHONY: test
44-
test: unit-test integration-test
38+
test: unit-test
4539

4640
.PHONY: unit-test
4741
unit-test: dependencies build
48-
npm run unit-test
42+
npm run forge-test
4943

5044
.PHONY: integration-test
5145
integration-test: dependencies build
5246
npm run integration-test
5347

5448
.PHONY: clean
5549
clean:
56-
rm -rf anvil.log .env node_modules build lib wormhole
50+
rm -rf anvil.log .env node_modules build lib

ethereum/contracts/coreRelayer/CoreRelayer.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ contract CoreRelayer is CoreRelayerDelivery {
277277
// because we will then know how much of the 'maxTransactionFee' of the current delivery is still available for use in this forward
278278
setForwardInstruction(
279279
ForwardInstruction({
280-
container: instructionsContainer,
280+
container: encodeDeliveryInstructionsContainer(instructionsContainer),
281281
nonce: nonce,
282282
msgValue: msg.value,
283283
totalFee: totalFee,

ethereum/contracts/coreRelayer/CoreRelayerDelivery.sol

+49-27
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
4141
internal
4242
returns (bool forwardIsFunded)
4343
{
44-
DeliveryInstructionsContainer memory container = forwardInstruction.container;
44+
DeliveryInstructionsContainer memory container =
45+
decodeDeliveryInstructionsContainer(forwardInstruction.container);
4546

4647
// Add any additional funds which were passed in to the forward as msg.value
4748
transactionFeeRefundAmount = transactionFeeRefundAmount + forwardInstruction.msgValue;
@@ -103,18 +104,17 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
103104
*
104105
* @param internalInstruction instruction to execute
105106
* @param encodedVMs list of signed wormhole messages (VAAs)
106-
* @param deliveryVaaHash hash of delivery VAA
107-
* @param relayerRefund address to send the relayer's refund to
108-
* @param sourceChain chain id that the delivery originated from
109-
* @param sourceSequence sequence number of the delivery VAA on the source chain
107+
* @param relayerRefundAddress address to send the relayer's refund to
108+
* @param vaaInfo struct specifying:
109+
* - sourceChain chain id that the delivery originated from
110+
* - sourceSequence sequence number of the delivery VAA on the source chain
111+
* - deliveryVaaHash hash of delivery VAA
110112
*/
111113
function _executeDelivery(
112114
DeliveryInstruction memory internalInstruction,
113115
bytes[] memory encodedVMs,
114-
bytes32 deliveryVaaHash,
115-
address payable relayerRefund,
116-
uint16 sourceChain,
117-
uint64 sourceSequence
116+
address payable relayerRefundAddress,
117+
DeliveryVAAInfo memory vaaInfo
118118
) internal {
119119
// lock the contract to prevent reentrancy
120120
if (isContractLocked()) {
@@ -161,26 +161,44 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
161161
status = callToTargetContractSucceeded ? DeliveryStatus.SUCCESS : DeliveryStatus.RECEIVER_FAILURE;
162162
}
163163

164+
// Emit a status update that can be read by a SDK
165+
emit Delivery({
166+
recipientContract: fromWormholeFormat(internalInstruction.targetAddress),
167+
sourceChain: vaaInfo.sourceChain,
168+
sequence: vaaInfo.sourceSequence,
169+
deliveryVaaHash: vaaInfo.deliveryVaaHash,
170+
status: status
171+
});
172+
173+
payRefunds(
174+
internalInstruction,
175+
relayerRefundAddress,
176+
transactionFeeRefundAmount,
177+
callToTargetContractSucceeded,
178+
forwardingRequest.isValid,
179+
forwardIsFunded
180+
);
181+
}
182+
183+
function payRefunds(
184+
DeliveryInstruction memory internalInstruction,
185+
address payable relayerRefundAddress,
186+
uint256 transactionFeeRefundAmount,
187+
bool callToTargetContractSucceeded,
188+
bool forwardingRequestExists,
189+
bool forwardWasFunded
190+
) internal {
164191
// Amount of receiverValue that is refunded to the user (0 if the call to 'receiveWormholeMessages' did not revert, or the full receiverValue otherwise)
165192
uint256 receiverValueRefundAmount =
166193
(callToTargetContractSucceeded ? 0 : internalInstruction.receiverValueTarget);
167194

168195
// Total refund to the user
169-
uint256 refundToRefundAddress = receiverValueRefundAmount + (forwardIsFunded ? 0 : transactionFeeRefundAmount);
196+
uint256 refundToRefundAddress = receiverValueRefundAmount + (forwardWasFunded ? 0 : transactionFeeRefundAmount);
170197

171198
// Whether or not the refund succeeded
172199
bool refundPaidToRefundAddress =
173200
pay(payable(fromWormholeFormat(internalInstruction.refundAddress)), refundToRefundAddress);
174201

175-
// Emit a status update that can be read by a SDK
176-
emit Delivery({
177-
recipientContract: fromWormholeFormat(internalInstruction.targetAddress),
178-
sourceChain: sourceChain,
179-
sequence: sourceSequence,
180-
deliveryVaaHash: deliveryVaaHash,
181-
status: status
182-
});
183-
184202
uint256 wormholeMessageFee = wormhole().messageFee();
185203
// Funds that the relayer passed as msg.value over what they needed
186204
uint256 extraRelayerFunds = (
@@ -192,8 +210,8 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
192210
// + (the users refund if that refund didn't succeed)
193211
uint256 relayerRefundAmount = extraRelayerFunds
194212
+ (internalInstruction.maximumRefundTarget - transactionFeeRefundAmount)
195-
+ (forwardingRequest.isValid ? 0 : wormholeMessageFee) + (refundPaidToRefundAddress ? 0 : refundToRefundAddress);
196-
pay(relayerRefund, relayerRefundAmount);
213+
+ (forwardingRequestExists ? 0 : wormholeMessageFee) + (refundPaidToRefundAddress ? 0 : refundToRefundAddress);
214+
pay(relayerRefundAddress, relayerRefundAmount);
197215
}
198216

199217
function verifyRelayerVM(IWormhole.VM memory vm) internal view returns (bool) {
@@ -300,10 +318,12 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
300318
_executeDelivery(
301319
originalInstruction,
302320
targetParams.sourceEncodedVMs,
303-
originalDeliveryVM.hash,
304321
targetParams.relayerRefundAddress,
305-
originalDeliveryVM.emitterChainId,
306-
originalDeliveryVM.sequence
322+
DeliveryVAAInfo({
323+
sourceChain: originalDeliveryVM.emitterChainId,
324+
sourceSequence: originalDeliveryVM.sequence,
325+
deliveryVaaHash: originalDeliveryVM.hash
326+
})
307327
);
308328
}
309329

@@ -427,10 +447,12 @@ contract CoreRelayerDelivery is CoreRelayerGovernance {
427447
_executeDelivery(
428448
deliveryInstruction,
429449
targetParams.encodedVMs,
430-
deliveryVM.hash,
431450
targetParams.relayerRefundAddress,
432-
deliveryVM.emitterChainId,
433-
deliveryVM.sequence
451+
DeliveryVAAInfo({
452+
sourceChain: deliveryVM.emitterChainId,
453+
sourceSequence: deliveryVM.sequence,
454+
deliveryVaaHash: deliveryVM.hash
455+
})
434456
);
435457
}
436458

ethereum/contracts/coreRelayer/CoreRelayerStructs.sol

+7-1
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ abstract contract CoreRelayerStructs {
4141
}
4242

4343
struct ForwardInstruction {
44-
DeliveryInstructionsContainer container;
44+
bytes container;
4545
uint32 nonce;
4646
address sender;
4747
uint256 msgValue;
4848
uint256 totalFee;
4949
address relayProvider;
5050
bool isValid;
5151
}
52+
53+
struct DeliveryVAAInfo {
54+
uint16 sourceChain;
55+
uint64 sourceSequence;
56+
bytes32 deliveryVaaHash;
57+
}
5258
}

0 commit comments

Comments
 (0)