-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add mint with referral funcionality #14
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/BaseGen.sol"; | ||
|
||
contract BaseGenReferralTest is Test { | ||
BaseGen public instance; | ||
uint256 public constant pricePerMint = 0.0015 ether; | ||
uint256 public constant quantity = 10; | ||
address public initialOwner; | ||
address public receiver; | ||
uint256 public maxSupply = 20; | ||
|
||
function setUp() public { | ||
initialOwner = vm.addr(1); | ||
receiver = vm.addr(2); | ||
string memory name = "Generative"; | ||
string memory symbol = "GEN"; | ||
string memory contractURI = "ipfs://"; | ||
string memory baseURI = "https://data.kodadot.xyz/base/"; // suffixed with /?hash= | ||
instance = new BaseGen(initialOwner, name, symbol, contractURI, baseURI, maxSupply, receiver); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you guide me in the difference between initialOwner and royalty receiver? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. InitialOwner is the provider (Koda) and receiver is the creator of the art. The logic without referrer was that payment is split in half between Koda and artist. |
||
} | ||
|
||
function testMintWithReferral() public { | ||
address tokenOwner = vm.addr(3); | ||
address referrer = vm.addr(4); | ||
|
||
// Calculate the total cost for minting | ||
uint256 totalCost = pricePerMint * quantity; | ||
vm.deal(tokenOwner, totalCost); | ||
|
||
// Assert initial state | ||
assertEq(instance.totalSupply(), 0); | ||
|
||
// Prank msg.sender as initialOwner to simulate the mint transaction | ||
vm.prank(tokenOwner); | ||
|
||
// Send sufficient funds to mint | ||
instance.mintWithReferral{value: totalCost}(tokenOwner, quantity, referrer); | ||
|
||
// Assert that totalSupply is updated correctly | ||
assertEq(instance.totalSupply(), quantity); | ||
|
||
// Assert the owner of the newly minted tokens | ||
for (uint256 i = 0; i < quantity; i++) { | ||
assertEq(instance.ownerOf(i), tokenOwner); | ||
} | ||
|
||
// Assert that the contract balance is transferred correctly | ||
uint256 receiverBalance = totalCost / 2; | ||
assertEq(receiver.balance, receiverBalance); | ||
uint256 referrerBalance = totalCost / 20; | ||
assertEq(referrer.balance, referrerBalance); | ||
assertEq(initialOwner.balance, receiverBalance- referrerBalance); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't feel right to use balance as what if minter will send more than needed?
Maybe we should make it equal here? L147
if it's okay, than probably it's the best way