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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 27x 27x 27x 27x 27x 162x 152x 152x 152x 162x 107x 107x 107x 111x 111x 111x 111x 111x 111x 111x 105x 111x 6x 6x 6x 6x 6x 6x 105x 105x 105x 105x 107x 107x 27x 27x 9x 1x 1x 1x 18x 6x 6x 6x 1x 1x 1x 18x 12x 12x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 18x 6x 6x 6x 6x 6x 1x 1x 1x 18x 6x 6x 6x 1x 1x 1x 109x 109x 109x 109x 16x 16x 16x 93x 109x 1203x 1203x 4x 4x 4x 16x 16x 1203x 1030x 1030x 1203x 92x 1x 29x 29x 29x 822x 822x 822x 822x 822x 29x 29x 29x 29x 29x 29x 29x 1x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 1x 16x 16x 16x 16x 18x 18x 48x 48x 18x 18x 18x 18x 18x 16x 16x 16x 16x 16x 16x 10x 16x 6x 6x 16x 16x 16x 16x 1x 1x 1x 16x 16x 13x 13x 13x 13x 1x 1x 1x 16x 16x 16x 1x 1x 1x 1x 1x 16x 20x 16x 1x 1x 1x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 2x 2x 16x 16x 16x 16x 16x 16x 1x 1x 1x 16x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 64x 64x 64x 24x 24x 24x 24x 24x 24x 24x 4x 1x | import assert from "assert"; import { checkProvider, getProvider, setupProviders, providerNames } from "./create-provider.js"; import { retryIt } from "./utils.js"; import { JsonRpcProvider, Network } from "../index.js"; import type { Provider } from "../index.js"; import { networkFeatureAtBlock, networkNames, testAddress, testBlock, testReceipt, testTransaction } from "./blockchain-data.js"; import type { TestBlockchainNetwork } from "./blockchain-data.js"; setupProviders(); function forEach<T extends { test: string }>(prefix: string, tests: Record<TestBlockchainNetwork, Array<T>>, func: (providerName: string, test: T) => (null | ((p: Provider) => Promise<void>))): void { for (const networkName of networkNames) { const networkTests: Array<T> = tests[networkName]; if (networkTests == null) { continue; } for (const test of networkTests) { for (const providerName of providerNames) { if (!checkProvider(providerName, networkName)) { continue; } // Let the testcase skip this by returning null const testFunc = func(providerName, test); if (testFunc == null) { continue; } // Prepare the testcase retryIt(`${ prefix }: ${ providerName }:${ networkName }.${ test.test }`, async function() { // Create a provider const provider = getProvider(providerName, networkName); try { assert.ok(provider != null, "missing provider"); await testFunc(provider); } catch (error) { // Shutdown socket-based provider, otherwise its socket will prevent // this process from exiting if ((<any>provider).destroy) { (<any>provider).destroy(); } throw error; } // Shutdown socket-based provider, otherwise its socket will prevent // this process from exiting if ((<any>provider).destroy) { (<any>provider).destroy(); } }); } } } } describe("Test Provider Address operations", function() { forEach("test getBalance(address)", testAddress, (providerName, test) => { if (test.balance == null) { return null; } return async (provider) => { assert.equal(await provider.getBalance(test.address), test.balance); }; }); forEach("test getCode(address)", testAddress, (providerName, test) => { if (test.code == null) { return null; } return async (provider) => { assert.equal(await provider.getCode(test.address), test.code); }; }); /* forEach("test lookupAddress(address)", testAddress, (provider, test) => { if (test.name == null) { return null; } return async () => { assert.equal(await provider.lookupAddress(test.address), test.name); }; }); forEach("test resolveName(name)", testAddress, (provider, test) => { if (test.name == null) { return null; } return async () => { assert.equal(await provider.lookupAddress(<string>(test.name)), test.address); }; }); */ forEach("test getStorage(address)", testAddress, (providerName, test) => { if (test.storage == null) { return null; } return async (provider) => { for (const key in test.storage) { assert.equal(await provider.getStorage(test.address, key), test.storage[key]); } }; }); forEach("test getTransactionCount(address)", testAddress, (providerName, test) => { if (test.balance == null) { return null; } return async (provider) => { assert.equal(await provider.getTransactionCount(test.address), test.nonce); }; }); }); function assertObj(prefix: string, actual: any, expected: any): void { assert.ok(actual != null, `${ prefix } is null`); if (typeof(expected) !== "object") { assert.equal(actual, expected, prefix); return; } for (const key in expected) { if (expected[key] === undefined) { continue; } if (Array.isArray(expected[key])) { assert.ok(Array.isArray(actual[key]), `Array.isArray(${ prefix }.${ key })`); assert.equal(actual[key].length, expected[key].length, `${ prefix }.${ key }.length`); for (let i = 0; i < expected[key].length; i++) { assertObj(`${ prefix }[${ i }]`, actual[key][i], expected[key][i]); } } else { assert.equal(actual[key], expected[key], `${ prefix }.${ key }`); } } } function assertBlock(actual: any, expected: any): void { // Check transactions for (let i = 0; i < expected.transactions.length; i++) { const expectedTx = expected.transactions[i]; if (typeof(expectedTx) === "string") { assert.equal(actual.transactions[i], expectedTx, `block.transactions[${ i }]`); } else { throw new Error("@TODO"); } } // Remove the transactions and test keys expected = Object.assign({ }, expected, { transactions: undefined, test: undefined }); // Check remaining keys assertObj("block", actual, expected); } function assertTransaction(actual: any, expected: any): void { // @TODO: Accesslist // Check signature assertObj("tx.signature", actual.signature, expected.signature); // Remove the transactions and test keys expected = Object.assign({ }, expected, { accessList: undefined, signature: undefined, test: undefined }); // Check remaining keys assertObj("tx", actual, expected); } function assertReceipt(actual: any, expected: any): void { // Check logs for (let i = 0; i < expected.logs.length; i++) { let expectedLog = expected.logs[i]; for (let j = 0; j < expectedLog.topics.length; j++) { assert.equal(actual.logs[i].topics[j], expectedLog.topics[j], `receipt.logs[${ i }].topics[${ j }]`); } expectedLog = Object.assign({ }, expectedLog, { topics: undefined }); assertObj(`receipt.log[${ i }]`, actual.logs[i], expectedLog); } // Remove the transactions and test keys expected = Object.assign({ }, expected, { logs: undefined, test: undefined }); // In Byzantium, the root was dropped and the status was added if (networkFeatureAtBlock("byzantium", expected.blockNumber)) { expected = Object.assign({ }, expected, { root: undefined }); } else { expected = Object.assign({ }, expected, { status: undefined }); } // Check remaining keys assertObj("receipt", actual, expected); } describe("Test Provider Block operations", function() { forEach("test getBlock(blockHash)", testBlock, (providerName, test) => { // Etherscan does not support getting a block by blockhash if (providerName === "EtherscanProvider") { return null; } return async (provider) => { assertBlock(await provider.getBlock(test.hash), test); }; }); forEach("test getBlock(blockNumber)", testBlock, (providerName, test) => { return async (provider) => { assertBlock(await provider.getBlock(test.number), test); }; }); }); describe("Test Provider Transaction operations", function() { forEach("test getTransaction(hash)", testTransaction, (providerName, test) => { return async (provider) => { assertTransaction(await provider.getTransaction(test.hash), test); }; }); forEach("test getTransactionReceipt(hash)", testReceipt, (providerName, test) => { return async (provider) => { const receipt = await provider.getTransactionReceipt(test.hash) assert.ok(receipt != null, "receipt != null"); // Cloudflare doesn't return the root in legacy receipts; but it isn't // *actually* that important, so we'll give it a pass... if (providerName === "CloudflareProvider" || providerName === "AnkrProvider" || providerName === "PocketProvider" || providerName === "BlockscoutProvider") { test = Object.assign({ } , test, { root: undefined }); } //if (providerName === "PocketProvider") { //} assertReceipt(receipt, test); }; }); forEach("test lookupAddress(addr) == null", testReceipt, (providerName, test) => { return async (provider) => { const name = await provider.lookupAddress("0x0123456789012345678901234567890123456789") assert.ok(name == null, "name == null"); }; }); }); describe("Test Networks", function() { const networks = [ "mainnet", "sepolia", "holesky", "arbitrum", "arbitrum-sepolia", "base", "base-sepolia", "bnb", "bnbt", "linea", "linea-sepolia", "matic", "matic-amoy", "optimism", "optimism-sepolia", "xdai", ]; const providerNames = [ "AlchemyProvider", "InfuraProvider", "AnkrProvider", "QuickNodeProvider", ]; for (const providerName of providerNames) { for (const networkName of networks) { const network = Network.from(networkName); const provider = getProvider(providerName, networkName); if (provider == null || !(provider instanceof JsonRpcProvider)) { continue; } it(`checks network chainId: ${ providerName }/${ networkName }`, async function() { this.timeout(10000); const chainId = await provider.send("eth_chainId", [ ]); assert.equal(parseInt(chainId), network.chainId, "chainId"); }); } } }); |