All files / ethers.js/src.ts/_tests test-providers-send.ts

92.75% Statements 64/69
83.33% Branches 10/12
100% Functions 1/1
92.75% Lines 64/69

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 701x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 6x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 11x 11x 11x 11x 11x 11x 5x 11x 6x 6x 6x 6x     11x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x  
import assert from "assert";
 
import { isError, Wallet } from "../index.js";
 
import { getProvider, providerNames, setupProviders } from "./create-provider.js";
 
import type { TransactionResponse } from "../index.js";
 
import { FAUCET_PRIVATEKEY } from "./utils.js";
 
 
function stall(duration: number): Promise<void> {
    return new Promise((resolve) => { setTimeout(resolve, duration); });
}
 
setupProviders();
 
describe("Sends Transactions", function() {
    if (!FAUCET_PRIVATEKEY) {
        console.log("Missing Faucet Private Key! Tests Skipped.");
        return;
    }
 
    const wallet = new Wallet(FAUCET_PRIVATEKEY);
    console.log("Faucet Address:", wallet.address);
 
    const networkName = "sepolia";
    for (const providerName of providerNames) {
        const provider = getProvider(providerName, networkName);
        if (provider == null) { continue; }
 
        it(`tests sending: ${ providerName }`, async function() {
            this.timeout(180000);
 
            const w = wallet.connect(provider);
 
            const dustAddr = Wallet.createRandom().address;
 
            // Retry if another CI instance used our value
            let tx: null | TransactionResponse = null;
            for (let i = 0; i < 10; i++) {
                try {
                    tx = await w.sendTransaction({
                        to: dustAddr,
                        value: 42,
                        type: 2
                    });
                    break;
                } catch (error) {
                    if (isError(error, "REPLACEMENT_UNDERPRICED") || isError(error, "NONCE_EXPIRED")) {
                        await stall(1000);
                        continue;
                    }
                    throw error;
                }
            }
            assert.ok(!!tx, "too many retries");
 
            //const receipt = 
            await provider.waitForTransaction(tx.hash, null, 60000); //tx.wait();
            //console.log(receipt);
 
            const balance = await provider.getBalance(dustAddr);
            assert.equal(balance, BigInt(42), "target balance after send");
        });
    }
 
 
});