misc: SVG Profile Traits added with test script

This commit is contained in:
vicnaum
2023-11-17 17:12:52 +01:00
parent 4af3dc28cd
commit c6ac7de171
8 changed files with 423 additions and 28 deletions

View File

@@ -0,0 +1,123 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import {ForkManagement} from 'script/helpers/ForkManagement.sol';
import 'forge-std/Script.sol';
import {ProfileTokenURI} from 'contracts/misc/token-uris/ProfileTokenURI.sol';
import {ERC721} from '@openzeppelin/contracts/token/ERC721/ERC721.sol';
contract NFTMinter is ProfileTokenURI, ERC721 {
constructor() ERC721('Test Protocol', 'TEST') {}
function mintMany(uint256 tokenIdFrom, uint256 tokenIdTo) external {
for (uint256 i = tokenIdFrom; i < tokenIdTo; i++) {
_mint(msg.sender, i);
}
}
function mintFuzz(uint256 seed, uint256 n) external {
for (uint256 i = 0; i < n; i++) {
uint256 tokenId = uint256(keccak256(abi.encodePacked(seed, i))) % 130000;
if (!_exists(tokenId)) {
_mint(msg.sender, tokenId);
}
}
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return ProfileTokenURI.getTokenURI(tokenId, block.timestamp);
}
}
contract DeployTestProfiles is Script, ForkManagement {
using stdJson for string;
struct LensAccount {
uint256 ownerPk;
address owner;
uint256 profileId;
}
LensAccount _deployer;
string mnemonic;
NFTMinter nftMinter;
function loadPrivateKeys() internal {
if (isEnvSet('MNEMONIC')) {
mnemonic = vm.envString('MNEMONIC');
}
if (bytes(mnemonic).length == 0) {
revert('Missing mnemonic');
}
console.log('\n');
(_deployer.owner, _deployer.ownerPk) = deriveRememberKey(mnemonic, 0);
console.log('Deployer address: %s', address(_deployer.owner));
console.log('\n');
console.log('Current block:', block.number);
}
function deploy() internal {
console.log('\n');
console.log('Deploying NFTMinter contract...');
vm.startBroadcast(_deployer.ownerPk);
nftMinter = new NFTMinter();
vm.stopBroadcast();
console.log('NFTMinter address: %s', address(nftMinter));
console.log('\n');
}
function interact() internal {
nftMinter = NFTMinter(0x9358Fe2E2Ec00bd24eeee491DFd3d57333A88FBB);
vm.startBroadcast(_deployer.ownerPk);
nftMinter.mintMany(100, 101);
nftMinter.mintMany(200, 201);
nftMinter.mintMany(300, 301);
nftMinter.mintMany(400, 401);
nftMinter.mintMany(500, 501);
nftMinter.mintMany(600, 601);
nftMinter.mintMany(700, 701);
nftMinter.mintMany(800, 801);
nftMinter.mintMany(900, 901);
nftMinter.mintMany(1001, 1010);
// nftMinter.mintMany(1, 100);
// nftMinter.mintMany(101, 200);
// nftMinter.mintMany(201, 300);
// nftMinter.mintMany(301, 400);
// nftMinter.mintMany(401, 500);
// nftMinter.mintMany(501, 600);
// nftMinter.mintMany(601, 700);
// nftMinter.mintMany(701, 800);
// nftMinter.mintMany(801, 900);
// nftMinter.mintMany(901, 1001);
nftMinter.mintFuzz(1, 200);
nftMinter.mintFuzz(2, 200);
nftMinter.mintFuzz(3, 200);
nftMinter.mintFuzz(4, 200);
nftMinter.mintFuzz(5, 200);
nftMinter.mintFuzz(6, 200);
nftMinter.mintFuzz(7, 200);
nftMinter.mintFuzz(8, 200);
nftMinter.mintFuzz(9, 200);
nftMinter.mintFuzz(10, 200);
vm.stopBroadcast();
}
function run(string memory targetEnv_) external {
targetEnv = targetEnv_;
loadJson();
checkNetworkParams();
loadBaseAddresses();
loadPrivateKeys();
// deploy();
interact();
}
}

View File

@@ -12,10 +12,11 @@ import {Logo} from 'contracts/libraries/svgs/Profile/Logo.sol';
import {Headwear} from 'contracts/libraries/svgs/Profile/Headwear.sol';
import {ProfileSVG} from 'contracts/libraries/svgs/Profile/ProfileSVG.sol';
import {ProfileTokenURI} from 'contracts/misc/token-uris/ProfileTokenURI.sol';
contract ProfileNFT {
function tryProfile(uint256 profileId) external pure returns (string memory) {
(string memory profileSvg, ) = ProfileSVG.getProfileSVG(profileId);
function tryProfile(uint256 profileId) external view returns (string memory) {
(string memory profileSvg, ) = ProfileSVG.getProfileSVG(profileId, blockhash(block.number - 1));
return profileSvg;
}
@@ -31,10 +32,12 @@ contract ProfileNFT {
contract ProfileSVGGen is Test {
ProfileNFT profileNFT;
ProfileTokenURI profileTokenURI;
string constant dir = 'svgs/';
function setUp() public {
profileNFT = new ProfileNFT();
profileTokenURI = new ProfileTokenURI();
}
function _testElement(uint256 maxColors, Helpers.ComponentBytes componentByte, string memory elementName) internal {
@@ -209,6 +212,22 @@ contract ProfileSVGGen is Test {
}
}
function testGoldProfilesJson1() public {
uint256 i;
for (i = 1; i < 500; i++) {
string memory result = profileTokenURI.getTokenURI(i, i);
vm.writeFile(string.concat(dir, 'profiles_fuzz_json/profile_', vm.toString(i), '.json'), result);
}
}
function testGoldProfilesJson2() public {
uint256 i;
for (i = 500; i <= 1000; i++) {
string memory result = profileTokenURI.getTokenURI(i, i);
vm.writeFile(string.concat(dir, 'profiles_fuzz_json/profile_', vm.toString(i), '.json'), result);
}
}
function testHowManyHaveIcecream() public view {
console.log('How many have icecream?');
uint256 count;
@@ -241,6 +260,14 @@ contract ProfileSVGGen is Test {
}
}
function testFuzzProfilesJson() public {
for (uint256 i = 1; i < 500; i++) {
uint256 profileId = uint256(keccak256(abi.encode(i))) % 130000;
string memory result = profileTokenURI.getTokenURI(profileId, i);
vm.writeFile(string.concat(dir, 'profiles_fuzz_json/profile_', vm.toString(profileId), '.json'), result);
}
}
// We take variants from the right bytes of the seed
function setVariant(uint256 newByte, Helpers.ComponentBytes componentByte) internal pure returns (uint256) {
return newByte << (uint8(componentByte) * 8);

View File

@@ -12,6 +12,7 @@ mkdir headwear
mkdir profiles_gold
mkdir profiles
mkdir profiles_fuzz
mkdir profiles_fuzz_json
mkdir follows
mkdir handles
cd ..