From 38115a16ed3fbc5d868ae8b1ab3042cf8a0c3399 Mon Sep 17 00:00:00 2001 From: Chad Ostrowski <221614+chadoh@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:33:28 -0500 Subject: [PATCH] chore: use `requestAirdrop` to fund e2e accounts (#1125) @willemneal [pointed out](https://github.com/stellar/stellar-docs/pull/1101#pullrequestreview-2461887053) that it's a bit of a bummer to create accounts with a pure-SDK interface just to revert to `fetch` and a hard-coded Friendbot URL in order to fund that account. This uses `rpc.Server#requestAirdrop` to do the funding. I find the name of this method a bit unexpected! I wonder if the language here has evolved since the method was first added. --- test/e2e/src/util.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/test/e2e/src/util.js b/test/e2e/src/util.js index 3c6a0d5c3..7b4e160b3 100644 --- a/test/e2e/src/util.js +++ b/test/e2e/src/util.js @@ -1,5 +1,5 @@ const { spawnSync } = require("node:child_process"); -const { contract, Keypair } = require("../../../lib"); +const { contract, Keypair, rpc } = require("../../../lib"); const path = require("node:path"); /* @@ -67,17 +67,13 @@ const networkPassphrase = process.env.SOROBAN_NETWORK_PASSPHRASE ?? "Standalone Network ; February 2017"; module.exports.networkPassphrase = networkPassphrase; -const friendbotUrl = - process.env.SOROBAN_FRIENDBOT_URL ?? "http://localhost:8000/friendbot"; -module.exports.friendbotUrl = friendbotUrl; async function generateFundedKeypair() { const keypair = Keypair.random(); - await fetch( - friendbotUrl === "https://friendbot.stellar.org" - ? `${friendbotUrl}/?addr=${keypair.publicKey()}` - : `${friendbotUrl}/friendbot?addr=${keypair.publicKey()}`, - ); + const server = new rpc.Server(rpcUrl, { + allowHttp: rpcUrl.startsWith("http://") ?? false, + }); + await server.requestAirdrop(keypair.publicKey()); return keypair; } module.exports.generateFundedKeypair = generateFundedKeypair;