Skip to content

Commit

Permalink
Add helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 committed Feb 13, 2025
1 parent c353f90 commit 7c619a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 4 additions & 9 deletions test/solidity/Facets/ChainflipFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { LibAllowList, TestBaseFacet, console, ERC20 } from "../utils/TestBaseFa
import { ChainflipFacet } from "lifi/Facets/ChainflipFacet.sol";
import { LibAsset } from "lifi/Libraries/LibAsset.sol";
import { LibSwap } from "lifi/Libraries/LibSwap.sol";
import { stdJson } from "forge-std/StdJson.sol";

using stdJson for string;

// Stub ChainflipFacet Contract
contract TestChainflipFacet is ChainflipFacet {
Expand Down Expand Up @@ -36,13 +33,11 @@ contract ChainflipFacetTest is TestBaseFacet {
customBlockNumberForForking = 18277082;
initTestBase();

// Read chainflip vault address from config
string memory path = string.concat(
vm.projectRoot(),
"/config/chainflip.json"
// Read chainflip vault address from config using the new helper
CHAINFLIP_VAULT = getConfigAddressFromPath(
"chainflip.json",
".mainnet.chainflipVault"
);
string memory json = vm.readFile(path);
CHAINFLIP_VAULT = json.readAddress(".mainnet.chainflipVault");
vm.label(CHAINFLIP_VAULT, "Chainflip Vault");
console.log("Chainflip Vault Address:", CHAINFLIP_VAULT);

Expand Down
16 changes: 16 additions & 0 deletions test/solidity/utils/TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { LibAccess } from "lifi/Libraries/LibAccess.sol";
import { console } from "test/solidity/utils/Console.sol";
import { FeeCollector } from "lifi/Periphery/FeeCollector.sol";
import { NoSwapDataProvided, InformationMismatch, NativeAssetTransferFailed, ReentrancyError, InsufficientBalance, CannotBridgeToSameNetwork, InvalidReceiver, InvalidAmount, InvalidConfig, InvalidSendingToken, AlreadyInitialized, NotInitialized, UnAuthorized } from "src/Errors/GenericErrors.sol";
import { stdJson } from "forge-std/StdJson.sol";

using stdJson for string;

contract TestFacet {
constructor() {}
Expand Down Expand Up @@ -530,5 +533,18 @@ abstract contract TestBase is Test, DiamondTest, ILiFi {
uint256 targetBlock = block.number + numBlocks;
vm.roll(targetBlock);
}

function getConfigAddressFromPath(
string memory configFileName,
string memory jsonPath
) internal returns (address) {
string memory path = string.concat(
vm.projectRoot(),
"/config/",
configFileName
);
string memory json = vm.readFile(path);
return json.readAddress(jsonPath);
}
//#endregion
}

0 comments on commit 7c619a3

Please sign in to comment.