ethers.js/lib.esm/_tests/test-providers-send.js

58 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-11-09 10:57:02 +03:00
import assert from "assert";
2022-11-09 14:22:17 +03:00
import { isError, Wallet } from "../index.js";
2022-11-09 10:57:02 +03:00
import { getProvider, providerNames } from "./create-provider.js";
2022-11-09 14:22:17 +03:00
function stall(duration) {
return new Promise((resolve) => { setTimeout(resolve, duration); });
}
2022-11-09 10:57:02 +03:00
describe("Sends Transactions", function () {
const cleanup = [];
after(function () {
for (const func of cleanup) {
func();
}
});
const wallet = new Wallet((process.env.FAUCET_PRIVATEKEY));
const networkName = "goerli";
for (const providerName of providerNames) {
const provider = getProvider(providerName, networkName);
if (provider == null) {
continue;
}
// Shutdown socket-based provider, otherwise its socket will prevent
// this process from exiting
if (provider.destroy) {
cleanup.push(() => { provider.destroy(); });
}
it(`tests sending: ${providerName}`, async function () {
2022-12-10 02:24:58 +03:00
this.timeout(180000);
2022-11-09 10:57:02 +03:00
const w = wallet.connect(provider);
const dustAddr = Wallet.createRandom().address;
2022-11-09 14:22:17 +03:00
// Retry if another CI instance used our value
let tx = null;
for (let i = 0; i < 10; i++) {
try {
tx = await w.sendTransaction({
to: dustAddr,
value: 42,
type: 2
});
break;
}
catch (error) {
2022-12-30 19:53:40 +03:00
if (isError(error, "REPLACEMENT_UNDERPRICED") || isError(error, "NONCE_EXPIRED")) {
2022-11-09 14:22:17 +03:00
await stall(1000);
continue;
}
throw error;
}
}
assert.ok(!!tx, "too many retries");
2022-11-09 10:57:02 +03:00
//const receipt =
2022-12-10 02:24:58 +03:00
await provider.waitForTransaction(tx.hash, null, 60000); //tx.wait();
2022-11-09 10:57:02 +03:00
//console.log(receipt);
const balance = await provider.getBalance(dustAddr);
assert.equal(balance, BigInt(42), "target balance after send");
});
}
});
//# sourceMappingURL=test-providers-send.js.map