From 090c1e1477c3ac3ccbf2efb0d4fff28d3c99f695 Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Mon, 9 Jan 2023 18:52:04 +0330 Subject: [PATCH 1/6] 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" From 810739c740f0d42883102d118cf7cf852f42abac Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Mon, 9 Jan 2023 19:48:17 +0330 Subject: [PATCH 2/6] Add optimization to hardhat config & comment the tokenURI hardhat test --- contracts/FleekERC721.sol | 2 +- hardhat.config.ts | 14 ++++++++++---- test/FleekERC721.ts | 26 ++++++++++++++++++-------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol index a219204..6a847f5 100644 --- a/contracts/FleekERC721.sol +++ b/contracts/FleekERC721.sol @@ -66,7 +66,7 @@ contract FleekERC721 is ERC721, FleekAccessControl { abi.encodePacked( '', "", - "" + "", '', '', "", diff --git a/hardhat.config.ts b/hardhat.config.ts index d33d74e..d8bf1ac 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -52,11 +52,17 @@ const config: HardhatUserConfig = { }, }, solidity: { - compilers: [ - { - version: '0.8.7', + version: '0.8.7', + settings: { + optimizer: { + enabled: true, + runs: 200, + details: { + yul: false, + }, }, - ], + viaIR: false, + }, }, mocha: { timeout: 200000, // 200 seconds max for running tests diff --git a/test/FleekERC721.ts b/test/FleekERC721.ts index 3391713..ab98e48 100644 --- a/test/FleekERC721.ts +++ b/test/FleekERC721.ts @@ -59,7 +59,6 @@ describe('FleekERC721', () => { owner.address, MINT_PARAMS.name, MINT_PARAMS.description, - MINT_PARAMS.image, MINT_PARAMS.externalUrl, MINT_PARAMS.ens, MINT_PARAMS.commitHash, @@ -80,7 +79,6 @@ describe('FleekERC721', () => { otherAccount.address, MINT_PARAMS.name, MINT_PARAMS.description, - MINT_PARAMS.image, MINT_PARAMS.externalUrl, MINT_PARAMS.ens, MINT_PARAMS.commitHash, @@ -98,7 +96,6 @@ describe('FleekERC721', () => { owner.address, MINT_PARAMS.name, MINT_PARAMS.description, - MINT_PARAMS.image, MINT_PARAMS.externalUrl, MINT_PARAMS.ens, MINT_PARAMS.commitHash, @@ -132,7 +129,6 @@ describe('FleekERC721', () => { fixture.owner.address, MINT_PARAMS.name, MINT_PARAMS.description, - MINT_PARAMS.image, MINT_PARAMS.externalUrl, MINT_PARAMS.ens, MINT_PARAMS.commitHash, @@ -143,7 +139,7 @@ describe('FleekERC721', () => { }); it('should return the token URI', async () => { - const { contract } = fixture; + /**const { contract } = fixture; const tokenURI = await contract.tokenURI(tokenId); const tokenURIDecoded = Buffer.from( @@ -159,7 +155,22 @@ describe('FleekERC721', () => { owner: fixture.owner.address.toLowerCase(), name: MINT_PARAMS.name, description: MINT_PARAMS.description, - image: MINT_PARAMS.image, + image: ''+""+ + +"" + +'' + +'' + +"" + +'' + +'Fleek NFAs' + +"" + +'' + +'' + +MINT_PARAMS.name + +'' + +MINT_PARAMS.ens + +"" + +"" + +"", external_url: MINT_PARAMS.externalUrl, attributes: [ { @@ -179,7 +190,7 @@ describe('FleekERC721', () => { value: '0', }, ], - }); + });**/ }); }); @@ -195,7 +206,6 @@ describe('FleekERC721', () => { fixture.owner.address, MINT_PARAMS.name, MINT_PARAMS.description, - MINT_PARAMS.image, MINT_PARAMS.externalUrl, MINT_PARAMS.ens, MINT_PARAMS.commitHash, From 75ae5fa4403718f31776111801de278cbd3d7b84 Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Wed, 11 Jan 2023 17:36:50 +0330 Subject: [PATCH 3/6] Move calling _genenrateSVG() to tokenURI() from mint() --- contracts/FleekERC721.sol | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol index 6a847f5..3b38c76 100644 --- a/contracts/FleekERC721.sol +++ b/contracts/FleekERC721.sol @@ -26,7 +26,6 @@ contract FleekERC721 is ERC721, FleekAccessControl { struct App { string name; // Name of the site string description; // Description about the site - string image; // Preview Image IPFS Link string externalURL; // Site URL string ENS; // ENS ID uint256 currentBuild; // The current build number (Increments by one with each change, starts at zero) @@ -112,7 +111,6 @@ contract FleekERC721 is ERC721, FleekAccessControl { App storage app = _apps[tokenId]; app.name = name; app.description = description; - app.image = _generateSVG(name, ENS); app.externalURL = externalURL; app.ENS = ENS; @@ -145,7 +143,7 @@ contract FleekERC721 is ERC721, FleekAccessControl { '"description":"', app.description, '",', '"owner":"', Strings.toHexString(uint160(owner), 20), '",', '"external_url":"', app.externalURL, '",', - '"image":"', app.image, '",', + '"image":"', _generateSVG(app.name, app.ENS), '",', '"attributes": [', '{"trait_type": "ENS", "value":"', app.ENS,'"},', '{"trait_type": "Commit Hash", "value":"', app.builds[app.currentBuild].commitHash,'"},', @@ -275,26 +273,6 @@ contract FleekERC721 is ERC721, FleekAccessControl { emit NewTokenDescription(tokenId, _tokenDescription, msg.sender); } - /** - * @dev Updates the `image` metadata field of a minted `tokenId`. - * - * May emit a {NewTokenImage} event. - * - * Requirements: - * - * - the tokenId must be minted and valid. - * - the sender must have the `tokenController` role. - * - */ - function setTokenImage( - uint256 tokenId, - string memory _tokenImage - ) public virtual requireTokenRole(tokenId, Roles.Controller) { - _requireMinted(tokenId); - _apps[tokenId].image = _tokenImage; - emit NewTokenImage(tokenId, _tokenImage, msg.sender); - } - /** * @dev Adds a new build to a minted `tokenId`'s builds mapping. * From 9013bd9faf3f95fda69cc52612cb8ac3b83fb7b8 Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Wed, 11 Jan 2023 17:46:33 +0330 Subject: [PATCH 4/6] Change _generateSVG() mutability to pure from view --- contracts/FleekERC721.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol index 3b38c76..2cee076 100644 --- a/contracts/FleekERC721.sol +++ b/contracts/FleekERC721.sol @@ -59,7 +59,7 @@ contract FleekERC721 is ERC721, FleekAccessControl { /** * @dev Generates a SVG image. */ - function _generateSVG(string memory name, string memory ENS) internal returns (string memory) { + function _generateSVG(string memory name, string memory ENS) internal pure returns (string memory) { return ( string( abi.encodePacked( From 94caa633ff1a75f777a7eed35374865cc3d0daf3 Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Wed, 11 Jan 2023 17:51:35 +0330 Subject: [PATCH 5/6] Remove foundry test cases that call setTokenImage() since that function is removed from the code base --- test/foundry/apps.t.sol | 44 ++++++----------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/test/foundry/apps.t.sol b/test/foundry/apps.t.sol index 2dc3e28..b130ddb 100644 --- a/test/foundry/apps.t.sol +++ b/test/foundry/apps.t.sol @@ -197,7 +197,6 @@ contract FleekTest is Test { fleekContract.setTokenName(mint, "Foundry Test App 2"); fleekContract.setTokenDescription(mint, "This is a test application submitted by foundry tests. 2"); - fleekContract.setTokenImage(mint, "https://fleek2.xyz"); fleekContract.setTokenExternalURL(mint, "https://fleek2.xyz"); fleekContract.setTokenENS(mint, "fleek_xyz2"); fleekContract.setTokenBuild(mint, "afff3f62", "https://github.com/fleekxyz/non-fungible-apps2"); @@ -212,7 +211,9 @@ contract FleekTest is Test { Strings.toHexString(uint160(DEPLOYER), 20), '",', '"external_url":"https://fleek2.xyz",', - '"image":"https://fleek2.xyz",', + '"image":"', + _generateSVG("Foundry Test App 2", "fleek_xyz2"), + '",', '"attributes": [', '{"trait_type": "ENS", "value":"fleek_xyz2"},', '{"trait_type": "Commit Hash", "value":"afff3f62"},', @@ -242,7 +243,6 @@ contract FleekTest is Test { fleekContract.setTokenName(mint, "Foundry Test App 2"); fleekContract.setTokenDescription(mint, "This is a test application submitted by foundry tests. 2"); - fleekContract.setTokenImage(mint, "https://fleek2.xyz"); fleekContract.setTokenExternalURL(mint, "https://fleek2.xyz"); fleekContract.setTokenENS(mint, "fleek_xyz2"); fleekContract.setTokenBuild(mint, "afff3f62", "https://github.com/fleekxyz/non-fungible-apps2"); @@ -257,7 +257,9 @@ contract FleekTest is Test { Strings.toHexString(uint160(DEPLOYER), 20), '",', '"external_url":"https://fleek2.xyz",', - '"image":"https://fleek2.xyz",', + '"image":"', + _generateSVG("Foundry Test App 2", "fleek_xyz2"), + '",', '"attributes": [', '{"trait_type": "ENS", "value":"fleek_xyz2"},', '{"trait_type": "Commit Hash", "value":"afff3f62"},', @@ -425,40 +427,6 @@ contract FleekTest is Test { fleekContract.setTokenDescription(mint, "NEW TOKEN NAME!"); } - function testSetTokenImage() public { - uint256 mint = fleekContract.mint( - DEPLOYER, - "Foundry Test App", - "This is a test application submitted by foundry tests.", - "https://fleek.xyz", - "fleek_xyz", - "afff3f6", - "https://github.com/fleekxyz/non-fungible-apps" - ); - - assertEq(mint, 0); - - fleekContract.setTokenImage(mint, "https://ethereum.org"); - } - - function testFailSetTokenImageOnAnotherUsersTokenWithoutAccess() public { - uint256 mint = fleekContract.mint( - DEPLOYER, - "Foundry Test App", - "This is a test application submitted by foundry tests.", - "https://fleek.xyz", - "fleek_xyz", - "afff3f6", - "https://github.com/fleekxyz/non-fungible-apps" - ); - - assertEq(mint, 0); - - vm.prank(address(0xb4c79daB8f259C7Aee6E5b2Aa729821864227e84)); - - fleekContract.setTokenImage(mint, "https://ethereum.org"); - } - function testSetTokenExternalURL() public { uint256 mint = fleekContract.mint( DEPLOYER, From 69de99467ff278036aadcde22b420b92ffdb6c8c Mon Sep 17 00:00:00 2001 From: EmperorOrokuSaki Date: Wed, 11 Jan 2023 18:55:51 +0330 Subject: [PATCH 6/6] Fix the HardHat decoding bug by adding base URI to _generateSVG() and updating foundry tests --- contracts/FleekERC721.sol | 41 +++++++++++++++++++---------------- test/FleekERC721.ts | 45 ++++++++++++++++++++++----------------- test/foundry/apps.t.sol | 41 +++++++++++++++++++---------------- 3 files changed, 72 insertions(+), 55 deletions(-) diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol index 2cee076..956882d 100644 --- a/contracts/FleekERC721.sol +++ b/contracts/FleekERC721.sol @@ -59,27 +59,32 @@ contract FleekERC721 is ERC721, FleekAccessControl { /** * @dev Generates a SVG image. */ - function _generateSVG(string memory name, string memory ENS) internal pure returns (string memory) { + function _generateSVG(string memory name, string memory ENS) internal view returns (string memory) { return ( string( abi.encodePacked( - '', - "", - "", - '', - '', - "", - '', - 'Fleek NFAs', - "", - '', - '', - name, - '', - ENS, - "", - "", - "" + _baseURI(), + Base64.encode( + abi.encodePacked( + '', + "", + "", + '', + '', + "", + '', + 'Fleek NFAs', + "", + '', + '', + name, + '', + ENS, + "", + "", + "" + ) + ) ) ) ); diff --git a/test/FleekERC721.ts b/test/FleekERC721.ts index ab98e48..482763a 100644 --- a/test/FleekERC721.ts +++ b/test/FleekERC721.ts @@ -139,7 +139,7 @@ describe('FleekERC721', () => { }); it('should return the token URI', async () => { - /**const { contract } = fixture; + const { contract } = fixture; const tokenURI = await contract.tokenURI(tokenId); const tokenURIDecoded = Buffer.from( @@ -149,28 +149,35 @@ describe('FleekERC721', () => { const parsedURI = JSON.parse(tokenURIDecoded); - console.log(parsedURI.image); + const imageDecoded = Buffer.from( + parsedURI.image.replace('data:application/json;base64,', ''), + 'base64' + ).toString('ascii'); + + parsedURI.image = imageDecoded; expect(parsedURI).to.eql({ owner: fixture.owner.address.toLowerCase(), name: MINT_PARAMS.name, description: MINT_PARAMS.description, - image: ''+""+ - +"" - +'' - +'' - +"" - +'' - +'Fleek NFAs' - +"" - +'' - +'' - +MINT_PARAMS.name - +'' - +MINT_PARAMS.ens - +"" - +"" - +"", + image: + '' + + '' + + '' + + '' + + '' + + '' + + '' + + 'Fleek NFAs' + + '' + + '' + + '' + + MINT_PARAMS.name + + '' + + MINT_PARAMS.ens + + '' + + '' + + '', external_url: MINT_PARAMS.externalUrl, attributes: [ { @@ -190,7 +197,7 @@ describe('FleekERC721', () => { value: '0', }, ], - });**/ + }); }); }); diff --git a/test/foundry/apps.t.sol b/test/foundry/apps.t.sol index b130ddb..5689423 100644 --- a/test/foundry/apps.t.sol +++ b/test/foundry/apps.t.sol @@ -111,27 +111,32 @@ contract FleekTest is Test { assertEq(second_mint, 1); } - function _generateSVG(string memory name, string memory ENS) internal returns (string memory) { + function _generateSVG(string memory name, string memory ENS) internal pure returns (string memory) { return ( string( abi.encodePacked( - '', - "", - "" - '', - '', - "", - '', - 'Fleek NFAs', - "", - '', - '', - name, - '', - ENS, - "", - "", - "" + "data:application/json;base64,", + Base64.encode( + abi.encodePacked( + '', + "", + "", + '', + '', + "", + '', + 'Fleek NFAs', + "", + '', + '', + name, + '', + ENS, + "", + "", + "" + ) + ) ) ) );