2022-11-04 18:11:38 -04:00
|
|
|
import assert from "assert";
|
|
|
|
|
2022-11-09 06:20:48 -05:00
|
|
|
import { isError, Wallet } from "../index.js";
|
2022-11-04 18:11:38 -04:00
|
|
|
|
2022-12-30 16:33:28 -05:00
|
|
|
import { getProvider, providerNames, setupProviders } from "./create-provider.js";
|
2022-11-04 18:11:38 -04:00
|
|
|
|
2022-11-09 06:20:48 -05:00
|
|
|
import type { TransactionResponse } from "../index.js";
|
|
|
|
|
|
|
|
function stall(duration: number): Promise<void> {
|
|
|
|
return new Promise((resolve) => { setTimeout(resolve, duration); });
|
|
|
|
}
|
|
|
|
|
2022-12-30 16:33:28 -05:00
|
|
|
setupProviders();
|
2022-11-04 18:11:38 -04:00
|
|
|
|
|
|
|
describe("Sends Transactions", function() {
|
|
|
|
|
|
|
|
const wallet = new Wallet(<string>(process.env.FAUCET_PRIVATEKEY));
|
|
|
|
|
|
|
|
const networkName = "goerli";
|
|
|
|
for (const providerName of providerNames) {
|
|
|
|
const provider = getProvider(providerName, networkName);
|
|
|
|
if (provider == null) { continue; }
|
|
|
|
|
2022-11-09 02:53:13 -05:00
|
|
|
it(`tests sending: ${ providerName }`, async function() {
|
2022-12-05 23:47:02 -05:00
|
|
|
this.timeout(180000);
|
2022-11-04 18:11:38 -04:00
|
|
|
|
|
|
|
const w = wallet.connect(provider);
|
|
|
|
|
|
|
|
const dustAddr = Wallet.createRandom().address;
|
|
|
|
|
2022-11-09 06:20:48 -05:00
|
|
|
// 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) {
|
2022-12-30 11:52:54 -05:00
|
|
|
if (isError(error, "REPLACEMENT_UNDERPRICED") || isError(error, "NONCE_EXPIRED")) {
|
2022-11-09 06:20:48 -05:00
|
|
|
await stall(1000);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.ok(!!tx, "too many retries");
|
2022-11-04 18:11:38 -04:00
|
|
|
|
2022-11-09 02:53:13 -05:00
|
|
|
//const receipt =
|
2022-12-05 23:47:02 -05:00
|
|
|
await provider.waitForTransaction(tx.hash, null, 60000); //tx.wait();
|
2022-11-09 02:53:13 -05:00
|
|
|
//console.log(receipt);
|
2022-11-04 18:11:38 -04:00
|
|
|
|
|
|
|
const balance = await provider.getBalance(dustAddr);
|
|
|
|
assert.equal(balance, BigInt(42), "target balance after send");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|