ethers.js/packages/tests/lib.esm/test-providers.js

488 lines
26 KiB
JavaScript
Raw Normal View History

2019-08-21 08:52:13 +03:00
"use strict";
import assert from "assert";
const Web3HttpProvider = require("web3-providers-http");
import { ethers } from "ethers";
const bnify = ethers.BigNumber.from;
const blockchainData = {
2019-05-15 01:48:48 +03:00
homestead: {
balance: {
2019-08-21 08:52:13 +03:00
address: "0xAC1639CF97a3A46D431e6d1216f576622894cBB5",
balance: bnify("4918774100000000")
2019-05-15 01:48:48 +03:00
},
block3: {
2019-08-21 08:52:13 +03:00
hash: "0x3d6122660cc824376f11ee842f83addc3525e2dd6756b9bcf0affa6aa88cf741",
parentHash: "0xb495a1d7e6663152ae92708da4843337b958146015a2802f4193a410044698c9",
2019-05-15 01:48:48 +03:00
number: 3,
timestamp: 1438270048,
2019-08-21 08:52:13 +03:00
nonce: "0x2e9344e0cbde83ce",
2019-05-15 01:48:48 +03:00
difficulty: 17154715646,
2019-08-21 08:52:13 +03:00
gasLimit: bnify("0x1388"),
gasUsed: bnify("0"),
miner: "0x5088D623ba0fcf0131E0897a91734A4D83596AA0",
extraData: "0x476574682f76312e302e302d66633739643332642f6c696e75782f676f312e34",
2019-05-15 01:48:48 +03:00
transactions: []
},
transaction: {
2019-08-21 08:52:13 +03:00
hash: "0xccc90ab97a74c952fb3376c4a3efb566a58a10df62eb4d44a61e106fcf10ec61",
blockHash: "0x9653f180a5720f3634816eb945a6d722adee52cc47526f6357ac10adaf368135",
2019-05-15 01:48:48 +03:00
blockNumber: 4097745,
transactionIndex: 18,
2019-08-21 08:52:13 +03:00
from: "0x32DEF047DeFd076DB21A2D759aff2A591c972248",
gasPrice: bnify("0x4a817c800"),
gasLimit: bnify("0x3d090"),
to: "0x6fC21092DA55B392b045eD78F4732bff3C580e2c",
value: bnify("0x186cc6acd4b0000"),
2019-05-15 01:48:48 +03:00
nonce: 0,
2019-08-21 08:52:13 +03:00
data: "0xf2c298be000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067269636d6f6f0000000000000000000000000000000000000000000000000000",
r: "0x1e5605197a03e3f0a168f14749168dfeefc44c9228312dacbffdcbbb13263265",
s: "0x269c3e5b3558267ad91b0a887d51f9f10098771c67b82ea6cb74f29638754f54",
2019-05-15 01:48:48 +03:00
v: 38,
creates: null,
2019-08-21 08:52:13 +03:00
raw: "0xf8d2808504a817c8008303d090946fc21092da55b392b045ed78f4732bff3c580e2c880186cc6acd4b0000b864f2c298be000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067269636d6f6f000000000000000000000000000000000000000000000000000026a01e5605197a03e3f0a168f14749168dfeefc44c9228312dacbffdcbbb13263265a0269c3e5b3558267ad91b0a887d51f9f10098771c67b82ea6cb74f29638754f54",
2019-05-15 01:48:48 +03:00
networkId: 1
},
transactionReceipt: {
blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566",
blockNumber: 0x3c92b5,
contractAddress: null,
cumulativeGasUsed: 0x1cca2e,
from: "0x18C6045651826824FEBBD39d8560584078d1b247",
gasUsed: 0x14bb7,
logs: [
{
address: "0x314159265dD8dbb310642f98f50C066173C1259b",
blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566",
blockNumber: 0x3c92b5,
data: "0x00000000000000000000000018c6045651826824febbd39d8560584078d1b247",
logIndex: 0x1a,
topics: ["0xce0457fe73731f824cc272376169235128c118b49d344817417c6d108d155e82", "0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae", "0xf0106919d12469348e14ad6a051d0656227e1aba2fefed41737fdf78421b20e1"],
transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616",
transactionIndex: 0x39,
transactionLogIndex: 0x0
},
{
address: "0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef",
blockHash: "0x36b4af7f0538559e581c8588f16477df0f676439ea67fe8d7a2ae4abb20e2566",
blockNumber: 0x3c92b5,
data: "0x000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000595a32ce",
logIndex: 0x1b,
topics: ["0x0f0c27adfd84b60b6f456b0e87cdccb1e5fb9603991588d87fa99f5b6b61e670", "0xf0106919d12469348e14ad6a051d0656227e1aba2fefed41737fdf78421b20e1", "0x00000000000000000000000018c6045651826824febbd39d8560584078d1b247"],
transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616",
transactionIndex: 0x39,
transactionLogIndex: 0x1
}
],
logsBloom: "0x00000000000000040000000000100000010000000000000040000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000200000010000000004000000000000000000000000000000000002000000000000000000000000400000000020000000000000000000000000000000000000004000000000000000000000000000000000000000000000000801000000000000000000000020000000000040000000040000000000000000002000000004000000000000000000000000000000000000000000000010000000000000000000000000000000000200000000000000000",
root: "0x9b550a9a640ce50331b64504ef87aaa7e2aaf97344acb6ff111f879b319d2590",
status: null,
to: "0x6090A6e47849629b7245Dfa1Ca21D94cd15878Ef",
transactionHash: "0xc6fcb7d00d536e659a4559d2de29afa9e364094438fef3e72ba80728ce1cb616",
transactionIndex: 0x39
},
transactionReceiptByzantium: {
byzantium: true,
blockHash: "0x34e5a6cfbdbb84f7625df1de69d218ade4da72f4a2558064a156674e72e976c9",
blockNumber: 0x444f76,
contractAddress: null,
cumulativeGasUsed: 0x15bfe7,
from: "0x18C6045651826824FEBBD39d8560584078d1b247",
gasUsed: 0x1b968,
logs: [
{
address: "0xb90E64082D00437e65A76d4c8187596BC213480a",
blockHash: "0x34e5a6cfbdbb84f7625df1de69d218ade4da72f4a2558064a156674e72e976c9",
blockNumber: 0x444f76,
data: "0x",
logIndex: 0x10,
topics: ["0x748d071d1992ee1bfe7a39058114d0a50d5798fe8eb3a9bfb4687f024629a2ce", "0x5574aa58f7191ccab6de6cf75fe2ea0484f010b852fdd8c6b7ae151d6c2f4b83"],
transactionHash: "0x7f1c6a58dc880438236d0b0a4ae166e9e9a038dbea8ec074149bd8b176332cac",
transactionIndex: 0x1e,
transactionLogIndex: 0x0
}
],
logsBloom: "0x00000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000200000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000800000000000000000800000000000000000000000000000000000000",
status: 1,
to: "0xb90E64082D00437e65A76d4c8187596BC213480a",
transactionHash: "0x7f1c6a58dc880438236d0b0a4ae166e9e9a038dbea8ec074149bd8b176332cac",
transactionIndex: 0x1e
}
},
kovan: {
balance: {
2019-08-21 08:52:13 +03:00
address: "0x09c967A0385eE3B3717779738cA0B9D116e0EcE7",
balance: bnify("997787946734641021")
2019-05-15 01:48:48 +03:00
},
block3: {
2019-08-21 08:52:13 +03:00
hash: "0xf0ec9bf41b99a6bd1f6cd29f91302f71a1a82d14634d2e207edea4b7962f3676",
parentHash: "0xf110ecd84454f116e2222378e7bca81ac3e59be0dac96d7ec56d5ef1c3bc1d64",
2019-05-15 01:48:48 +03:00
number: 3,
timestamp: 1488459452,
difficulty: 131072,
2019-08-21 08:52:13 +03:00
gasLimit: bnify("0x5b48ec"),
gasUsed: bnify("0"),
miner: "0x00A0A24b9f0E5EC7Aa4c7389b8302fd0123194dE",
extraData: "0xd5830105048650617269747986312e31352e31826c69",
2019-05-15 01:48:48 +03:00
transactions: []
},
},
rinkeby: {
balance: {
2019-08-21 08:52:13 +03:00
address: "0xd09a624630a656a7dbb122cb05e41c12c7cd8c0e",
balance: bnify("3000000000000000000")
2019-05-15 01:48:48 +03:00
},
block3: {
2019-08-21 08:52:13 +03:00
hash: "0x9eb9db9c3ec72918c7db73ae44e520139e95319c421ed6f9fc11fa8dd0cddc56",
parentHash: "0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9",
2019-05-15 01:48:48 +03:00
number: 3,
timestamp: 1492010489,
2019-08-21 08:52:13 +03:00
nonce: "0x0000000000000000",
2019-05-15 01:48:48 +03:00
difficulty: 2,
2019-08-21 08:52:13 +03:00
gasLimit: bnify("0x47e7c4"),
2019-05-15 01:48:48 +03:00
gasUsed: bnify(0),
2019-08-21 08:52:13 +03:00
miner: "0x0000000000000000000000000000000000000000",
extraData: "0xd783010600846765746887676f312e372e33856c696e757800000000000000004e10f96536e45ceca7e34cc1bdda71db3f3bb029eb69afd28b57eb0202c0ec0859d383a99f63503c4df9ab6c1dc63bf6b9db77be952f47d86d2d7b208e77397301",
2019-05-15 01:48:48 +03:00
transactions: []
},
},
ropsten: {
balance: {
2019-08-21 08:52:13 +03:00
address: "0x03a6F7a5ce5866d9A0CCC1D4C980b8d523f80480",
balance: bnify("15861113897828552666")
2019-05-15 01:48:48 +03:00
},
block3: {
2019-08-21 08:52:13 +03:00
hash: "0xaf2f2d55e6514389bcc388ccaf40c6ebf7b3814a199a214f1203fb674076e6df",
parentHash: "0x88e8bc1dd383672e96d77ee247e7524622ff3b15c337bd33ef602f15ba82d920",
2019-05-15 01:48:48 +03:00
number: 3,
timestamp: 1479642588,
2019-08-21 08:52:13 +03:00
nonce: "0x04668f72247a130c",
2019-05-15 01:48:48 +03:00
difficulty: 996427,
2019-08-21 08:52:13 +03:00
gasLimit: bnify("0xff4033"),
gasUsed: bnify("0"),
miner: "0xD1aEb42885A43b72B518182Ef893125814811048",
extraData: "0xd883010503846765746887676f312e372e318664617277696e",
2019-05-15 01:48:48 +03:00
transactions: []
},
transactionReceipt: {
blockHash: "0xc9235b8253fce455942147aa8b450d23081b867ffbb2a1e4dec934827cd80f8f",
blockNumber: 0x1564d8,
contractAddress: null,
cumulativeGasUsed: bnify("0x80b9"),
from: "0xb346D5019EeafC028CfC01A5f789399C2314ae8D",
gasUsed: bnify("0x80b9"),
logs: [
{
address: "0x6fC21092DA55B392b045eD78F4732bff3C580e2c",
blockHash: "0xc9235b8253fce455942147aa8b450d23081b867ffbb2a1e4dec934827cd80f8f",
blockNumber: 0x1564d8,
data: "0x00000000000000000000000006b5955a67d827cdf91823e3bb8f069e6c89c1d6000000000000000000000000000000000000000000000000016345785d8a0000",
logIndex: 0x0,
topics: ["0xac375770417e1cb46c89436efcf586a74d0298fee9838f66a38d40c65959ffda"],
transactionHash: "0x55c477790b105e69e98afadf0505cbda606414b0187356137132bf24945016ce",
transactionIndex: 0x0,
transactionLogIndex: 0x0
}
],
logsBloom: "0x00000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000010000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
root: "0xf1c3506ab619ac1b5e8f1ca355b16d6b9a1b7436b2960b0e9ec9a91f4238b5cc",
to: "0x6fC21092DA55B392b045eD78F4732bff3C580e2c",
transactionHash: "0x55c477790b105e69e98afadf0505cbda606414b0187356137132bf24945016ce",
transactionIndex: 0x0
},
transactionReceiptByzantium: {
byzantium: true,
blockHash: "0x61d343e0e081b60ac53bab381e07bdd5d0815b204091a576fd05106b814e7e1e",
blockNumber: 0x1e1e3b,
contractAddress: null,
cumulativeGasUsed: bnify("0x4142f"),
from: "0xdc8F20170C0946ACCF9627b3EB1513CFD1c0499f",
gasUsed: bnify("0x1eb6d"),
logs: [
{
address: "0xCBf1735Aad8C4B337903cD44b419eFE6538aaB40",
blockHash: "0x61d343e0e081b60ac53bab381e07bdd5d0815b204091a576fd05106b814e7e1e",
blockNumber: 0x1e1e3b,
data: "0x000000000000000000000000b70560a43a9abf6ea2016f40a3e84b8821e134c5f6c95607c490f4f379c0160ef5c8898770f8a52959abf0e9de914647b377fa290000000000000000000000000000000000000000000000000000000000001c20000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000355524c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004c6a736f6e2868747470733a2f2f6170692e6b72616b656e2e636f6d2f302f7075626c69632f5469636b65723f706169723d455448555344292e726573756c742e584554485a5553442e632e300000000000000000000000000000000000000000",
logIndex: 0x1,
topics: ["0xb76d0edd90c6a07aa3ff7a222d7f5933e29c6acc660c059c97837f05c4ca1a84"],
transactionHash: "0xf724f1d6813f13fb523c5f6af6261d06d41138dd094fff723e09fb0f893f03e6",
transactionIndex: 0x2,
transactionLogIndex: 0x0
}
],
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000080000000202000000",
status: 1,
to: "0xB70560a43A9aBf6ea2016F40a3e84B8821E134c5",
transactionHash: "0xf724f1d6813f13fb523c5f6af6261d06d41138dd094fff723e09fb0f893f03e6",
transactionIndex: 0x2
},
},
goerli: {
balance: {
address: "0x06B5955A67D827CDF91823E3bB8F069e6c89c1D6",
balance: bnify("314159000000000000")
},
block3: {
2019-08-21 08:52:13 +03:00
hash: "0xd5daa825732729bb0d2fd187a1b888e6bfc890f1fc5333984740d9052afb2920",
parentHash: "0xe675f1362d82cdd1ec260b16fb046c17f61d8a84808150f5d715ccce775f575e",
2019-05-15 01:48:48 +03:00
number: 3,
timestamp: 1548947483,
difficulty: 2,
2019-08-21 08:52:13 +03:00
gasLimit: bnify("10455073"),
gasUsed: bnify("0"),
miner: "0x0000000000000000000000000000000000000000",
extraData: "0x506172697479205465636820417574686f7269747900000000000000000000002822e1b202411c38084d96c84302b8361ec4840a51cd2fad9cb4bd9921cad7e64bc2e5dc7b41f3f75b33358be3aec718cf4d4317ace940e01b3581a95c9259ac01",
2019-05-15 01:48:48 +03:00
transactions: []
},
transactionReceipt: {
2019-08-21 08:52:13 +03:00
blockHash: "0x2384e8e8bdcf6eb87ec7c138fa503ac34adb32cac817e4b35f14d4339eaa1993",
2019-05-15 01:48:48 +03:00
blockNumber: 47464,
byzantium: true,
contractAddress: null,
cumulativeGasUsed: bnify(21000),
2019-08-21 08:52:13 +03:00
from: "0x8c1e1e5b47980D214965f3bd8ea34C413E120ae4",
2019-05-15 01:48:48 +03:00
gasUsed: bnify(21000),
2019-08-21 08:52:13 +03:00
logsBloom: "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
to: "0x58Bb4221245461E1d4cf886f18a01E3Df40Bd359",
transactionHash: "0xec8b1ac5d787f36c738cc7793fec606283b41f1efa69df4ae6b2a014dcd12797",
2019-05-15 01:48:48 +03:00
transactionIndex: 0,
logs: [],
status: 1
}
}
};
2019-08-21 08:52:13 +03:00
blockchainData["default"] = blockchainData.homestead;
2019-05-15 01:48:48 +03:00
function equals(name, actual, expected) {
if (expected && expected.eq) {
if (actual == null) {
assert.ok(false, name + " - actual big number null");
2019-05-15 01:48:48 +03:00
}
assert.ok(expected.eq(actual), name + " matches");
2019-05-15 01:48:48 +03:00
}
else if (Array.isArray(expected)) {
if (actual == null) {
assert.ok(false, name + " - actual array null");
2019-05-15 01:48:48 +03:00
}
assert.equal(actual.length, expected.length, name + " array lengths match");
for (let i = 0; i < expected.length; i++) {
2019-08-21 08:52:13 +03:00
equals("(" + name + " - item " + i + ")", actual[i], expected[i]);
2019-05-15 01:48:48 +03:00
}
}
2019-08-21 08:52:13 +03:00
else if (typeof (expected) === "object") {
2019-05-15 01:48:48 +03:00
if (actual == null) {
if (expected === actual) {
return;
}
assert.ok(false, name + " - actual object null");
2019-05-15 01:48:48 +03:00
}
let keys = {};
Object.keys(expected).forEach((key) => { keys[key] = true; });
Object.keys(actual).forEach((key) => { keys[key] = true; });
Object.keys(keys).forEach((key) => {
2019-08-21 08:52:13 +03:00
equals("(" + name + " - key + " + key + ")", actual[key], expected[key]);
2019-05-15 01:48:48 +03:00
});
}
else {
if (actual == null) {
assert.ok(false, name + " - actual null");
2019-05-15 01:48:48 +03:00
}
assert.equal(actual, expected, name + " matches");
2019-05-15 01:48:48 +03:00
}
}
function testProvider(providerName, networkName) {
2019-08-21 08:52:13 +03:00
describe(("Read-Only " + providerName + " (" + networkName + ")"), function () {
let provider = null;
2019-08-21 08:52:13 +03:00
if (networkName === "default") {
if (providerName === "getDefaultProvider") {
provider = ethers.getDefaultProvider();
2019-05-15 01:48:48 +03:00
}
2019-08-21 08:52:13 +03:00
else if (providerName === "Web3Provider") {
let infuraUrl = (new ethers.providers.InfuraProvider()).connection.url;
provider = new ethers.providers.Web3Provider(new Web3HttpProvider(infuraUrl));
2019-05-15 01:48:48 +03:00
}
else {
provider = new (ethers.providers)[providerName]();
2019-05-15 01:48:48 +03:00
}
}
else {
2019-08-21 08:52:13 +03:00
if (providerName === "getDefaultProvider") {
provider = ethers.getDefaultProvider(networkName);
2019-05-15 01:48:48 +03:00
}
2019-08-21 08:52:13 +03:00
else if (providerName === "Web3Provider") {
let infuraUrl = (new ethers.providers.InfuraProvider(networkName)).connection.url;
provider = new ethers.providers.Web3Provider(new Web3HttpProvider(infuraUrl), networkName);
2019-05-15 01:48:48 +03:00
}
else {
provider = new (ethers.providers)[providerName](networkName);
2019-05-15 01:48:48 +03:00
}
}
2019-08-21 08:52:13 +03:00
it("fetches block #3", function () {
2019-05-15 01:48:48 +03:00
this.timeout(20000);
let test = blockchainData[networkName].block3;
return provider.getBlock(3).then((block) => {
for (let key in test) {
2019-08-21 08:52:13 +03:00
equals("Block " + key, block[key], test[key]);
2019-05-15 01:48:48 +03:00
}
}, (error) => {
2019-08-21 08:52:13 +03:00
console.log("Error", error);
assert.ok(false);
2019-05-15 01:48:48 +03:00
});
});
2019-08-21 08:52:13 +03:00
it("fetches address balance", function () {
2019-05-15 01:48:48 +03:00
// @TODO: These tests could be fiddled with if someone sends ether to our address
// We should set up a contract on each network like:
//
// contract TestBalance {
// function resetBalance() {
// assert(_owner.send(this.balance - 0.0000314159 ether));
// }
// }
this.timeout(100000);
let test = blockchainData[networkName].balance;
2019-05-15 01:48:48 +03:00
return provider.getBalance(test.address).then(function (balance) {
2019-08-21 08:52:13 +03:00
equals("Balance", test.balance, balance);
2019-05-15 01:48:48 +03:00
});
});
function testTransactionReceipt(expected) {
let title = ("Receipt " + expected.transactionHash.substring(0, 10) + " - ");
2019-05-15 01:48:48 +03:00
return provider.getTransactionReceipt(expected.transactionHash).then(function (receipt) {
// This changes with every block
assert.equal(typeof (receipt.confirmations), "number", "confirmations is a number");
2019-05-15 01:48:48 +03:00
delete receipt.confirmations;
for (let key in receipt) {
2019-05-15 01:48:48 +03:00
equals((title + key), receipt[key], expected[key]);
}
2019-08-21 08:52:13 +03:00
//equals(("Receipt " + expected.transactionHash.substring(0, 10)), receipt, expected);
2019-05-15 01:48:48 +03:00
});
}
if (blockchainData[networkName].transactionReceipt) {
2019-08-21 08:52:13 +03:00
it("fetches pre-Byzantium transaction receipt", function () {
2019-05-15 01:48:48 +03:00
this.timeout(100000);
return testTransactionReceipt(blockchainData[networkName].transactionReceipt);
});
}
if (blockchainData[networkName].transactionReceiptByzantium) {
2019-08-21 08:52:13 +03:00
it("fetches Byzantium transaction receipt", function () {
2019-05-15 01:48:48 +03:00
this.timeout(20000);
return testTransactionReceipt(blockchainData[networkName].transactionReceiptByzantium);
});
}
function testTransaction(expected) {
let title = ("Transaction " + expected.hash.substring(0, 10) + " - ");
return provider.getTransaction(expected.hash).then((tx) => {
2019-05-15 01:48:48 +03:00
// This changes with every block
assert.equal(typeof (tx.confirmations), "number", "confirmations is a number");
2019-05-15 01:48:48 +03:00
delete tx.confirmations;
assert.equal(typeof (tx.wait), "function", "wait is a function");
2019-05-15 01:48:48 +03:00
delete tx.wait;
for (let key in tx) {
2019-05-15 01:48:48 +03:00
equals((title + key), tx[key], expected[key]);
}
});
}
if (blockchainData[networkName].transaction) {
2019-08-21 08:52:13 +03:00
it("fetches transaction", function () {
2019-05-15 01:48:48 +03:00
this.timeout(20000);
return testTransaction(blockchainData[networkName].transaction);
});
}
// Obviously many more cases to add here
// - getTransactionCount
// - getCode
// - getStorageAt
// - getBlockNumber
// - getGasPrice
// - estimateGas
// - sendTransaction
// - getTransaction (for other chains)
// - call
// - getLogs
//
// Many of these are tLegacyParametersested in run-providers, which uses nodeunit, but
// also creates a local private key which must then be funded to
// execute the tests. I am working on a better test contract to deploy
// to all the networks to help test these.
});
}
2019-08-21 08:52:13 +03:00
["default", "homestead", "ropsten", "rinkeby", "kovan", "goerli"].forEach(function (networkName) {
["getDefaultProvider", "AlchemyProvider", "CloudflareProvider", "InfuraProvider", "EtherscanProvider", "NodesmithProvider", "Web3Provider"].forEach(function (providerName) {
2019-05-15 01:48:48 +03:00
if (networkName === "goerli" && providerName === "AlchemyProvider") {
return;
}
2019-08-21 08:52:13 +03:00
if ((networkName !== "homestead" && networkName !== "default") && providerName === "CloudflareProvider") {
return;
}
2019-05-15 01:48:48 +03:00
testProvider(providerName, networkName);
});
});
/*
function getDefaults(network, extra) {
let network = ethers.utils.getNetwork(network);
let result = {
chainId: network.chainId,
ensAddress: (network.ensAddress ? getAddress(network.ensAddress): null),
name: network.name,
2019-08-21 08:52:13 +03:00
testnet: (network.name !== "homestead"),
2019-05-15 01:48:48 +03:00
};
for (let key in extra) {
result[key] = extra[key];
}
return result;
}
*/
/*
2019-08-21 08:52:13 +03:00
describe("Test extra Etherscan operations", function() {
2019-05-15 01:48:48 +03:00
let provider = new providers.EtherscanProvider();
2019-08-21 08:52:13 +03:00
it("fethces the current price of ether", function() {
2019-05-15 01:48:48 +03:00
this.timeout(20000);
return provider.getEtherPrice().then(function(price) {
2019-08-21 08:52:13 +03:00
assert.ok(typeof(price) === "number", "Etherscan price returns a number");
assert.ok(price > 0.0, "Etherscan price returns non-zero");
2019-05-15 01:48:48 +03:00
});
});
2019-08-21 08:52:13 +03:00
it("fetches the history", function() {
2019-05-15 01:48:48 +03:00
this.timeout(100000);
2019-08-21 08:52:13 +03:00
return provider.getHistory("ricmoo.firefly.eth").then(function(history) {
assert.ok(history.length > 40, "Etherscan history returns results");
assert.equal(history[0].hash, "0xd25f550cfdff90c086a6496a84dbb2c4577df15b1416e5b3319a3e4ebb5b25d8", "Etherscan history returns correct transaction");
2019-05-15 01:48:48 +03:00
});
});
});
*/
2019-08-21 08:52:13 +03:00
describe("Test Basic Authentication", function () {
2019-05-15 01:48:48 +03:00
// https://stackoverflow.com/questions/6509278/authentication-test-servers#16756383
function test(name, url) {
2019-08-21 08:52:13 +03:00
it("tests " + name, function () {
2019-05-15 01:48:48 +03:00
this.timeout(20000);
return ethers.utils.fetchJson(url).then((data) => {
assert.equal(data.authenticated, true, "authenticates user");
2019-05-15 01:48:48 +03:00
});
});
}
let secure = {
2019-08-21 08:52:13 +03:00
url: "https://httpbin.org/basic-auth/user/passwd",
user: "user",
password: "passwd"
2019-05-15 01:48:48 +03:00
};
let insecure = {
2019-08-21 08:52:13 +03:00
url: "http://httpbin.org/basic-auth/user/passwd",
user: "user",
password: "passwd"
2019-05-15 01:48:48 +03:00
};
let insecureForced = {
2019-08-21 08:52:13 +03:00
url: "http://httpbin.org/basic-auth/user/passwd",
user: "user",
password: "passwd",
2019-06-12 08:01:04 +03:00
allowInsecureAuthentication: true
2019-05-15 01:48:48 +03:00
};
2019-08-21 08:52:13 +03:00
test("secure url", secure);
test("insecure url", insecureForced);
it("tests insecure connections fail", function () {
2019-05-15 01:48:48 +03:00
this.timeout(20000);
assert.throws(() => {
return ethers.utils.fetchJson(insecure);
}, (error) => {
2019-08-21 08:52:13 +03:00
return (error.reason === "basic authentication requires a secure https url");
}, "throws an exception for insecure connections");
2019-05-15 01:48:48 +03:00
});
});