-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTestTokenUri.s.sol
More file actions
113 lines (98 loc) · 5.43 KB
/
Copy pathTestTokenUri.s.sol
File metadata and controls
113 lines (98 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "forge-std/Script.sol";
import "../src/Ethscriptions.sol";
import "../script/L2Genesis.s.sol";
import {Base64} from "solady/utils/Base64.sol";
contract TestTokenUri is Script {
function run() public {
// Deploy system
L2Genesis genesis = new L2Genesis();
genesis.runWithoutDump();
Ethscriptions eth = Ethscriptions(Predeploys.ETHSCRIPTIONS);
// Test case 1: Plain text (should use viewer)
vm.prank(address(0x1111));
eth.createEthscription(Ethscriptions.CreateEthscriptionParams({
transactionHash: keccak256("text1"),
contentUriHash: keccak256("data:text/plain,Hello World!"),
initialOwner: address(0x1111),
content: bytes("Hello World!"),
mimetype: "text/plain",
esip6: false,
protocolParams: Ethscriptions.ProtocolParams("", "", "")
}));
// Test case 2: JSON content (should use viewer with pretty print)
vm.prank(address(0x2222));
eth.createEthscription(Ethscriptions.CreateEthscriptionParams({
transactionHash: keccak256("json1"),
contentUriHash: keccak256('data:application/json,{"p":"erc-20","op":"mint","tick":"test","amt":"1000"}'),
initialOwner: address(0x2222),
content: bytes('{"p":"erc-20","op":"mint","tick":"test","amt":"1000"}'),
mimetype: "application/json",
esip6: false,
protocolParams: Ethscriptions.ProtocolParams("", "", "")
}));
// Test case 3: HTML content (should pass through directly)
vm.prank(address(0x3333));
eth.createEthscription(Ethscriptions.CreateEthscriptionParams({
transactionHash: keccak256("html1"),
contentUriHash: keccak256('data:text/html,<html><body style="background:linear-gradient(45deg,#ff006e,#8338ec);color:white;font-family:monospace;display:flex;align-items:center;justify-content:center;height:100vh;margin:0"><h1>Ethscriptions Rule!</h1></body></html>'),
initialOwner: address(0x3333),
content: bytes('<html><body style="background:linear-gradient(45deg,#ff006e,#8338ec);color:white;font-family:monospace;display:flex;align-items:center;justify-content:center;height:100vh;margin:0"><h1>Ethscriptions Rule!</h1></body></html>'),
mimetype: "text/html",
esip6: false,
protocolParams: Ethscriptions.ProtocolParams("", "", "")
}));
// Test case 4: Image (1x1 red pixel PNG, base64)
bytes memory redPixelPng = Base64.decode("iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAm0lEQVR42mNgGITgPxTTxvBleTo0swBsOK0s+N8aJkczC1AMR7KAKpb8v72xAY5hFsD4lFoCN+j56ZUoliBbSoklGIZjwxRbQAjT1YK7d+82kGUBeuQii5FrAYYrL81NwCpGFQtoEUT/6RoHWAyknQV0S6ZI5RE6Jt8CZIOOHTuGgR9Fq5FkCf19QM3wx5rZKHEtsRZQt5qkhgUAR6cGaUehOD4AAAAASUVORK5CYII=");
vm.prank(address(0x4444));
eth.createEthscription(Ethscriptions.CreateEthscriptionParams({
transactionHash: keccak256("image1"),
contentUriHash: keccak256("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAm0lEQVR42mNgGITgPxTTxvBleTo0swBsOK0s+N8aJkczC1AMR7KAKpb8v72xAY5hFsD4lFoCN+j56ZUoliBbSoklGIZjwxRbQAjT1YK7d+82kGUBeuQii5FrAYYrL81NwCpGFQtoEUT/6RoHWAyknQV0S6ZI5RE6Jt8CZIOOHTuGgR9Fq5FkCf19QM3wx5rZKHEtsRZQt5qkhgUAR6cGaUehOD4AAAAASUVORK5CYII="),
initialOwner: address(0x4444),
content: redPixelPng,
mimetype: "image/png",
esip6: false,
protocolParams: Ethscriptions.ProtocolParams("", "", "")
}));
// Test case 5: CSS content (should use viewer)
vm.prank(address(0x5555));
eth.createEthscription(Ethscriptions.CreateEthscriptionParams({
transactionHash: keccak256("css1"),
contentUriHash: keccak256("data:text/css,body { background: #000; color: #0f0; font-family: 'Courier New'; }"),
initialOwner: address(0x5555),
content: bytes("body { background: #000; color: #0f0; font-family: 'Courier New'; }"),
mimetype: "text/css",
esip6: false,
protocolParams: Ethscriptions.ProtocolParams("", "", "")
}));
// Output all token URIs
console.log("\n=== TOKEN URI TEST RESULTS ===\n");
console.log("Test 1 - Plain Text (text/plain):");
console.log("Should use HTML viewer with content displayed");
string memory uri1 = eth.tokenURI(11);
console.log(uri1);
console.log("");
console.log("Test 2 - JSON (application/json):");
console.log("Should use HTML viewer with pretty-printed JSON");
string memory uri2 = eth.tokenURI(12);
console.log(uri2);
console.log("");
console.log("Test 3 - HTML (text/html):");
console.log("Should pass through HTML directly in animation_url");
string memory uri3 = eth.tokenURI(13);
console.log(uri3);
console.log("");
console.log("Test 4 - Image (image/png):");
console.log("Should use image field (not animation_url)");
string memory uri4 = eth.tokenURI(14);
console.log(uri4);
console.log("");
console.log("Test 5 - CSS (text/css):");
console.log("Should use HTML viewer");
string memory uri5 = eth.tokenURI(15);
console.log(uri5);
console.log("");
console.log("=== PASTE ANY OF THE ABOVE data: URIs INTO YOUR BROWSER ===");
}
}