diff --git a/test/TheBadge/Config.sol b/test/TheBadge/Config.sol new file mode 100644 index 0000000..ccd88e7 --- /dev/null +++ b/test/TheBadge/Config.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import { Test } from "forge-std/Test.sol"; +import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol"; +import { TheBadgeStore } from "../../src/contracts/thebadge/TheBadgeStore.sol"; +import { TheBadge } from "../../src/contracts/thebadge/TheBadge.sol"; + + +contract Config is Test { + address admin = vm.addr(1); + address feeCollector = vm.addr(2); + address u1 = vm.addr(3); + address u2 = vm.addr(4); + + TheBadgeStore badgeStore; + TheBadge badge; + + function setUp() public { + vm.deal(u1, 1 ether); + vm.deal(u2, 1 ether); + vm.deal(feeCollector, 0 ether); + + address badgeStoreProxy = Clones.clone(address(new TheBadgeStore())); + badgeStore = TheBadgeStore(payable(badgeStoreProxy)); + badgeStore.initialize(admin, feeCollector); + + address badgeProxy = Clones.clone(address(new TheBadge())); + badge = TheBadge(payable(badgeProxy)); + badge.initialize(admin, badgeStoreProxy); + } +} diff --git a/test/TheBadge/Mint.t.sol b/test/TheBadge/Mint.t.sol new file mode 100644 index 0000000..83c7fbf --- /dev/null +++ b/test/TheBadge/Mint.t.sol @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.20; + +import { Config } from "./Config.sol"; +import { TheBadgeStore } from "../../src/contracts/thebadge/TheBadgeStore.sol"; +import { IBadgeModelController } from "../../src/interfaces/IBadgeModelController.sol"; + +contract Mint is Config { + function testWorks() public { + vm.startPrank(admin); + badgeStore.addPermittedContract("TheBadge", address(badge)); + vm.stopPrank(); + + address controllerAddress = vm.addr(11); + vm.deal(controllerAddress, 10 ether); + string memory controllerName = "controllerName"; + + TheBadgeStore.BadgeModelController memory _badgeModelController = TheBadgeStore.BadgeModelController({ + controller: controllerAddress, + initialized: true, + paused: false + }); + + uint256 mintCreatorFee = 0.1e18; + + vm.startPrank(address(badge)); + badgeStore.addBadgeModelController(controllerName, _badgeModelController); + badgeStore.addBadgeModel( + TheBadgeStore.BadgeModel( + u1, + controllerName, + false, + mintCreatorFee, + 100, + 1000, + true, + 1, + false, + false, + "metadata" + ) + ); + vm.stopPrank(); + + uint256 badgeModelId = 0; + string memory tokenURI = "ipfs://metadata"; + bytes memory data = "blabla"; + + uint256 controllerMintValue = 0.2e18; + + vm.mockCall( + controllerAddress, + abi.encodeWithSelector(IBadgeModelController.mintValue.selector, badgeModelId), + abi.encode(controllerMintValue) + ); + + vm.deal(address(badge), 10 ether); + + vm.mockCall( + controllerAddress, + abi.encodeWithSelector(IBadgeModelController.mint.selector), + abi.encode(1) + ); + + vm.prank(u2); + badge.mint{ value: (controllerMintValue + mintCreatorFee) }(badgeModelId, u1, tokenURI, data); + } +}