Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 37490x 21266x 21266x 21266x 21266x 21266x 21266x 21266x 21266x 21266x 21266x 21266x 37490x 1x 1x 37490x 16224x 16224x 16224x 16224x 16224x 16224x 16224x 16224x 16224x 16224x 16224x 16222x 16222x 16224x 16224x 37490x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 2x 2x 2x 2x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 2016x 2016x 2016x 2016x 1x 1x 2016x 2016x 2016x 2016x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x | import assert from "assert"; import { hashMessage, namehash, isValidName, solidityPacked, solidityPackedKeccak256, solidityPackedSha256, isError } from "../index.js"; import { loadTests } from "./utils.js" import type { TestCaseNamehash, TestCaseSolidityHash } from "./types.js"; import { dnsEncode } from "../index.js"; describe("Tests Namehash", function() { const tests = loadTests<TestCaseNamehash>("namehash"); for (const test of tests) { if (!test.error) { it(`hashes ENS name: ${ JSON.stringify(test.name) }`, function() { const actual = namehash(test.ensName); assert.equal(actual, test.namehash, "namehash"); // The empty string is not a valid ENS name if (test.ensName) { assert.ok(isValidName(test.ensName), "isValidName"); } }); } } for (const test of tests) { if (test.error) { it(`correctly fails to hash ENS name: ${ test.error } ${ JSON.stringify(test.name) }`, function() { assert.throws(function() { const actual = namehash(test.ensName); console.log("Failed to throw", actual); }, (error) => { return (isError(error, "INVALID_ARGUMENT") && error.argument === "name" && error.value === test.ensName); }) // The empty string is not a valid ENS name if (test.ensName) { assert.ok(!isValidName(test.ensName), "!isValidName"); } }); } } }); /* describe("Tests Bad ENS Names", function() { const badTests: Array<{ ensName: any, prefix: string }> = [ { ensName: ".", prefix: "missing component" }, { ensName:"..", prefix: "missing component" }, { ensName:"ricmoo..eth", prefix: "missing component" }, { ensName:"ricmoo...eth", prefix: "missing component" }, { ensName:".foo", prefix: "missing component" }, { ensName:"foo.", prefix: "missing component" }, { ensName: 1234, prefix: "not a string" }, { ensName: true, prefix: "not a string" }, ]; // The empty string is not a valid name, but has a valid namehash // (the zero hash) as it is the base case for recursion it("empty ENS name", function() { assert.ok(!isValidName(""), "!isValidName"); }); for (const { ensName, prefix } of badTests) { it(`fails on bad ENS name: ${ JSON.stringify(ensName) }`, function() { assert.ok(!isValidName(ensName), "!isValidName"); assert.throws(() => { const result = namehash(ensName); console.log(result); }, (error) => { const errorPrefix = `invalid ENS name; ${ prefix }`; return (error.code === "INVALID_ARGUMENT" && error.argument === "name" && error.value === ensName && error.message.substring(0, errorPrefix.length) === errorPrefix); }); }); } }); describe("Tests DNS Encoding", function() { const tests: Array<{ ensName: string, dnsEncoded: string}> = [ { ensName: "", dnsEncoded: "0x00" }, { ensName: "ricmoo.eth", dnsEncoded: "0x067269636d6f6f0365746800" }, ]; for (const { ensName, dnsEncoded } of tests) { it(`computes the DNS Encoding: ${ JSON.stringify(ensName) }`, function() { assert.equal(dnsEncode(ensName), dnsEncoded, "dnsEncoded"); }); } }); describe("Tests DNS Names", function() { const badTests: Array<{ ensName: any, prefix: string}> = [ { ensName: ".", prefix: "invalid DNS name; missing component" }, { ensName: "foo..bar", prefix: "invalid DNS name; missing component" }, { ensName: ".foo", prefix: "invalid DNS name; missing component" }, { ensName: "foo.", prefix: "invalid DNS name; missing component" }, { ensName: 1234, prefix: "invalid DNS name; not a string" }, { ensName: true, prefix: "invalid DNS name; not a string" }, ]; for (const { ensName, prefix } of badTests) { it(`fails on bad DNS name: ${ JSON.stringify(ensName) }`, function() { assert.throws(() => { const result = dnsEncode(ensName); console.log(result); }, (error) => { return (error.code === "INVALID_ARGUMENT" && error.argument === "name" && error.value === ensName && error.message.substring(0, prefix.length) === prefix); }); }); } { const ensName = "foobar012345678901234567890123456789012345678901234567890123456789"; const prefix = "too long"; it(`fails on bad DNS name: ${ JSON.stringify(ensName) }`, function() { assert.throws(() => { const result = dnsEncode(ensName); console.log(result); }, (error) => { return (error.code === "INVALID_ARGUMENT" && error.argument === "value" && error.value === ensName && error.message.substring(0, prefix.length) === prefix); }); }); } }); */ interface TestCaseDnsEncode { name: string; length?: number; result?: string; error?: string; } describe("Test dnsEncode", function() { const tests: Array<TestCaseDnsEncode> = [ { name: "ricmoo.com", result: "0x067269636d6f6f03636f6d00" }, { name: "ricmoo.com", length: 5, error: "exceeds 5 bytes" }, { name: "a-very-long-label-without-a-length-override-foo-12345678901234567890", error: "exceeds 63 bytes" }, { name: "a-very-long-label-with-a-length-override-to-255-foo-12345678901234567890", length: 255, result: "0x48612d766572792d6c6f6e672d6c6162656c2d776974682d612d6c656e6774682d6f766572726964652d746f2d3235352d666f6f2d313233343536373839303132333435363738393000" }, ]; for (const test of tests) { it(`tests dnsEncode: ${ test.name }`, function() { if (test.error) { assert.throws(() => { let result; if (test.length != null) { result = dnsEncode(test.name, test.length); } else { result = dnsEncode(test.name); } console.log("result", result); }, (error) => { return (isError(error, "INVALID_ARGUMENT") && error.argument === "name" && error.value === test.name && error.message.indexOf(test.error || "") >= 0); }); } else { if (test.length != null) { assert.equal(dnsEncode(test.name, test.length), test.result, "dnsEncode(name, length)"); } else { assert.equal(dnsEncode(test.name), test.result, "dnsEncode(name)"); } } }); } }); describe("Test EIP-191 Personal Message Hash", function() { const tests = [ { test: "hello-world", message: "Hello World", hash: "0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2" }, { test: "binary-message", message: new Uint8Array([ 0x42, 0x43 ]), hash: "0x0d3abc18ec299cf9b42ba439ac6f7e3e6ec9f5c048943704e30fc2d9c7981438" }, { test: "hex-looking-string", message: "0x4243", hash: "0x6d91b221f765224b256762dcba32d62209cf78e9bebb0a1b758ca26c76db3af4" } ]; for (const test of tests) { it(`tests hashMessage: ${ test.test }`, function() { assert.equal(hashMessage(test.message), test.hash); }); } }) describe("Test Solidity Hash functions", function() { const tests = loadTests<TestCaseSolidityHash>("solidity-hashes"); for (const test of tests) { it(`computes the solidity keccak256: ${ test.name }`, function() { assert.equal(solidityPackedKeccak256(test.types, test.values), test.keccak256); }); } for (const test of tests) { it(`computes the solidity sha256: ${ test.name }`, function() { assert.equal(solidityPackedSha256(test.types, test.values), test.sha256); }); } const badTypes = [ { types: [ "uint5" ], values: [ 1 ] }, { types: [ "bytes0" ], values: [ "0x" ] }, { types: [ "blorb" ], values: [ false ] }, ]; for (const { types, values } of badTypes) { it("correctly fails on invalid type", function() { assert.throws(function() { const result = solidityPacked(types, values); console.log(result); }, function (error) { return (isError(error, "INVALID_ARGUMENT") && error.argument === "type"); }); }); } }); |