From 090c1e1477c3ac3ccbf2efb0d4fff28d3c99f695 Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Mon, 9 Jan 2023 18:52:04 +0330 Subject: [PATCH] Add SVG generation test and function. --- contracts/FleekERC721.sol | 32 +++++++++++++++- test/FleekERC721.ts | 2 + test/foundry/apps.t.sol | 79 ++++++++++++++++++++------------------- 3 files changed, 72 insertions(+), 41 deletions(-) diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol index 96a69d8..a219204 100644 --- a/contracts/FleekERC721.sol +++ b/contracts/FleekERC721.sol @@ -57,6 +57,35 @@ contract FleekERC721 is ERC721, FleekAccessControl { _; } + /** + * @dev Generates a SVG image. + */ + function _generateSVG(string memory name, string memory ENS) internal returns (string memory) { + return ( + string( + abi.encodePacked( + '', + "", + "" + '', + '', + "", + '', + 'Fleek NFAs', + "", + '', + '', + name, + '', + ENS, + "", + "", + "" + ) + ) + ); + } + /** * @dev Mints a token and returns a tokenId. * @@ -71,7 +100,6 @@ contract FleekERC721 is ERC721, FleekAccessControl { address to, string memory name, string memory description, - string memory image, string memory externalURL, string memory ENS, string memory commitHash, @@ -84,7 +112,7 @@ contract FleekERC721 is ERC721, FleekAccessControl { App storage app = _apps[tokenId]; app.name = name; app.description = description; - app.image = image; + app.image = _generateSVG(name, ENS); app.externalURL = externalURL; app.ENS = ENS; diff --git a/test/FleekERC721.ts b/test/FleekERC721.ts index 7445f70..3391713 100644 --- a/test/FleekERC721.ts +++ b/test/FleekERC721.ts @@ -153,6 +153,8 @@ describe('FleekERC721', () => { const parsedURI = JSON.parse(tokenURIDecoded); + console.log(parsedURI.image); + expect(parsedURI).to.eql({ owner: fixture.owner.address.toLowerCase(), name: MINT_PARAMS.name, diff --git a/test/foundry/apps.t.sol b/test/foundry/apps.t.sol index 27a267e..2dc3e28 100644 --- a/test/foundry/apps.t.sol +++ b/test/foundry/apps.t.sol @@ -25,7 +25,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -41,7 +40,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -52,7 +50,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -68,7 +65,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -81,7 +77,6 @@ contract FleekTest is Test { "Foundry Test App 2", "This is a test application submitted by foundry tests [2].", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -96,7 +91,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -109,7 +103,6 @@ contract FleekTest is Test { "Foundry Test App 2", "This is a test application submitted by foundry tests[2].", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -118,14 +111,42 @@ contract FleekTest is Test { assertEq(second_mint, 1); } + function _generateSVG(string memory name, string memory ENS) internal returns (string memory) { + return ( + string( + abi.encodePacked( + '', + "", + "" + '', + '', + "", + '', + 'Fleek NFAs', + "", + '', + '', + name, + '', + ENS, + "", + "", + "" + ) + ) + ); + } + function testTokenURI() public { + string memory name = "Foundry Test App"; + string memory ens = "fleek_xyz"; + uint256 mint = fleekContract.mint( DEPLOYER, - "Foundry Test App", + name, "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", - "fleek_xyz", + ens, "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" ); @@ -136,15 +157,21 @@ contract FleekTest is Test { bytes memory dataURI = abi.encodePacked( "{", - '"name":"Foundry Test App",', + '"name":"', + name, + '",', '"description":"This is a test application submitted by foundry tests.",', '"owner":"', Strings.toHexString(uint160(DEPLOYER), 20), '",', '"external_url":"https://fleek.xyz",', - '"image":"https://fleek.xyz",', + '"image":"', + _generateSVG(name, ens), + '",', '"attributes": [', - '{"trait_type": "ENS", "value":"fleek_xyz"},', + '{"trait_type": "ENS", "value":"', + ens, + '"},', '{"trait_type": "Commit Hash", "value":"afff3f6"},', '{"trait_type": "Repository", "value":"https://github.com/fleekxyz/non-fungible-apps"},', '{"trait_type": "Version", "value":"0"}', @@ -161,7 +188,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -205,7 +231,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -276,7 +301,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -297,7 +321,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -316,7 +339,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -341,7 +363,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -358,7 +379,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -377,7 +397,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -394,7 +413,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -413,7 +431,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -430,7 +447,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -449,7 +465,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -466,7 +481,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -485,7 +499,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -502,7 +515,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -521,7 +533,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -538,7 +549,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -557,7 +567,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -578,7 +587,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -601,7 +609,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -627,7 +634,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -653,7 +659,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -680,7 +685,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -711,7 +715,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -740,7 +743,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps" @@ -765,7 +767,6 @@ contract FleekTest is Test { "Foundry Test App", "This is a test application submitted by foundry tests.", "https://fleek.xyz", - "https://fleek.xyz", "fleek_xyz", "afff3f6", "https://github.com/fleekxyz/non-fungible-apps"