Skip to content

Commit da21dde

Browse files
tests
1 parent 8ef0464 commit da21dde

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

src/concrete/deploy/ERC20PriceOracleReceiptVaultCloneDeployer.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ struct ERC20PriceOracleReceiptVaultCloneDeployerConfig {
2323
}
2424

2525
contract ERC20PriceOracleReceiptVaultCloneDeployer {
26-
event Deployment(address sender, address erc20PriceOracleReceiptVault, address receipt);
26+
event ERC20PriceOracleReceiptVaultCloneDeployerDeployment(
27+
address sender, address erc20PriceOracleReceiptVault, address receipt
28+
);
2729

2830
address public immutable I_RECEIPT_IMPLEMENTATION;
2931
address public immutable I_ERC20_PRICE_ORACLE_RECEIPT_VAULT_IMPLEMENTATION;
@@ -56,7 +58,9 @@ contract ERC20PriceOracleReceiptVaultCloneDeployer {
5658
revert InitializeVaultFailed();
5759
}
5860

59-
emit Deployment(msg.sender, address(erc20PriceOracleReceiptVault), address(receipt));
61+
emit ERC20PriceOracleReceiptVaultCloneDeployerDeployment(
62+
msg.sender, address(erc20PriceOracleReceiptVault), address(receipt)
63+
);
6064

6165
return erc20PriceOracleReceiptVault;
6266
}

test/src/concrete/deploy/ERC20PriceOracleReceiptVaultCloneDeployer.newERC20PriceOracleReceiptVault.t.sol

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
33
pragma solidity =0.8.25;
44

5-
import {Test} from "forge-std/Test.sol";
5+
import {Test, Vm} from "forge-std/Test.sol";
66

77
import {
88
ERC20PriceOracleReceiptVaultCloneDeployer,
@@ -34,7 +34,11 @@ contract ERC20PriceOracleReceiptVaultCloneDeployerNewERC20PriceOracleReceiptVaul
3434
deployer.newERC20PriceOracleReceiptVault(config);
3535
}
3636

37-
function testNewERC20PriceOracleReceiptVaultSuccess(ERC20PriceOracleReceiptVaultConfigV2 memory config) external {
37+
function testNewERC20PriceOracleReceiptVaultSuccess(
38+
address alice,
39+
ERC20PriceOracleReceiptVaultConfigV2 memory config
40+
) external {
41+
vm.assume(alice.code.length == 0);
3842
vm.assume(config.receiptVaultConfig.receipt == address(0));
3943
ReceiptContract receiptImplementation = new ReceiptContract();
4044
ERC20PriceOracleReceiptVault erc20PriceOracleReceiptVaultImplementation = new ERC20PriceOracleReceiptVault();
@@ -44,7 +48,29 @@ contract ERC20PriceOracleReceiptVaultCloneDeployerNewERC20PriceOracleReceiptVaul
4448
erc20PriceOracleReceiptVaultImplementation: address(erc20PriceOracleReceiptVaultImplementation)
4549
})
4650
);
51+
vm.startPrank(alice);
52+
vm.recordLogs();
4753
ERC20PriceOracleReceiptVault vault = deployer.newERC20PriceOracleReceiptVault(config);
54+
Vm.Log[] memory logs = vm.getRecordedLogs();
55+
vm.stopPrank();
56+
57+
bool eventFound = false;
58+
bytes32 eventTopic = keccak256("ERC20PriceOracleReceiptVaultCloneDeployerDeployment(address,address,address)");
59+
address eventSender;
60+
address eventVault;
61+
address eventReceipt;
62+
for (uint256 i = 0; i < logs.length; i++) {
63+
if (logs[i].topics[0] == eventTopic) {
64+
(eventSender, eventVault, eventReceipt) = abi.decode(logs[i].data, (address, address, address));
65+
eventFound = true;
66+
break;
67+
}
68+
}
69+
assertTrue(eventFound, "ERC20PriceOracleReceiptVaultCloneDeployerDeployment event log not found");
70+
assertEq(eventSender, alice);
71+
assertEq(eventVault, address(vault));
72+
assertEq(eventReceipt, address(vault.receipt()));
73+
4874
assert(address(vault) != address(0));
4975
assert(vault.asset() == config.receiptVaultConfig.asset);
5076
}

test/src/concrete/deploy/OffchainAssetReceiptVaultBeaconSetDeployer.newOffchainAssetReceiptVault.t.sol

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
33
pragma solidity =0.8.25;
44

5-
import {Test} from "forge-std/Test.sol";
5+
import {Test, Vm} from "forge-std/Test.sol";
66

77
import {
88
OffchainAssetReceiptVaultBeaconSetDeployer,
@@ -50,7 +50,10 @@ contract OffchainAssetReceiptVaultBeaconSetDeployerNewOffchainAssetReceiptVaultT
5050
deployer.newOffchainAssetReceiptVault(config);
5151
}
5252

53-
function testNewOffchainAssetReceiptVault(OffchainAssetReceiptVaultConfigV2 memory config) external {
53+
function testNewOffchainAssetReceiptVault(address alice, OffchainAssetReceiptVaultConfigV2 memory config)
54+
external
55+
{
56+
vm.assume(alice.code.length == 0);
5457
vm.assume(config.receiptVaultConfig.receipt == address(0));
5558
vm.assume(config.initialAdmin != address(0));
5659
vm.assume(config.receiptVaultConfig.asset == address(0));
@@ -65,8 +68,28 @@ contract OffchainAssetReceiptVaultBeaconSetDeployerNewOffchainAssetReceiptVaultT
6568
})
6669
);
6770

68-
// expectEmit
71+
vm.startPrank(alice);
72+
vm.recordLogs();
6973
OffchainAssetReceiptVault offchainAssetReceiptVault = deployer.newOffchainAssetReceiptVault(config);
74+
Vm.Log[] memory logs = vm.getRecordedLogs();
75+
vm.stopPrank();
76+
77+
bool eventFound = false;
78+
bytes32 eventTopic = keccak256("OffchainAssetReceiptVaultBeaconSetDeployerDeployment(address,address,address)");
79+
address eventSender;
80+
address eventVault;
81+
address eventReceipt;
82+
for (uint256 i = 0; i < logs.length; i++) {
83+
if (logs[i].topics[0] == eventTopic) {
84+
(eventSender, eventVault, eventReceipt) = abi.decode(logs[i].data, (address, address, address));
85+
eventFound = true;
86+
break;
87+
}
88+
}
89+
assertTrue(eventFound, "OffchainAssetReceiptVaultBeaconSetDeployerDeployment event log not found");
90+
assertEq(eventSender, alice);
91+
assertEq(eventVault, address(offchainAssetReceiptVault));
92+
assertEq(eventReceipt, address(offchainAssetReceiptVault.receipt()));
7093

7194
assertEq(
7295
address(OffchainAssetReceiptVault(payable(offchainAssetReceiptVault)).receipt().manager()),

0 commit comments

Comments
 (0)