forked from Astrea-Payouts/astrea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstellar-payment.test.ts
More file actions
45 lines (40 loc) · 1.26 KB
/
Copy pathstellar-payment.test.ts
File metadata and controls
45 lines (40 loc) · 1.26 KB
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
import {
Account,
Horizon,
Keypair,
TransactionBuilder,
} from "@stellar/stellar-sdk";
import { afterEach, describe, expect, it, vi } from "vitest";
import { STELLAR_NETWORK_PASSPHRASE } from "@/lib/stellar-network";
import { buildForwardPaymentXdr } from "./stellar-payment";
const FROM = Keypair.random().publicKey();
const TO = Keypair.random().publicKey();
describe("buildForwardPaymentXdr", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("builds a plain Stellar payment for the exact net amount the judge received", async () => {
vi.spyOn(Horizon.Server.prototype, "loadAccount").mockResolvedValue(
new Account(FROM, "5") as unknown as Awaited<
ReturnType<Horizon.Server["loadAccount"]>
>,
);
const { unsignedXdr } = await buildForwardPaymentXdr({
fromPublicKey: FROM,
toPublicKey: TO,
amount: 0.997,
});
const tx = TransactionBuilder.fromXDR(
unsignedXdr,
STELLAR_NETWORK_PASSPHRASE,
);
expect("operations" in tx).toBe(true);
const operation = "operations" in tx ? tx.operations[0] : undefined;
expect(operation?.type).toBe("payment");
if (operation?.type === "payment") {
expect(operation.destination).toBe(TO);
expect(operation.amount).toBe("0.9970000");
expect(operation.asset.code).toBe("USDC");
}
});
});