Skip to content

Commit f205db6

Browse files
committed
test: Add MyShinyFacetTest for shine functionality
1 parent 297e9e2 commit f205db6

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

test/MyShinyFacetTest.t.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import {Test, console} from "forge-std/Test.sol";
5+
import {MyShinyFacet} from "@diamond/facets/MyShinyFacet.sol";
6+
import {AddMyShinyFacetState} from "./helpers/TestStates.sol";
7+
8+
contract MyShinyFacetTest is AddMyShinyFacetState {
9+
function testSetAndGetShine() public {
10+
MyShinyFacet(address(diamond)).setShine(50);
11+
assertEq(MyShinyFacet(address(diamond)).getShine(), 50);
12+
}
13+
}

test/helpers/TestStates.sol

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ pragma solidity ^0.8.4;
33

44
import {Test, console} from "forge-std/Test.sol";
55
import {DeployDiamond} from "@diamond-script/DeployDiamond.s.sol";
6+
import {DeployDiamondHelper} from "@diamond-test/helpers/DeployDiamondHelper.sol";
67
import {Diamond} from "@diamond/Diamond.sol";
78
import {IDiamondCut} from "@diamond/interfaces/IDiamondCut.sol";
89
import {IDiamondLoupe} from "@diamond/interfaces/IDiamondLoupe.sol";
910
import {HelperContract} from "@diamond-test/helpers/HelperContract.sol";
11+
import {MyShinyFacet} from "@diamond/facets/MyShinyFacet.sol";
12+
import {AddMyShinyFacet} from "@diamond-script/AddMyShinyFacet.s.sol";
13+
import {AddMyShinyFacetHelper} from "@diamond-test/helpers/AddMyShinyFacetHelper.sol";
1014

1115
/// @notice Provides shared state for tests involving a freshly deployed Diamond contract.
1216
/// @dev Sets up references to deployed facets, interfaces, and the diamond itself for testing.
13-
abstract contract DeployedDiamondState is HelperContract {
17+
abstract contract DeployedDiamondState is DeployDiamondHelper {
1418
/// @notice Instance of the deployed Diamond contract.
1519
Diamond public diamond;
1620

17-
/// @notice Script used to deploy the Diamond contract.
18-
DeployDiamond public deployDiamond;
19-
2021
/// @notice Interface for the DiamondCut functionality of the deployed diamond.
2122
IDiamondCut public diamondCut;
2223

@@ -32,12 +33,43 @@ abstract contract DeployedDiamondState is HelperContract {
3233
/// @notice Deploys the Diamond contract and initializes interface references and facet addresses.
3334
/// @dev This function is intended to be called in a test setup phase (e.g., `setUp()` in Foundry).
3435
function setUp() public {
35-
deployDiamond = new DeployDiamond();
36-
diamond = deployDiamond.run();
36+
diamond = _deployDiamond(diamondOwner);
37+
38+
diamondCut = IDiamondCut(address(diamond));
39+
diamondLoupe = IDiamondLoupe(address(diamond));
40+
41+
facetAddresses = diamondLoupe.facetAddresses();
42+
}
43+
}
44+
45+
abstract contract AddMyShinyFacetState is DeployDiamondHelper, AddMyShinyFacetHelper {
46+
/// @notice Instance of the deployed Diamond contract.
47+
Diamond public diamond;
48+
49+
/// @notice Interface for the DiamondCut functionality of the deployed diamond.
50+
IDiamondCut public diamondCut;
51+
52+
/// @notice Interface for the DiamondLoupe functionality of the deployed diamond.
53+
IDiamondLoupe public diamondLoupe;
54+
55+
/// @notice Stores the facet addresses returned from the diamond loupe.
56+
address[] public facetAddresses;
57+
58+
MyShinyFacet public myShinyFacet;
59+
60+
AddMyShinyFacet public addMyShinyFacet;
61+
62+
string[4] public facetNames = ["DiamondCutFacet", "DiamondLoupeFacet", "OwnableRolesFacet", "MyShinyFacet"];
63+
64+
function setUp() public {
65+
vm.startPrank(diamondOwner);
66+
diamond = _deployDiamond(diamondOwner);
3767

3868
diamondCut = IDiamondCut(address(diamond));
3969
diamondLoupe = IDiamondLoupe(address(diamond));
4070

71+
myShinyFacet = _addMyShinyFacet(diamond);
72+
4173
facetAddresses = diamondLoupe.facetAddresses();
4274
}
4375
}

0 commit comments

Comments
 (0)