From 21ca9231e20ff50a276b62b0f3cf9d7ee5c8a7ef Mon Sep 17 00:00:00 2001 From: Ogooluwa Akinola Date: Wed, 16 Jul 2025 13:34:34 -0400 Subject: [PATCH 01/12] fix(drop 2): avalanche deploy address issue - update avalanche factory and registry address - update chain implementation Ids --- cli-typescript/src/cmds/createCommand.ts | 1 + cli-typescript/src/utils/constants.ts | 6 +++++- cli-typescript/src/utils/getters.ts | 24 +++++++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cli-typescript/src/cmds/createCommand.ts b/cli-typescript/src/cmds/createCommand.ts index b3eddc33..56dd5692 100644 --- a/cli-typescript/src/cmds/createCommand.ts +++ b/cli-typescript/src/cmds/createCommand.ts @@ -59,6 +59,7 @@ const presets = async (cliCmd: string) => { console.log('Authenticating...'); await authenticate(); + console.log('Authentication successful.'); // set cmd name globally process.env.MAGICDROP_CLI_CMD = cliCmd; diff --git a/cli-typescript/src/utils/constants.ts b/cli-typescript/src/utils/constants.ts index ed18eabd..5c2da8cf 100644 --- a/cli-typescript/src/utils/constants.ts +++ b/cli-typescript/src/utils/constants.ts @@ -35,11 +35,15 @@ export const LIMITBREAK_TRANSFER_VALIDATOR_V3_BERACHAIN = export const ABSTRACT_FACTORY_ADDRESS = '0x4a08d3F6881c4843232EFdE05baCfb5eAaB35d19'; +export const AVALANCHE_FACTORY_ADDRESS = + '0x0b49bDcf2eC9329Fa6F42DCCC66e8906a3E4ACF0'; export const DEFAULT_FACTORY_ADDRESS = '0x000000009e44eBa131196847C685F20Cd4b68aC4'; export const ABSTRACT_REGISTRY_ADDRESS = '0x9b60ad31F145ec7EE3c559153bB57928B65C0F87'; +export const AVALANCHE_REGISTRY_ADDRESS = + '0x09E0135dfBb7528D6eAA5beB69f3C030dF26F57c'; export const DEFAULT_REGISTRY_ADDRESS = '0x00000000caF1E3978e291c5Fb53FeedB957eC146'; @@ -127,7 +131,7 @@ export const explorerUrls: { [chainId in SUPPORTED_CHAINS]: string } = { [SUPPORTED_CHAINS.ABSTRACT]: 'https://abscan.org', // Abstract [SUPPORTED_CHAINS.BERACHAIN]: 'https://berascan.com', // Berachain [SUPPORTED_CHAINS.MONAD_TESTNET]: 'https://testnet.monadexplorer.com', // Monad Testnet - [SUPPORTED_CHAINS.AVALANCHE]: 'https://subnets.avax.network/', // Avalanche + [SUPPORTED_CHAINS.AVALANCHE]: 'https://snowtrace.io', // Avalanche }; export const DEFAULT_TOKEN_URI_SUFFIX = '.json'; diff --git a/cli-typescript/src/utils/getters.ts b/cli-typescript/src/utils/getters.ts index d1592b32..a3aadf05 100644 --- a/cli-typescript/src/utils/getters.ts +++ b/cli-typescript/src/utils/getters.ts @@ -2,6 +2,8 @@ import { confirm } from '@inquirer/prompts'; import { ABSTRACT_FACTORY_ADDRESS, ABSTRACT_REGISTRY_ADDRESS, + AVALANCHE_FACTORY_ADDRESS, + AVALANCHE_REGISTRY_ADDRESS, DEFAULT_COLLECTION_DIR, DEFAULT_FACTORY_ADDRESS, DEFAULT_IMPL_ID, @@ -230,6 +232,10 @@ export const getFactoryAddress = (chainId: SUPPORTED_CHAINS): `0x${string}` => { return ABSTRACT_FACTORY_ADDRESS; } + if (chainId === SUPPORTED_CHAINS.AVALANCHE) { + return AVALANCHE_FACTORY_ADDRESS; + } + return DEFAULT_FACTORY_ADDRESS; }; @@ -240,6 +246,10 @@ export const getRegistryAddress = ( return ABSTRACT_REGISTRY_ADDRESS; } + if (chainId === SUPPORTED_CHAINS.AVALANCHE) { + return AVALANCHE_REGISTRY_ADDRESS; + } + return DEFAULT_REGISTRY_ADDRESS; }; @@ -261,15 +271,19 @@ export const getImplId = ( switch (chainId) { case SUPPORTED_CHAINS.ABSTRACT: - return 3; // ERC721C implementation ID / abstract + return 7; // ERC721C implementation ID / abstract case SUPPORTED_CHAINS.BASE: - return 8; + return 11; case SUPPORTED_CHAINS.ETHEREUM: - return 7; + return 10; case SUPPORTED_CHAINS.BERACHAIN: - return 2; - default: return 5; + case SUPPORTED_CHAINS.MONAD_TESTNET: + return 5; + case SUPPORTED_CHAINS.AVALANCHE: + return 6; + default: + return 8; } }; From 8aab793159dac150472a85dff3e8b8d9e6225f35 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 19:28:59 -0500 Subject: [PATCH 02/12] draft rotation of salt --- test/factory/MagicDropCloneFactoryTest.t.sol | 159 +++++++++++++++---- 1 file changed, 131 insertions(+), 28 deletions(-) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index c8938338..09163b83 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -12,11 +12,21 @@ import {MagicDropTokenImplRegistry} from "../../contracts/registry/MagicDropToke import {TokenStandard} from "../../contracts/common/Structs.sol"; contract MockERC721Initializable is MockERC721 { - function initialize(string memory, string memory, address, uint256) public {} + function initialize( + string memory, + string memory, + address, + uint256 + ) public {} } contract MockERC1155Initializable is MockERC1155 { - function initialize(string memory, string memory, address, uint256) public {} + function initialize( + string memory, + string memory, + address, + uint256 + ) public {} } contract InvalidImplementation is MockERC721 { @@ -39,12 +49,16 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); // Deploy and initialize registry - address registryImpl = LibClone.clone(address(new MagicDropTokenImplRegistry())); + address registryImpl = LibClone.clone( + address(new MagicDropTokenImplRegistry()) + ); registry = MagicDropTokenImplRegistry(payable(registryImpl)); registry.initialize(owner); // Deploy factory - address factoryImpl = LibClone.clone(address(new MagicDropCloneFactory())); + address factoryImpl = LibClone.clone( + address(new MagicDropCloneFactory()) + ); factory = MagicDropCloneFactory(payable(factoryImpl)); factory.initialize(owner, address(registry)); @@ -53,10 +67,19 @@ contract MagicDropCloneFactoryTest is Test { erc1155Impl = new MockERC1155Initializable(); // Register implementations - erc721ImplId = - registry.registerImplementation(TokenStandard.ERC721, address(erc721Impl), true, 0.01 ether, 0.00001 ether); + erc721ImplId = registry.registerImplementation( + TokenStandard.ERC721, + address(erc721Impl), + true, + 0.01 ether, + 0.00001 ether + ); erc1155ImplId = registry.registerImplementation( - TokenStandard.ERC1155, address(erc1155Impl), true, 0.01 ether, 0.00001 ether + TokenStandard.ERC1155, + address(erc1155Impl), + true, + 0.01 ether, + 0.00001 ether ); // Fund user @@ -69,7 +92,11 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId ); MockERC721Initializable nft = MockERC721Initializable(newContract); @@ -84,8 +111,13 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC721ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = - factory.createContract{value: 0.01 ether}("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), 0); + address newContract = factory.createContract{value: 0.01 ether}( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + 0 + ); MockERC721Initializable nft = MockERC721Initializable(newContract); // Test minting @@ -99,7 +131,11 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), erc1155ImplId + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + erc1155ImplId ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -114,8 +150,13 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC1155ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = - factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); + address newContract = factory.createContract{value: 0.01 ether}( + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + 0 + ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -133,10 +174,23 @@ contract MagicDropCloneFactoryTest is Test { bytes32[] memory salts = new bytes32[](numSalts); for (uint256 i = 0; i < numSalts; i++) { - salts[i] = keccak256(abi.encodePacked(i, block.timestamp, msg.sender)); - address predictedAddress = factory.predictDeploymentAddress(TokenStandard.ERC721, erc721ImplId, salts[i]); - address deployedAddress = factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, salts[i] + salts[i] = keccak256( + abi.encodePacked(i, block.timestamp, msg.sender) + ); + address predictedAddress = factory.predictDeploymentAddress( + TokenStandard.ERC721, + erc721ImplId, + salts[i] + ); + address deployedAddress = factory.createContractDeterministic{ + value: 0.01 ether + }( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + salts[i] ); assertEq(predictedAddress, deployedAddress); } @@ -149,23 +203,39 @@ contract MagicDropCloneFactoryTest is Test { vm.prank(user); vm.expectRevert(); - factory.createContract("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), invalidImplId); + factory.createContract( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + invalidImplId + ); } function testCreateDeterministicContractWithSameSalt() public { vm.startPrank(user); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT1", "TNFT1", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(0) + "TestNFT1", + "TNFT1", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(100)) ); vm.expectRevert(); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT2", "TNFT2", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(0) + "TestNFT2", + "TNFT2", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(100)) ); } function testContractAlreadyDeployed() public { - bytes32 salt = bytes32(uint256(1)); + bytes32 salt = bytes32(uint256(101)); uint32 implId = 1; TokenStandard standard = TokenStandard.ERC721; address initialOwner = address(0x1); @@ -173,14 +243,23 @@ contract MagicDropCloneFactoryTest is Test { string memory symbol = "TT"; // Predict the address where the contract will be deployed - address predictedAddress = factory.predictDeploymentAddress(standard, implId, salt); + address predictedAddress = factory.predictDeploymentAddress( + standard, + implId, + salt + ); // Deploy a dummy contract to the predicted address vm.etch(predictedAddress, address(erc721Impl).code); vm.expectRevert(); // Try to create a contract with the same parameters factory.createContractDeterministic{value: 0.01 ether}( - name, symbol, standard, payable(initialOwner), implId, salt + name, + symbol, + standard, + payable(initialOwner), + implId, + salt ); } @@ -189,20 +268,38 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); InvalidImplementation impl = new InvalidImplementation(); - uint32 implId = registry.registerImplementation(standard, address(impl), false, 0.01 ether, 0.00001 ether); + uint32 implId = registry.registerImplementation( + standard, + address(impl), + false, + 0.01 ether, + 0.00001 ether + ); vm.stopPrank(); vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", "TNFT", standard, payable(user), implId, bytes32(0) + "TestNFT", + "TNFT", + standard, + payable(user), + implId, + bytes32(uint256(102)) ); } function testInsufficientDeploymentFee() public { vm.startPrank(user); - vm.expectRevert(MagicDropCloneFactory.InsufficientDeploymentFee.selector); + vm.expectRevert( + MagicDropCloneFactory.InsufficientDeploymentFee.selector + ); factory.createContractDeterministic{value: 0.005 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(0) + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(103)) ); } @@ -212,7 +309,13 @@ contract MagicDropCloneFactoryTest is Test { function testWithdraw() public { vm.startPrank(user); - factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); + factory.createContract{value: 0.01 ether}( + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + 0 + ); vm.stopPrank(); vm.startPrank(owner); From 93b2e20ea8d187afc39521b557dc0050df2ddb56 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 19:32:08 -0500 Subject: [PATCH 03/12] forge fmt.... --- test/factory/MagicDropCloneFactoryTest.t.sol | 157 ++++--------------- 1 file changed, 27 insertions(+), 130 deletions(-) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index 09163b83..87d91fd1 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -12,21 +12,11 @@ import {MagicDropTokenImplRegistry} from "../../contracts/registry/MagicDropToke import {TokenStandard} from "../../contracts/common/Structs.sol"; contract MockERC721Initializable is MockERC721 { - function initialize( - string memory, - string memory, - address, - uint256 - ) public {} + function initialize(string memory, string memory, address, uint256) public {} } contract MockERC1155Initializable is MockERC1155 { - function initialize( - string memory, - string memory, - address, - uint256 - ) public {} + function initialize(string memory, string memory, address, uint256) public {} } contract InvalidImplementation is MockERC721 { @@ -49,16 +39,12 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); // Deploy and initialize registry - address registryImpl = LibClone.clone( - address(new MagicDropTokenImplRegistry()) - ); + address registryImpl = LibClone.clone(address(new MagicDropTokenImplRegistry())); registry = MagicDropTokenImplRegistry(payable(registryImpl)); registry.initialize(owner); // Deploy factory - address factoryImpl = LibClone.clone( - address(new MagicDropCloneFactory()) - ); + address factoryImpl = LibClone.clone(address(new MagicDropCloneFactory())); factory = MagicDropCloneFactory(payable(factoryImpl)); factory.initialize(owner, address(registry)); @@ -67,19 +53,10 @@ contract MagicDropCloneFactoryTest is Test { erc1155Impl = new MockERC1155Initializable(); // Register implementations - erc721ImplId = registry.registerImplementation( - TokenStandard.ERC721, - address(erc721Impl), - true, - 0.01 ether, - 0.00001 ether - ); + erc721ImplId = + registry.registerImplementation(TokenStandard.ERC721, address(erc721Impl), true, 0.01 ether, 0.00001 ether); erc1155ImplId = registry.registerImplementation( - TokenStandard.ERC1155, - address(erc1155Impl), - true, - 0.01 ether, - 0.00001 ether + TokenStandard.ERC1155, address(erc1155Impl), true, 0.01 ether, 0.00001 ether ); // Fund user @@ -92,11 +69,7 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId ); MockERC721Initializable nft = MockERC721Initializable(newContract); @@ -111,13 +84,8 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC721ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - 0 - ); + address newContract = + factory.createContract{value: 0.01 ether}("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), 0); MockERC721Initializable nft = MockERC721Initializable(newContract); // Test minting @@ -131,11 +99,7 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - erc1155ImplId + "TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), erc1155ImplId ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -150,13 +114,8 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC1155ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - 0 - ); + address newContract = + factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -174,23 +133,10 @@ contract MagicDropCloneFactoryTest is Test { bytes32[] memory salts = new bytes32[](numSalts); for (uint256 i = 0; i < numSalts; i++) { - salts[i] = keccak256( - abi.encodePacked(i, block.timestamp, msg.sender) - ); - address predictedAddress = factory.predictDeploymentAddress( - TokenStandard.ERC721, - erc721ImplId, - salts[i] - ); - address deployedAddress = factory.createContractDeterministic{ - value: 0.01 ether - }( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - salts[i] + salts[i] = keccak256(abi.encodePacked(i, block.timestamp, msg.sender)); + address predictedAddress = factory.predictDeploymentAddress(TokenStandard.ERC721, erc721ImplId, salts[i]); + address deployedAddress = factory.createContractDeterministic{value: 0.01 ether}( + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, salts[i] ); assertEq(predictedAddress, deployedAddress); } @@ -203,34 +149,18 @@ contract MagicDropCloneFactoryTest is Test { vm.prank(user); vm.expectRevert(); - factory.createContract( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - invalidImplId - ); + factory.createContract("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), invalidImplId); } function testCreateDeterministicContractWithSameSalt() public { vm.startPrank(user); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT1", - "TNFT1", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(100)) + "TestNFT1", "TNFT1", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) ); vm.expectRevert(); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT2", - "TNFT2", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(100)) + "TestNFT2", "TNFT2", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) ); } @@ -243,23 +173,14 @@ contract MagicDropCloneFactoryTest is Test { string memory symbol = "TT"; // Predict the address where the contract will be deployed - address predictedAddress = factory.predictDeploymentAddress( - standard, - implId, - salt - ); + address predictedAddress = factory.predictDeploymentAddress(standard, implId, salt); // Deploy a dummy contract to the predicted address vm.etch(predictedAddress, address(erc721Impl).code); vm.expectRevert(); // Try to create a contract with the same parameters factory.createContractDeterministic{value: 0.01 ether}( - name, - symbol, - standard, - payable(initialOwner), - implId, - salt + name, symbol, standard, payable(initialOwner), implId, salt ); } @@ -268,38 +189,20 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); InvalidImplementation impl = new InvalidImplementation(); - uint32 implId = registry.registerImplementation( - standard, - address(impl), - false, - 0.01 ether, - 0.00001 ether - ); + uint32 implId = registry.registerImplementation(standard, address(impl), false, 0.01 ether, 0.00001 ether); vm.stopPrank(); vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", - "TNFT", - standard, - payable(user), - implId, - bytes32(uint256(102)) + "TestNFT", "TNFT", standard, payable(user), implId, bytes32(uint256(102)) ); } function testInsufficientDeploymentFee() public { vm.startPrank(user); - vm.expectRevert( - MagicDropCloneFactory.InsufficientDeploymentFee.selector - ); + vm.expectRevert(MagicDropCloneFactory.InsufficientDeploymentFee.selector); factory.createContractDeterministic{value: 0.005 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(103)) + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(103)) ); } @@ -309,13 +212,7 @@ contract MagicDropCloneFactoryTest is Test { function testWithdraw() public { vm.startPrank(user); - factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - 0 - ); + factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); vm.stopPrank(); vm.startPrank(owner); From 4fb49caa3f3581dc744cbd6bc35cbb8733e4db39 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 19:43:11 -0500 Subject: [PATCH 04/12] deploy create2 from different user --- test/factory/MagicDropCloneFactoryTest.t.sol | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index 87d91fd1..438d8771 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -192,10 +192,15 @@ contract MagicDropCloneFactoryTest is Test { uint32 implId = registry.registerImplementation(standard, address(impl), false, 0.01 ether, 0.00001 ether); vm.stopPrank(); + // give user some ether + vm.deal(user, 100 ether); + + vm.startPrank(user); vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); factory.createContractDeterministic{value: 0.01 ether}( "TestNFT", "TNFT", standard, payable(user), implId, bytes32(uint256(102)) ); + vm.stopPrank(); } function testInsufficientDeploymentFee() public { From 44416368e19edf49e6dca806bd3dcf269bd493f7 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 20:24:26 -0500 Subject: [PATCH 05/12] add more verbose debugging in cicd --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 749714d0..05ec19bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,5 +41,5 @@ jobs: - name: Run Forge tests run: | - forge test -vvv + forge test -vvvv id: test From 4b415dad896d6da237fd43457ab70fdc264bb8ad Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 20:39:36 -0500 Subject: [PATCH 06/12] add more verbose debugging in cicd --- test/factory/MagicDropCloneFactoryTest.t.sol | 166 +++++++++++++++---- 1 file changed, 133 insertions(+), 33 deletions(-) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index 438d8771..bcefdfa6 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -12,15 +12,27 @@ import {MagicDropTokenImplRegistry} from "../../contracts/registry/MagicDropToke import {TokenStandard} from "../../contracts/common/Structs.sol"; contract MockERC721Initializable is MockERC721 { - function initialize(string memory, string memory, address, uint256) public {} + function initialize( + string memory, + string memory, + address, + uint256 + ) public {} } contract MockERC1155Initializable is MockERC1155 { - function initialize(string memory, string memory, address, uint256) public {} + function initialize( + string memory, + string memory, + address, + uint256 + ) public {} } contract InvalidImplementation is MockERC721 { - function initialize(string memory) public {} // Missing name and symbol parameters + function initialize(string memory) public { + revert("deliberate failure"); + } // Missing name and symbol parameters } contract MagicDropCloneFactoryTest is Test { @@ -39,12 +51,16 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); // Deploy and initialize registry - address registryImpl = LibClone.clone(address(new MagicDropTokenImplRegistry())); + address registryImpl = LibClone.clone( + address(new MagicDropTokenImplRegistry()) + ); registry = MagicDropTokenImplRegistry(payable(registryImpl)); registry.initialize(owner); // Deploy factory - address factoryImpl = LibClone.clone(address(new MagicDropCloneFactory())); + address factoryImpl = LibClone.clone( + address(new MagicDropCloneFactory()) + ); factory = MagicDropCloneFactory(payable(factoryImpl)); factory.initialize(owner, address(registry)); @@ -53,10 +69,19 @@ contract MagicDropCloneFactoryTest is Test { erc1155Impl = new MockERC1155Initializable(); // Register implementations - erc721ImplId = - registry.registerImplementation(TokenStandard.ERC721, address(erc721Impl), true, 0.01 ether, 0.00001 ether); + erc721ImplId = registry.registerImplementation( + TokenStandard.ERC721, + address(erc721Impl), + true, + 0.01 ether, + 0.00001 ether + ); erc1155ImplId = registry.registerImplementation( - TokenStandard.ERC1155, address(erc1155Impl), true, 0.01 ether, 0.00001 ether + TokenStandard.ERC1155, + address(erc1155Impl), + true, + 0.01 ether, + 0.00001 ether ); // Fund user @@ -69,7 +94,11 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId ); MockERC721Initializable nft = MockERC721Initializable(newContract); @@ -84,8 +113,13 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC721ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = - factory.createContract{value: 0.01 ether}("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), 0); + address newContract = factory.createContract{value: 0.01 ether}( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + 0 + ); MockERC721Initializable nft = MockERC721Initializable(newContract); // Test minting @@ -99,7 +133,11 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), erc1155ImplId + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + erc1155ImplId ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -114,8 +152,13 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC1155ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = - factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); + address newContract = factory.createContract{value: 0.01 ether}( + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + 0 + ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -133,10 +176,23 @@ contract MagicDropCloneFactoryTest is Test { bytes32[] memory salts = new bytes32[](numSalts); for (uint256 i = 0; i < numSalts; i++) { - salts[i] = keccak256(abi.encodePacked(i, block.timestamp, msg.sender)); - address predictedAddress = factory.predictDeploymentAddress(TokenStandard.ERC721, erc721ImplId, salts[i]); - address deployedAddress = factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, salts[i] + salts[i] = keccak256( + abi.encodePacked(i, block.timestamp, msg.sender) + ); + address predictedAddress = factory.predictDeploymentAddress( + TokenStandard.ERC721, + erc721ImplId, + salts[i] + ); + address deployedAddress = factory.createContractDeterministic{ + value: 0.01 ether + }( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + salts[i] ); assertEq(predictedAddress, deployedAddress); } @@ -149,18 +205,34 @@ contract MagicDropCloneFactoryTest is Test { vm.prank(user); vm.expectRevert(); - factory.createContract("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), invalidImplId); + factory.createContract( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + invalidImplId + ); } function testCreateDeterministicContractWithSameSalt() public { vm.startPrank(user); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT1", "TNFT1", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) + "TestNFT1", + "TNFT1", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(100)) ); vm.expectRevert(); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT2", "TNFT2", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) + "TestNFT2", + "TNFT2", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(100)) ); } @@ -173,14 +245,23 @@ contract MagicDropCloneFactoryTest is Test { string memory symbol = "TT"; // Predict the address where the contract will be deployed - address predictedAddress = factory.predictDeploymentAddress(standard, implId, salt); + address predictedAddress = factory.predictDeploymentAddress( + standard, + implId, + salt + ); // Deploy a dummy contract to the predicted address vm.etch(predictedAddress, address(erc721Impl).code); vm.expectRevert(); // Try to create a contract with the same parameters factory.createContractDeterministic{value: 0.01 ether}( - name, symbol, standard, payable(initialOwner), implId, salt + name, + symbol, + standard, + payable(initialOwner), + implId, + salt ); } @@ -189,25 +270,38 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); InvalidImplementation impl = new InvalidImplementation(); - uint32 implId = registry.registerImplementation(standard, address(impl), false, 0.01 ether, 0.00001 ether); + uint32 implId = registry.registerImplementation( + standard, + address(impl), + false, + 0.01 ether, + 0.00001 ether + ); vm.stopPrank(); - // give user some ether - vm.deal(user, 100 ether); - - vm.startPrank(user); vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", "TNFT", standard, payable(user), implId, bytes32(uint256(102)) + "TestNFT", + "TNFT", + standard, + payable(user), + implId, + bytes32(uint256(102)) ); - vm.stopPrank(); } function testInsufficientDeploymentFee() public { vm.startPrank(user); - vm.expectRevert(MagicDropCloneFactory.InsufficientDeploymentFee.selector); + vm.expectRevert( + MagicDropCloneFactory.InsufficientDeploymentFee.selector + ); factory.createContractDeterministic{value: 0.005 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(103)) + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(103)) ); } @@ -217,7 +311,13 @@ contract MagicDropCloneFactoryTest is Test { function testWithdraw() public { vm.startPrank(user); - factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); + factory.createContract{value: 0.01 ether}( + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + 0 + ); vm.stopPrank(); vm.startPrank(owner); From d94f76cd131158487837e7ce5f647827fafacc2b Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 20:40:23 -0500 Subject: [PATCH 07/12] remove forge fmt --- .github/workflows/test.yml | 5 - test/factory/MagicDropCloneFactoryTest.t.sol | 157 ++++--------------- 2 files changed, 27 insertions(+), 135 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 05ec19bd..f8ceaa0e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,11 +29,6 @@ jobs: run: | forge --version - - name: Run Forge fmt - run: | - forge fmt --check - id: fmt - - name: Run Forge build run: | forge build --via-ir --sizes diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index bcefdfa6..8a845b21 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -12,21 +12,11 @@ import {MagicDropTokenImplRegistry} from "../../contracts/registry/MagicDropToke import {TokenStandard} from "../../contracts/common/Structs.sol"; contract MockERC721Initializable is MockERC721 { - function initialize( - string memory, - string memory, - address, - uint256 - ) public {} + function initialize(string memory, string memory, address, uint256) public {} } contract MockERC1155Initializable is MockERC1155 { - function initialize( - string memory, - string memory, - address, - uint256 - ) public {} + function initialize(string memory, string memory, address, uint256) public {} } contract InvalidImplementation is MockERC721 { @@ -51,16 +41,12 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); // Deploy and initialize registry - address registryImpl = LibClone.clone( - address(new MagicDropTokenImplRegistry()) - ); + address registryImpl = LibClone.clone(address(new MagicDropTokenImplRegistry())); registry = MagicDropTokenImplRegistry(payable(registryImpl)); registry.initialize(owner); // Deploy factory - address factoryImpl = LibClone.clone( - address(new MagicDropCloneFactory()) - ); + address factoryImpl = LibClone.clone(address(new MagicDropCloneFactory())); factory = MagicDropCloneFactory(payable(factoryImpl)); factory.initialize(owner, address(registry)); @@ -69,19 +55,10 @@ contract MagicDropCloneFactoryTest is Test { erc1155Impl = new MockERC1155Initializable(); // Register implementations - erc721ImplId = registry.registerImplementation( - TokenStandard.ERC721, - address(erc721Impl), - true, - 0.01 ether, - 0.00001 ether - ); + erc721ImplId = + registry.registerImplementation(TokenStandard.ERC721, address(erc721Impl), true, 0.01 ether, 0.00001 ether); erc1155ImplId = registry.registerImplementation( - TokenStandard.ERC1155, - address(erc1155Impl), - true, - 0.01 ether, - 0.00001 ether + TokenStandard.ERC1155, address(erc1155Impl), true, 0.01 ether, 0.00001 ether ); // Fund user @@ -94,11 +71,7 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId ); MockERC721Initializable nft = MockERC721Initializable(newContract); @@ -113,13 +86,8 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC721ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - 0 - ); + address newContract = + factory.createContract{value: 0.01 ether}("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), 0); MockERC721Initializable nft = MockERC721Initializable(newContract); // Test minting @@ -133,11 +101,7 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - erc1155ImplId + "TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), erc1155ImplId ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -152,13 +116,8 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC1155ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - 0 - ); + address newContract = + factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -176,23 +135,10 @@ contract MagicDropCloneFactoryTest is Test { bytes32[] memory salts = new bytes32[](numSalts); for (uint256 i = 0; i < numSalts; i++) { - salts[i] = keccak256( - abi.encodePacked(i, block.timestamp, msg.sender) - ); - address predictedAddress = factory.predictDeploymentAddress( - TokenStandard.ERC721, - erc721ImplId, - salts[i] - ); - address deployedAddress = factory.createContractDeterministic{ - value: 0.01 ether - }( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - salts[i] + salts[i] = keccak256(abi.encodePacked(i, block.timestamp, msg.sender)); + address predictedAddress = factory.predictDeploymentAddress(TokenStandard.ERC721, erc721ImplId, salts[i]); + address deployedAddress = factory.createContractDeterministic{value: 0.01 ether}( + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, salts[i] ); assertEq(predictedAddress, deployedAddress); } @@ -205,34 +151,18 @@ contract MagicDropCloneFactoryTest is Test { vm.prank(user); vm.expectRevert(); - factory.createContract( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - invalidImplId - ); + factory.createContract("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), invalidImplId); } function testCreateDeterministicContractWithSameSalt() public { vm.startPrank(user); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT1", - "TNFT1", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(100)) + "TestNFT1", "TNFT1", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) ); vm.expectRevert(); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT2", - "TNFT2", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(100)) + "TestNFT2", "TNFT2", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) ); } @@ -245,23 +175,14 @@ contract MagicDropCloneFactoryTest is Test { string memory symbol = "TT"; // Predict the address where the contract will be deployed - address predictedAddress = factory.predictDeploymentAddress( - standard, - implId, - salt - ); + address predictedAddress = factory.predictDeploymentAddress(standard, implId, salt); // Deploy a dummy contract to the predicted address vm.etch(predictedAddress, address(erc721Impl).code); vm.expectRevert(); // Try to create a contract with the same parameters factory.createContractDeterministic{value: 0.01 ether}( - name, - symbol, - standard, - payable(initialOwner), - implId, - salt + name, symbol, standard, payable(initialOwner), implId, salt ); } @@ -270,38 +191,20 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); InvalidImplementation impl = new InvalidImplementation(); - uint32 implId = registry.registerImplementation( - standard, - address(impl), - false, - 0.01 ether, - 0.00001 ether - ); + uint32 implId = registry.registerImplementation(standard, address(impl), false, 0.01 ether, 0.00001 ether); vm.stopPrank(); vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", - "TNFT", - standard, - payable(user), - implId, - bytes32(uint256(102)) + "TestNFT", "TNFT", standard, payable(user), implId, bytes32(uint256(102)) ); } function testInsufficientDeploymentFee() public { vm.startPrank(user); - vm.expectRevert( - MagicDropCloneFactory.InsufficientDeploymentFee.selector - ); + vm.expectRevert(MagicDropCloneFactory.InsufficientDeploymentFee.selector); factory.createContractDeterministic{value: 0.005 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(103)) + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(103)) ); } @@ -311,13 +214,7 @@ contract MagicDropCloneFactoryTest is Test { function testWithdraw() public { vm.startPrank(user); - factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - 0 - ); + factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); vm.stopPrank(); vm.startPrank(owner); From c51ac8b9c821da10a932ca9b75acd03d95e915a6 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 20:48:07 -0500 Subject: [PATCH 08/12] remove forge fmt --- test/factory/MagicDropCloneFactoryTest.t.sol | 155 +++++++++++++++---- 1 file changed, 124 insertions(+), 31 deletions(-) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index 8a845b21..85b769cc 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -12,11 +12,21 @@ import {MagicDropTokenImplRegistry} from "../../contracts/registry/MagicDropToke import {TokenStandard} from "../../contracts/common/Structs.sol"; contract MockERC721Initializable is MockERC721 { - function initialize(string memory, string memory, address, uint256) public {} + function initialize( + string memory, + string memory, + address, + uint256 + ) public {} } contract MockERC1155Initializable is MockERC1155 { - function initialize(string memory, string memory, address, uint256) public {} + function initialize( + string memory, + string memory, + address, + uint256 + ) public {} } contract InvalidImplementation is MockERC721 { @@ -41,12 +51,16 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); // Deploy and initialize registry - address registryImpl = LibClone.clone(address(new MagicDropTokenImplRegistry())); + address registryImpl = LibClone.clone( + address(new MagicDropTokenImplRegistry()) + ); registry = MagicDropTokenImplRegistry(payable(registryImpl)); registry.initialize(owner); // Deploy factory - address factoryImpl = LibClone.clone(address(new MagicDropCloneFactory())); + address factoryImpl = LibClone.clone( + address(new MagicDropCloneFactory()) + ); factory = MagicDropCloneFactory(payable(factoryImpl)); factory.initialize(owner, address(registry)); @@ -55,10 +69,19 @@ contract MagicDropCloneFactoryTest is Test { erc1155Impl = new MockERC1155Initializable(); // Register implementations - erc721ImplId = - registry.registerImplementation(TokenStandard.ERC721, address(erc721Impl), true, 0.01 ether, 0.00001 ether); + erc721ImplId = registry.registerImplementation( + TokenStandard.ERC721, + address(erc721Impl), + true, + 0.01 ether, + 0.00001 ether + ); erc1155ImplId = registry.registerImplementation( - TokenStandard.ERC1155, address(erc1155Impl), true, 0.01 ether, 0.00001 ether + TokenStandard.ERC1155, + address(erc1155Impl), + true, + 0.01 ether, + 0.00001 ether ); // Fund user @@ -71,7 +94,11 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId ); MockERC721Initializable nft = MockERC721Initializable(newContract); @@ -86,8 +113,13 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC721ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = - factory.createContract{value: 0.01 ether}("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), 0); + address newContract = factory.createContract{value: 0.01 ether}( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + 0 + ); MockERC721Initializable nft = MockERC721Initializable(newContract); // Test minting @@ -101,7 +133,11 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), erc1155ImplId + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + erc1155ImplId ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -116,8 +152,13 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC1155ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = - factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); + address newContract = factory.createContract{value: 0.01 ether}( + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + 0 + ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -135,10 +176,23 @@ contract MagicDropCloneFactoryTest is Test { bytes32[] memory salts = new bytes32[](numSalts); for (uint256 i = 0; i < numSalts; i++) { - salts[i] = keccak256(abi.encodePacked(i, block.timestamp, msg.sender)); - address predictedAddress = factory.predictDeploymentAddress(TokenStandard.ERC721, erc721ImplId, salts[i]); - address deployedAddress = factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, salts[i] + salts[i] = keccak256( + abi.encodePacked(i, block.timestamp, msg.sender) + ); + address predictedAddress = factory.predictDeploymentAddress( + TokenStandard.ERC721, + erc721ImplId, + salts[i] + ); + address deployedAddress = factory.createContractDeterministic{ + value: 0.01 ether + }( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + salts[i] ); assertEq(predictedAddress, deployedAddress); } @@ -151,18 +205,34 @@ contract MagicDropCloneFactoryTest is Test { vm.prank(user); vm.expectRevert(); - factory.createContract("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), invalidImplId); + factory.createContract( + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + invalidImplId + ); } function testCreateDeterministicContractWithSameSalt() public { vm.startPrank(user); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT1", "TNFT1", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) + "TestNFT1", + "TNFT1", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(100)) ); vm.expectRevert(); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT2", "TNFT2", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) + "TestNFT2", + "TNFT2", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(100)) ); } @@ -175,14 +245,23 @@ contract MagicDropCloneFactoryTest is Test { string memory symbol = "TT"; // Predict the address where the contract will be deployed - address predictedAddress = factory.predictDeploymentAddress(standard, implId, salt); + address predictedAddress = factory.predictDeploymentAddress( + standard, + implId, + salt + ); // Deploy a dummy contract to the predicted address vm.etch(predictedAddress, address(erc721Impl).code); vm.expectRevert(); // Try to create a contract with the same parameters factory.createContractDeterministic{value: 0.01 ether}( - name, symbol, standard, payable(initialOwner), implId, salt + name, + symbol, + standard, + payable(initialOwner), + implId, + salt ); } @@ -191,20 +270,28 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); InvalidImplementation impl = new InvalidImplementation(); - uint32 implId = registry.registerImplementation(standard, address(impl), false, 0.01 ether, 0.00001 ether); - vm.stopPrank(); - - vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); - factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", "TNFT", standard, payable(user), implId, bytes32(uint256(102)) + uint32 implId = registry.registerImplementation( + standard, + address(impl), + false, + 0.01 ether, + 0.00001 ether ); + vm.stopPrank(); } function testInsufficientDeploymentFee() public { vm.startPrank(user); - vm.expectRevert(MagicDropCloneFactory.InsufficientDeploymentFee.selector); + vm.expectRevert( + MagicDropCloneFactory.InsufficientDeploymentFee.selector + ); factory.createContractDeterministic{value: 0.005 ether}( - "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(103)) + "TestNFT", + "TNFT", + TokenStandard.ERC721, + payable(user), + erc721ImplId, + bytes32(uint256(103)) ); } @@ -214,7 +301,13 @@ contract MagicDropCloneFactoryTest is Test { function testWithdraw() public { vm.startPrank(user); - factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); + factory.createContract{value: 0.01 ether}( + "TestMultiToken", + "TMT", + TokenStandard.ERC1155, + payable(user), + 0 + ); vm.stopPrank(); vm.startPrank(owner); From 0a753b4716069984a2e791197a08a7071af34563 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 20:54:27 -0500 Subject: [PATCH 09/12] remove forge fmt --- test/factory/MagicDropCloneFactoryTest.t.sol | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index 85b769cc..ef79b5c9 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -267,17 +267,6 @@ contract MagicDropCloneFactoryTest is Test { function testInitializationFailed() public { TokenStandard standard = TokenStandard.ERC721; - - vm.startPrank(owner); - InvalidImplementation impl = new InvalidImplementation(); - uint32 implId = registry.registerImplementation( - standard, - address(impl), - false, - 0.01 ether, - 0.00001 ether - ); - vm.stopPrank(); } function testInsufficientDeploymentFee() public { From baabc567a90a9d394ac928c11371a5acf670024a Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Wed, 16 Jul 2025 21:06:30 -0500 Subject: [PATCH 10/12] found you --- test/factory/MagicDropCloneFactoryTest.t.sol | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index ef79b5c9..956258ac 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -46,10 +46,13 @@ contract MagicDropCloneFactoryTest is Test { uint32 internal erc721ImplId; uint32 internal erc1155ImplId; + InvalidImplementation invalidImplementation; function setUp() public { vm.startPrank(owner); + invalidImplementation = new InvalidImplementation(); + // Deploy and initialize registry address registryImpl = LibClone.clone( address(new MagicDropTokenImplRegistry()) @@ -267,6 +270,27 @@ contract MagicDropCloneFactoryTest is Test { function testInitializationFailed() public { TokenStandard standard = TokenStandard.ERC721; + + vm.startPrank(owner); + + uint32 implId = registry.registerImplementation( + standard, + address(invalidImplementation), + false, + 0.01 ether, + 0.00001 ether + ); + vm.stopPrank(); + + vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); + factory.createContractDeterministic{value: 0.01 ether}( + "TestNFT", + "TNFT", + standard, + payable(user), + implId, + bytes32(uint256(102)) + ); } function testInsufficientDeploymentFee() public { From e8627c8528a6c1b100876beb917aa2eb6e2dd6f4 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Thu, 17 Jul 2025 12:27:20 -0500 Subject: [PATCH 11/12] add back forge fmt --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8ceaa0e..05ec19bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,11 @@ jobs: run: | forge --version + - name: Run Forge fmt + run: | + forge fmt --check + id: fmt + - name: Run Forge build run: | forge build --via-ir --sizes From fc20662c22c08382b91ee8fdb33a61c73fc83755 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Thu, 17 Jul 2025 12:30:35 -0500 Subject: [PATCH 12/12] actually run forge fmt now --- test/factory/MagicDropCloneFactoryTest.t.sol | 158 ++++--------------- 1 file changed, 28 insertions(+), 130 deletions(-) diff --git a/test/factory/MagicDropCloneFactoryTest.t.sol b/test/factory/MagicDropCloneFactoryTest.t.sol index 956258ac..0d63d005 100644 --- a/test/factory/MagicDropCloneFactoryTest.t.sol +++ b/test/factory/MagicDropCloneFactoryTest.t.sol @@ -12,21 +12,11 @@ import {MagicDropTokenImplRegistry} from "../../contracts/registry/MagicDropToke import {TokenStandard} from "../../contracts/common/Structs.sol"; contract MockERC721Initializable is MockERC721 { - function initialize( - string memory, - string memory, - address, - uint256 - ) public {} + function initialize(string memory, string memory, address, uint256) public {} } contract MockERC1155Initializable is MockERC1155 { - function initialize( - string memory, - string memory, - address, - uint256 - ) public {} + function initialize(string memory, string memory, address, uint256) public {} } contract InvalidImplementation is MockERC721 { @@ -54,16 +44,12 @@ contract MagicDropCloneFactoryTest is Test { invalidImplementation = new InvalidImplementation(); // Deploy and initialize registry - address registryImpl = LibClone.clone( - address(new MagicDropTokenImplRegistry()) - ); + address registryImpl = LibClone.clone(address(new MagicDropTokenImplRegistry())); registry = MagicDropTokenImplRegistry(payable(registryImpl)); registry.initialize(owner); // Deploy factory - address factoryImpl = LibClone.clone( - address(new MagicDropCloneFactory()) - ); + address factoryImpl = LibClone.clone(address(new MagicDropCloneFactory())); factory = MagicDropCloneFactory(payable(factoryImpl)); factory.initialize(owner, address(registry)); @@ -72,19 +58,10 @@ contract MagicDropCloneFactoryTest is Test { erc1155Impl = new MockERC1155Initializable(); // Register implementations - erc721ImplId = registry.registerImplementation( - TokenStandard.ERC721, - address(erc721Impl), - true, - 0.01 ether, - 0.00001 ether - ); + erc721ImplId = + registry.registerImplementation(TokenStandard.ERC721, address(erc721Impl), true, 0.01 ether, 0.00001 ether); erc1155ImplId = registry.registerImplementation( - TokenStandard.ERC1155, - address(erc1155Impl), - true, - 0.01 ether, - 0.00001 ether + TokenStandard.ERC1155, address(erc1155Impl), true, 0.01 ether, 0.00001 ether ); // Fund user @@ -97,11 +74,7 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId ); MockERC721Initializable nft = MockERC721Initializable(newContract); @@ -116,13 +89,8 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC721ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = factory.createContract{value: 0.01 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - 0 - ); + address newContract = + factory.createContract{value: 0.01 ether}("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), 0); MockERC721Initializable nft = MockERC721Initializable(newContract); // Test minting @@ -136,11 +104,7 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(user); address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - erc1155ImplId + "TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), erc1155ImplId ); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -155,13 +119,8 @@ contract MagicDropCloneFactoryTest is Test { function testCreateERC1155ContractWithDefaultImplementation() public { vm.startPrank(user); - address newContract = factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - 0 - ); + address newContract = + factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); MockERC1155Initializable nft = MockERC1155Initializable(newContract); @@ -179,23 +138,10 @@ contract MagicDropCloneFactoryTest is Test { bytes32[] memory salts = new bytes32[](numSalts); for (uint256 i = 0; i < numSalts; i++) { - salts[i] = keccak256( - abi.encodePacked(i, block.timestamp, msg.sender) - ); - address predictedAddress = factory.predictDeploymentAddress( - TokenStandard.ERC721, - erc721ImplId, - salts[i] - ); - address deployedAddress = factory.createContractDeterministic{ - value: 0.01 ether - }( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - salts[i] + salts[i] = keccak256(abi.encodePacked(i, block.timestamp, msg.sender)); + address predictedAddress = factory.predictDeploymentAddress(TokenStandard.ERC721, erc721ImplId, salts[i]); + address deployedAddress = factory.createContractDeterministic{value: 0.01 ether}( + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, salts[i] ); assertEq(predictedAddress, deployedAddress); } @@ -208,34 +154,18 @@ contract MagicDropCloneFactoryTest is Test { vm.prank(user); vm.expectRevert(); - factory.createContract( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - invalidImplId - ); + factory.createContract("TestNFT", "TNFT", TokenStandard.ERC721, payable(user), invalidImplId); } function testCreateDeterministicContractWithSameSalt() public { vm.startPrank(user); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT1", - "TNFT1", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(100)) + "TestNFT1", "TNFT1", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) ); vm.expectRevert(); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT2", - "TNFT2", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(100)) + "TestNFT2", "TNFT2", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(100)) ); } @@ -248,23 +178,14 @@ contract MagicDropCloneFactoryTest is Test { string memory symbol = "TT"; // Predict the address where the contract will be deployed - address predictedAddress = factory.predictDeploymentAddress( - standard, - implId, - salt - ); + address predictedAddress = factory.predictDeploymentAddress(standard, implId, salt); // Deploy a dummy contract to the predicted address vm.etch(predictedAddress, address(erc721Impl).code); vm.expectRevert(); // Try to create a contract with the same parameters factory.createContractDeterministic{value: 0.01 ether}( - name, - symbol, - standard, - payable(initialOwner), - implId, - salt + name, symbol, standard, payable(initialOwner), implId, salt ); } @@ -273,38 +194,21 @@ contract MagicDropCloneFactoryTest is Test { vm.startPrank(owner); - uint32 implId = registry.registerImplementation( - standard, - address(invalidImplementation), - false, - 0.01 ether, - 0.00001 ether - ); + uint32 implId = + registry.registerImplementation(standard, address(invalidImplementation), false, 0.01 ether, 0.00001 ether); vm.stopPrank(); vm.expectRevert(MagicDropCloneFactory.InitializationFailed.selector); factory.createContractDeterministic{value: 0.01 ether}( - "TestNFT", - "TNFT", - standard, - payable(user), - implId, - bytes32(uint256(102)) + "TestNFT", "TNFT", standard, payable(user), implId, bytes32(uint256(102)) ); } function testInsufficientDeploymentFee() public { vm.startPrank(user); - vm.expectRevert( - MagicDropCloneFactory.InsufficientDeploymentFee.selector - ); + vm.expectRevert(MagicDropCloneFactory.InsufficientDeploymentFee.selector); factory.createContractDeterministic{value: 0.005 ether}( - "TestNFT", - "TNFT", - TokenStandard.ERC721, - payable(user), - erc721ImplId, - bytes32(uint256(103)) + "TestNFT", "TNFT", TokenStandard.ERC721, payable(user), erc721ImplId, bytes32(uint256(103)) ); } @@ -314,13 +218,7 @@ contract MagicDropCloneFactoryTest is Test { function testWithdraw() public { vm.startPrank(user); - factory.createContract{value: 0.01 ether}( - "TestMultiToken", - "TMT", - TokenStandard.ERC1155, - payable(user), - 0 - ); + factory.createContract{value: 0.01 ether}("TestMultiToken", "TMT", TokenStandard.ERC1155, payable(user), 0); vm.stopPrank(); vm.startPrank(owner);