Skip to content

Commit

Permalink
Merge pull request #119 from gildlab/07-09-2024-convert-erc20priceora…
Browse files Browse the repository at this point in the history
…clereceiptvault-construction-tests

Test ERC20PriceOracleReceiptVault is constracted
  • Loading branch information
thedavidmeister committed Jul 10, 2024
2 parents 9b4a706 + fcae5c1 commit a710f3a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 176 deletions.
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)));
}
}
176 changes: 0 additions & 176 deletions test/priceOracle/Initialize.test.ts

This file was deleted.

0 comments on commit a710f3a

Please sign in to comment.