Add SVG generation test and function.

This commit is contained in:
EmperorOrokuSaki 2023-01-09 18:52:04 +03:30
parent 04991eaeff
commit 090c1e1477
3 changed files with 72 additions and 41 deletions

View File

@ -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(
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="640" height="480" viewBox="0 0 640 480" xml:space="preserve">',
"<defs>",
"</defs>"
'<g transform="matrix(3.42 0 0 3.42 300.98 252.98)" >',
'<polygon style="stroke: rgb(0,0,0); stroke-width: 8; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(152,152,183); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" points="-50,-50 -50,50 50,50 50,-50 " />',
"</g>",
'<g transform="matrix(1 0 0 1 303.5 115.67)" style="" >',
'<text xml:space="preserve" font-family="Open Sans" font-size="24" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" ><tspan x="-45.7" y="5.65" style="stroke-width: 1; font-family: "Open Sans", sans-serif; font-size: 18px; font-style: normal; font-weight: normal; fill: rgb(0,0,0); ">Fleek NFAs</tspan></text>',
"</g>",
'<g transform="matrix(1 0 0 1 302 261.47)" style="" >',
'<text xml:space="preserve" font-family="Open Sans" font-size="28" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" ><tspan x="-44.26" y="-6.14" style="stroke-width: 1; font-family: "Open Sans", sans-serif; font-size: 18px; font-style: normal; font-weight: normal; fill: rgb(0,0,0); ">',
name,
'</tspan><tspan x="-37.14" y="17.45" style="stroke-width: 1; font-family: "Open Sans", sans-serif; font-size: 18px; font-style: normal; font-weight: normal; fill: rgb(0,0,0); ">',
ENS,
"</tspan></text>",
"</g>",
"</svg>"
)
)
);
}
/** /**
* @dev Mints a token and returns a tokenId. * @dev Mints a token and returns a tokenId.
* *
@ -71,7 +100,6 @@ contract FleekERC721 is ERC721, FleekAccessControl {
address to, address to,
string memory name, string memory name,
string memory description, string memory description,
string memory image,
string memory externalURL, string memory externalURL,
string memory ENS, string memory ENS,
string memory commitHash, string memory commitHash,
@ -84,7 +112,7 @@ contract FleekERC721 is ERC721, FleekAccessControl {
App storage app = _apps[tokenId]; App storage app = _apps[tokenId];
app.name = name; app.name = name;
app.description = description; app.description = description;
app.image = image; app.image = _generateSVG(name, ENS);
app.externalURL = externalURL; app.externalURL = externalURL;
app.ENS = ENS; app.ENS = ENS;

View File

@ -153,6 +153,8 @@ describe('FleekERC721', () => {
const parsedURI = JSON.parse(tokenURIDecoded); const parsedURI = JSON.parse(tokenURIDecoded);
console.log(parsedURI.image);
expect(parsedURI).to.eql({ expect(parsedURI).to.eql({
owner: fixture.owner.address.toLowerCase(), owner: fixture.owner.address.toLowerCase(),
name: MINT_PARAMS.name, name: MINT_PARAMS.name,

View File

@ -25,7 +25,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -41,7 +40,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -52,7 +50,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -68,7 +65,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -81,7 +77,6 @@ contract FleekTest is Test {
"Foundry Test App 2", "Foundry Test App 2",
"This is a test application submitted by foundry tests [2].", "This is a test application submitted by foundry tests [2].",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -96,7 +91,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -109,7 +103,6 @@ contract FleekTest is Test {
"Foundry Test App 2", "Foundry Test App 2",
"This is a test application submitted by foundry tests[2].", "This is a test application submitted by foundry tests[2].",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -118,14 +111,42 @@ contract FleekTest is Test {
assertEq(second_mint, 1); assertEq(second_mint, 1);
} }
function _generateSVG(string memory name, string memory ENS) internal returns (string memory) {
return (
string(
abi.encodePacked(
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="640" height="480" viewBox="0 0 640 480" xml:space="preserve">',
"<defs>",
"</defs>"
'<g transform="matrix(3.42 0 0 3.42 300.98 252.98)" >',
'<polygon style="stroke: rgb(0,0,0); stroke-width: 8; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(152,152,183); fill-rule: nonzero; opacity: 1;" vector-effect="non-scaling-stroke" points="-50,-50 -50,50 50,50 50,-50 " />',
"</g>",
'<g transform="matrix(1 0 0 1 303.5 115.67)" style="" >',
'<text xml:space="preserve" font-family="Open Sans" font-size="24" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" ><tspan x="-45.7" y="5.65" style="stroke-width: 1; font-family: "Open Sans", sans-serif; font-size: 18px; font-style: normal; font-weight: normal; fill: rgb(0,0,0); ">Fleek NFAs</tspan></text>',
"</g>",
'<g transform="matrix(1 0 0 1 302 261.47)" style="" >',
'<text xml:space="preserve" font-family="Open Sans" font-size="28" font-style="normal" font-weight="normal" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1; white-space: pre;" ><tspan x="-44.26" y="-6.14" style="stroke-width: 1; font-family: "Open Sans", sans-serif; font-size: 18px; font-style: normal; font-weight: normal; fill: rgb(0,0,0); ">',
name,
'</tspan><tspan x="-37.14" y="17.45" style="stroke-width: 1; font-family: "Open Sans", sans-serif; font-size: 18px; font-style: normal; font-weight: normal; fill: rgb(0,0,0); ">',
ENS,
"</tspan></text>",
"</g>",
"</svg>"
)
)
);
}
function testTokenURI() public { function testTokenURI() public {
string memory name = "Foundry Test App";
string memory ens = "fleek_xyz";
uint256 mint = fleekContract.mint( uint256 mint = fleekContract.mint(
DEPLOYER, DEPLOYER,
"Foundry Test App", name,
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz", ens,
"fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
); );
@ -136,15 +157,21 @@ contract FleekTest is Test {
bytes memory dataURI = abi.encodePacked( bytes memory dataURI = abi.encodePacked(
"{", "{",
'"name":"Foundry Test App",', '"name":"',
name,
'",',
'"description":"This is a test application submitted by foundry tests.",', '"description":"This is a test application submitted by foundry tests.",',
'"owner":"', '"owner":"',
Strings.toHexString(uint160(DEPLOYER), 20), Strings.toHexString(uint160(DEPLOYER), 20),
'",', '",',
'"external_url":"https://fleek.xyz",', '"external_url":"https://fleek.xyz",',
'"image":"https://fleek.xyz",', '"image":"',
_generateSVG(name, ens),
'",',
'"attributes": [', '"attributes": [',
'{"trait_type": "ENS", "value":"fleek_xyz"},', '{"trait_type": "ENS", "value":"',
ens,
'"},',
'{"trait_type": "Commit Hash", "value":"afff3f6"},', '{"trait_type": "Commit Hash", "value":"afff3f6"},',
'{"trait_type": "Repository", "value":"https://github.com/fleekxyz/non-fungible-apps"},', '{"trait_type": "Repository", "value":"https://github.com/fleekxyz/non-fungible-apps"},',
'{"trait_type": "Version", "value":"0"}', '{"trait_type": "Version", "value":"0"}',
@ -161,7 +188,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -205,7 +231,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -276,7 +301,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -297,7 +321,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -316,7 +339,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -341,7 +363,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -358,7 +379,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -377,7 +397,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -394,7 +413,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -413,7 +431,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -430,7 +447,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -449,7 +465,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -466,7 +481,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -485,7 +499,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -502,7 +515,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -521,7 +533,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -538,7 +549,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -557,7 +567,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -578,7 +587,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -601,7 +609,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -627,7 +634,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -653,7 +659,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -680,7 +685,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -711,7 +715,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -740,7 +743,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"
@ -765,7 +767,6 @@ contract FleekTest is Test {
"Foundry Test App", "Foundry Test App",
"This is a test application submitted by foundry tests.", "This is a test application submitted by foundry tests.",
"https://fleek.xyz", "https://fleek.xyz",
"https://fleek.xyz",
"fleek_xyz", "fleek_xyz",
"afff3f6", "afff3f6",
"https://github.com/fleekxyz/non-fungible-apps" "https://github.com/fleekxyz/non-fungible-apps"