Skip to content

Commit 75f43c5

Browse files
authored
Merge pull request holographxyz#344 from holographxyz/refactor_tests
Refactor tests
2 parents 1131284 + 7b72d60 commit 75f43c5

7 files changed

+36
-25
lines changed

test/foundry/deploy/05_cross-chain_configuration_tests_lq_l2.sol

+7-6
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ contract CrossChainConfiguration is Test {
140140
function deployTestHToken(bool isChain1) private returns (DeploymentConfig memory, bytes32, Verification memory) {
141141
string memory tokenName = string.concat("Holographed TestToken chain ", ((isChain1) ? "one" : "two"));
142142
DeploymentConfig memory deployConfig = HelperDeploymentConfig.getDeployConfigERC20(
143-
bytes32(0x000000000000000000000000000000000000486f6c6f67726170684552433230), //hToken hash
143+
Constants.hTokenHash,
144144
(isChain1) ? Constants.getHolographIdL1() : Constants.getHolographIdL2(),
145145
vm.getCode("hTokenProxy.sol:hTokenProxy"),
146146
tokenName,
147147
"hTTC1",
148-
bytes32(0x0000000000000000000000000000000000000000000000000000000000000000),
148+
Constants.EMPTY_BYTES32,
149149
tokenName,
150150
HelperDeploymentConfig.getInitCodeHtokenETH()
151151
);
@@ -673,6 +673,7 @@ VALIDATE CROSS-CHAIN DATA
673673
HolographDropERC721V2 holographDropERC721V2Chain2 = holographDropERC721V2;
674674
assertEq(address(holographDropERC721V2Chain1), address(holographDropERC721V2Chain2));
675675
}
676+
676677
/*
677678
DEPLOY CROSS-CHAIN CONTRACTS
678679
*/
@@ -810,7 +811,7 @@ DEPLOY CROSS-CHAIN CONTRACTS
810811
DeploymentConfig memory deployConfig = HelperDeploymentConfig.getERC721(
811812
Constants.getHolographIdL1(),
812813
vm.getCode("SampleERC721.sol:SampleERC721"),
813-
bytes32(0x0000000000000000000000000000000000000000000000000000000000000086),
814+
Constants.eventConfig,
814815
true
815816
);
816817

@@ -840,7 +841,7 @@ DEPLOY CROSS-CHAIN CONTRACTS
840841
DeploymentConfig memory deployConfig = HelperDeploymentConfig.getERC721(
841842
Constants.getHolographIdL2(),
842843
vm.getCode("SampleERC721.sol:SampleERC721"),
843-
bytes32(0x0000000000000000000000000000000000000000000000000000000000000086),
844+
Constants.eventConfig,
844845
false
845846
);
846847

@@ -874,7 +875,7 @@ DEPLOY CROSS-CHAIN CONTRACTS
874875
DeploymentConfig memory deployConfig = HelperDeploymentConfig.getCxipERC721(
875876
Constants.getHolographIdL1(),
876877
vm.getCode("CxipERC721Proxy.sol:CxipERC721Proxy"),
877-
bytes32(0x0000000000000000000000000000000000000000000000000000000000000086),
878+
Constants.eventConfig,
878879
true
879880
);
880881

@@ -904,7 +905,7 @@ DEPLOY CROSS-CHAIN CONTRACTS
904905
DeploymentConfig memory deployConfig = HelperDeploymentConfig.getCxipERC721(
905906
Constants.getHolographIdL2(),
906907
vm.getCode("CxipERC721Proxy.sol:CxipERC721Proxy"),
907-
bytes32(0x0000000000000000000000000000000000000000000000000000000000000086),
908+
Constants.eventConfig,
908909
false
909910
);
910911

test/foundry/deploy/06_CrossChainMinting.t.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ contract CrossChainMinting is Test {
400400
deployConfig = HelperDeploymentConfig.getERC721(
401401
isL1 ? Constants.getHolographIdL1() : Constants.getHolographIdL2(),
402402
vm.getCode("SampleERC721.sol:SampleERC721"),
403-
0x0000000000000000000000000000000000000000000000000000000000000086, // eventConfig,
403+
Constants.eventConfig,
404404
isL1
405405
);
406406

@@ -421,7 +421,7 @@ contract CrossChainMinting is Test {
421421
deployConfig = HelperDeploymentConfig.getCxipERC721(
422422
isL1 ? Constants.getHolographIdL1() : Constants.getHolographIdL2(),
423423
vm.getCode("CxipERC721Proxy.sol:CxipERC721Proxy"),
424-
0x0000000000000000000000000000000000000000000000000000000000000086, // eventConfig,
424+
Constants.eventConfig,
425425
isL1
426426
);
427427

@@ -442,12 +442,12 @@ contract CrossChainMinting is Test {
442442
string memory tokenName = string.concat("Holographed TestToken chain ", ((isL1) ? "one" : "two"));
443443

444444
deployConfig = HelperDeploymentConfig.getDeployConfigERC20(
445-
bytes32(0x000000000000000000000000000000000000486f6c6f67726170684552433230), //hToken hash
445+
Constants.hTokenHash,
446446
(isL1) ? Constants.getHolographIdL1() : Constants.getHolographIdL2(),
447447
vm.getCode("hTokenProxy.sol:hTokenProxy"),
448448
tokenName,
449449
"hTTC1",
450-
bytes32(0x0000000000000000000000000000000000000000000000000000000000000000),
450+
Constants.EMPTY_BYTES32,
451451
tokenName,
452452
HelperDeploymentConfig.getInitCodeHtokenETH()
453453
);

test/foundry/deploy/11_HolographFactory.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ contract HolographFactoryTest is Test {
8181
DeploymentConfig memory deployConfig = HelperDeploymentConfig.getERC721(
8282
Constants.getHolographIdL1(),
8383
vm.getCode("SampleERC721.sol:SampleERC721"),
84-
0x0000000000000000000000000000000000000000000000000000000000000000, // eventConfig,
84+
Constants.EMPTY_BYTES32, // eventConfig,
8585
true
8686
);
8787

test/foundry/deploy/17_holographer_tests.t.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ contract HolographerTests is Test {
2929
address deployer = vm.addr(Constants.getPKDeployer());
3030
uint256 localHostFork;
3131
string LOCALHOST_RPC_URL = vm.envString("LOCALHOST_RPC_URL");
32-
bytes32 holographERC721Hash = bytes32(0x0000000000000000000000000000000000486f6c6f6772617068455243373231);
32+
bytes32 holographERC721Hash = Constants.holographERC721Hash;
3333

3434
/**
3535
* @notice Deploys the Holographer contract
@@ -47,7 +47,7 @@ contract HolographerTests is Test {
4747
vm.getCode("SampleERC721.sol:SampleERC721"),
4848
"Sample ERC721 Contract: unit test",
4949
"SMPLR",
50-
0x0000000000000000000000000000000000000000000000000000000000000086,
50+
Constants.eventConfig,
5151
1000,
5252
HelperDeploymentConfig.getInitCodeSampleErc721()
5353
);

test/foundry/deploy/19_ERC721H_tests.t.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity 0.8.13;
33

44
import {Test, Vm, console} from "forge-std/Test.sol";
5-
import {Constants} from "../utils/Constants.sol";
5+
import {Constants, ErrorConstants} from "../utils/Constants.sol";
66
import {ERC721H} from "../../../src/abstract/ERC721H.sol";
77
import {Holographer} from "../../../src/enforcer/Holographer.sol";
88
import {HolographLegacyERC721} from "../../../src/token/HolographLegacyERC721.sol";
@@ -45,7 +45,7 @@ contract ERC721HTests is Test {
4545
* Refers to the hardhat test with the description 'should fail be initialized twice'
4646
*/
4747
function testInit() public {
48-
vm.expectRevert("HOLOGRAPHER: already initialized");
48+
vm.expectRevert(bytes(ErrorConstants.HOLOGRAPHER_ALREADY_INITIALIZED_ERROR_MSG));
4949
vm.prank(deployer);
5050
erc721h.init(abi.encode(deployer));
5151
}

test/foundry/utils/Constants.sol

+7
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ library Constants {
191191
uint256 public constant HALF_INVERSE_VALUE = 0xffffffffffffffffffffffffffffffff00000000000000000000000000000000;
192192
bytes32 public constant EMPTY_BYTES32 = bytes32(0x0);
193193
bytes public constant EMPTY_BYTES = abi.encode(0x0);
194+
bytes32 public constant erc20Hash = bytes32(0x000000000000000000000000000000000000486f6c6f67726170684552433230);
195+
bytes32 public constant hTokenHash = bytes32(0x000000000000000000000000000000000000000000000000000068546f6b656e);
196+
bytes32 public constant holographERC721Hash =
197+
bytes32(0x0000000000000000000000000000000000486f6c6f6772617068455243373231);
198+
bytes32 public constant cxipERC721Hex = 0x0000000000000000000000000000000000000000000043786970455243373231;
199+
bytes32 public constant contractTypeHolographDropERC721V2 =
200+
bytes32(0x0000000000000000000000486f6c6f677261706844726f704552433732315632);
194201
}
195202

196203
library ErrorConstants {

test/foundry/utils/HelperDeploymentConfig.sol

+13-10
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import {SalesConfiguration} from "../../../src/drops/struct/SalesConfiguration.s
1212

1313
library HelperDeploymentConfig {
1414
uint256 constant dropEventConfig = 0x0000000000000000000000000000000000000000000000000000000000040000;
15+
1516
function getInitCodeHtokenETH() public pure returns (bytes memory) {
1617
return
1718
abi.encode(
18-
bytes32(0x000000000000000000000000000000000000000000000000000068546f6b656e), //htokenHash
19+
Constants.hTokenHash,
1920
Constants.getHolographRegistryProxy(), //registry address
2021
abi.encode(Constants.getDeployer(), uint16(0))
2122
);
@@ -30,7 +31,7 @@ library HelperDeploymentConfig {
3031
}
3132

3233
function getInitCodeCxipERC721() public pure returns (bytes memory) {
33-
bytes32 CxipERC721Hex = 0x0000000000000000000000000000000000000000000043786970455243373231;
34+
bytes32 CxipERC721Hex = Constants.cxipERC721Hex;
3435
return abi.encode(CxipERC721Hex, Constants.getHolographRegistryProxy(), getInitCodeSampleErc721());
3536
}
3637

@@ -46,7 +47,7 @@ library HelperDeploymentConfig {
4647
) public pure returns (DeploymentConfig memory deployConfig) {
4748
deployConfig.contractType = contractType; //hToken
4849
deployConfig.chainType = chainType; //holograph id
49-
deployConfig.salt = bytes32(0x00000000000000000000000000000000000000000000000000000000000003e8);
50+
deployConfig.salt = Constants.saltHex;
5051
deployConfig.byteCode = contractByteCode;
5152
deployConfig.initCode = abi.encode(
5253
tokenName, //token name
@@ -60,6 +61,7 @@ library HelperDeploymentConfig {
6061
);
6162
return deployConfig;
6263
}
64+
6365
function getDeployConfigERC721(
6466
bytes32 contractType,
6567
uint32 chainType,
@@ -98,6 +100,7 @@ library HelperDeploymentConfig {
98100
)
99101
);
100102
}
103+
101104
/*
102105
* @note This contract is used to get the DeploymentConfig for hToken ETH
103106
* @dev This contract provides helper functions to get the DeploymentConfig by chainType (getHolographIdL1 or getHolographIdL2) for hToken ETH
@@ -110,12 +113,12 @@ library HelperDeploymentConfig {
110113
) public pure returns (DeploymentConfig memory deployConfig) {
111114
return
112115
getDeployConfigERC20(
113-
bytes32(0x000000000000000000000000000000000000486f6c6f67726170684552433230), //hToken hash
116+
Constants.erc20Hash,
114117
chainType,
115118
contractByteCode,
116119
"Holographed ETH",
117120
"hETH",
118-
0x0000000000000000000000000000000000000000000000000000000000000000,
121+
Constants.EMPTY_BYTES32,
119122
"Holographed ETH",
120123
getInitCodeHtokenETH()
121124
);
@@ -128,7 +131,7 @@ library HelperDeploymentConfig {
128131
) public pure returns (DeploymentConfig memory deployConfig) {
129132
return
130133
getDeployConfigERC20(
131-
bytes32(0x000000000000000000000000000000000000486f6c6f67726170684552433230), //hToken hash
134+
Constants.erc20Hash,
132135
chainType,
133136
contractByteCode,
134137
isL1 ? "Sample ERC20 Token (localhost)" : "Sample ERC20 Token (localhost2)",
@@ -147,7 +150,7 @@ library HelperDeploymentConfig {
147150
) public pure returns (DeploymentConfig memory deployConfig) {
148151
return
149152
getDeployConfigERC721(
150-
bytes32(0x0000000000000000000000000000000000486f6c6f6772617068455243373231), //HolographERC721 hash,
153+
Constants.holographERC721Hash,
151154
chainType,
152155
contractByteCode,
153156
isL1 ? "CXIP ERC721 Collection (localhost)" : "CXIP ERC721 Collection (localhost2)",
@@ -166,7 +169,7 @@ library HelperDeploymentConfig {
166169
) public pure returns (DeploymentConfig memory deployConfig) {
167170
return
168171
getDeployConfigERC721(
169-
bytes32(0x0000000000000000000000000000000000486f6c6f6772617068455243373231), //HolographERC721 hash,
172+
Constants.holographERC721Hash,
170173
chainType,
171174
contractByteCode,
172175
isL1 ? "Sample ERC721 Contract (localhost)" : "Sample ERC721 Contract (localhost2)",
@@ -190,7 +193,7 @@ library HelperDeploymentConfig {
190193
presaleEnd: 0,
191194
publicSalePrice: 0,
192195
maxSalePurchasePerAddress: 0,
193-
presaleMerkleRoot: bytes32(0x0000000000000000000000000000000000000000000000000000000000000000)
196+
presaleMerkleRoot: Constants.EMPTY_BYTES32
194197
});
195198

196199
DropsInitializerV2 memory initializer = DropsInitializerV2({
@@ -203,7 +206,7 @@ library HelperDeploymentConfig {
203206
metadataRendererInit: abi.encode("decscription", "imageURI", "animationURI")
204207
});
205208

206-
deployConfig.contractType = bytes32(0x0000000000000000000000486f6c6f677261706844726f704552433732315632); //Source contract type HolographDropERC721V2
209+
deployConfig.contractType = Constants.contractTypeHolographDropERC721V2;
207210
deployConfig.chainType = chainType; //holograph id
208211
deployConfig.salt = Constants.saltHex;
209212
deployConfig.byteCode = contractByteCode;

0 commit comments

Comments
 (0)