-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into 07-10-2024-convert-er…
…c20priceoraclereceiptvault-base-withdraw--tests
- Loading branch information
Showing
8 changed files
with
474 additions
and
1,774 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
test/foundry/src/concrete/erc20PriceOracle/ERC20PriceOracleReceiptVault.construct.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// SPDX-License-Identifier: CAL | ||
pragma solidity =0.8.25; | ||
|
||
import {ReceiptVaultConfig, VaultConfig} from "../../../../../contracts/abstract/ReceiptVault.sol"; | ||
import { | ||
ERC20PriceOracleReceiptVault, | ||
ERC20PriceOracleReceiptVaultConfig | ||
} from "../../../../../contracts/concrete/vault/ERC20PriceOracleReceiptVault.sol"; | ||
import {ERC20PriceOracleReceiptVaultTest, Vm} from "test/foundry/abstract/ERC20PriceOracleReceiptVaultTest.sol"; | ||
import {TwoPriceOracle} from "../../../../../contracts/oracle/price/TwoPriceOracle.sol"; | ||
|
||
contract ERC20PriceOracleReceiptVaultConstructionTest is ERC20PriceOracleReceiptVaultTest { | ||
/// Test ERC20PriceOracleReceiptVault is constracted | ||
function testCheckConstructionEvent( | ||
uint256 fuzzedKeyAlice, | ||
string memory assetName, | ||
string memory assetSymbol, | ||
uint256 timestamp, | ||
uint8 xauDecimals, | ||
uint8 usdDecimals, | ||
uint80 answeredInRound | ||
) external { | ||
// Ensure the fuzzed key is within the valid range for secp256 | ||
address alice = vm.addr((fuzzedKeyAlice % (SECP256K1_ORDER - 1)) + 1); | ||
// Use common decimal bounds for price feeds | ||
// Use 0-20 so we at least have some coverage higher than 18 | ||
usdDecimals = uint8(bound(usdDecimals, 0, 20)); | ||
xauDecimals = uint8(bound(xauDecimals, 0, 20)); | ||
timestamp = bound(timestamp, 0, type(uint32).max); | ||
|
||
vm.warp(timestamp); | ||
TwoPriceOracle twoPriceOracle = createTwoPriceOracle(usdDecimals, usdDecimals, timestamp, answeredInRound); | ||
vm.startPrank(alice); | ||
|
||
// Start recording logs | ||
vm.recordLogs(); | ||
|
||
ERC20PriceOracleReceiptVault vault = createVault(address(twoPriceOracle), assetName, assetSymbol); | ||
// Get the logs | ||
Vm.Log[] memory logs = vm.getRecordedLogs(); | ||
|
||
// Note: To use vm.expectEmit receipt address is needed to be known. | ||
// Find the OffchainAssetReceiptVaultInitialized event log | ||
address msgSender = address(0); | ||
address priceOracle = address(0); | ||
address assetAddress = address(0); | ||
string memory name = ""; | ||
string memory symbol = ""; | ||
bool eventFound = false; // Flag to indicate whether the event log was found | ||
for (uint256 i = 0; i < logs.length; i++) { | ||
if ( | ||
logs[i].topics[0] | ||
== keccak256( | ||
"ERC20PriceOracleReceiptVaultInitialized(address,(address,(address,(address,string,string))))" | ||
) | ||
) { | ||
// Decode the event data | ||
(address sender, ERC20PriceOracleReceiptVaultConfig memory config) = | ||
abi.decode(logs[i].data, (address, ERC20PriceOracleReceiptVaultConfig)); | ||
msgSender = sender; | ||
priceOracle = config.priceOracle; | ||
name = config.receiptVaultConfig.vaultConfig.name; | ||
symbol = config.receiptVaultConfig.vaultConfig.symbol; | ||
assetAddress = address(config.receiptVaultConfig.vaultConfig.asset); | ||
eventFound = true; // Set the flag to true since event log was found | ||
break; | ||
} | ||
} | ||
// Assert that the event log was found | ||
assertTrue(eventFound, "ERC20PriceOracleReceiptVaultInitialized event log not found"); | ||
|
||
assertEq(msgSender, address(iFactory)); | ||
assertEq(priceOracle, address(twoPriceOracle)); | ||
assert(address(vault) != address(0)); | ||
assertEq(keccak256(bytes(vault.name())), keccak256(bytes(name))); | ||
assertEq(keccak256(bytes(vault.symbol())), keccak256(bytes(symbol))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.