Skip to content

Commit

Permalink
chore: use requestAirdrop to fund e2e accounts (#1125)
Browse files Browse the repository at this point in the history
@willemneal [pointed out](stellar/stellar-docs#1101 (review))
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.
  • Loading branch information
chadoh authored Dec 20, 2024
1 parent d147768 commit 38115a1
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions test/e2e/src/util.js
Original file line number Diff line number Diff line change
@@ -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");

/*
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 38115a1

Please sign in to comment.