Skip to content

Commit

Permalink
anchor: add test suite for api integ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yurushao committed Jun 10, 2024
1 parent 6686f39 commit bcb535a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
7 changes: 4 additions & 3 deletions anchor/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ glam = "Gco1pcjxCMYjKJjSNJ7mKV7qezeUTE7arXJgy7PAPNRc"
url = "https://api.apr.dev"

[provider]
cluster = "localnet"
# cluster = "localnet"
#cluster = "devnet"
#cluster = "mainnet"
cluster = "mainnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_api_tx"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_crud"
test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_investor"
# test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_investor"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_drift"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_staking"
#test = "../node_modules/.bin/nx run --skip-nx-cache anchor:jest --verbose --testPathPattern tests/ --testNamePattern glam_jupiter"
Expand Down
1 change: 0 additions & 1 deletion anchor/src/client/jupiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ export class JupiterClient {
const addressLookupTableAccounts = await this.getAdressLookupTableAccounts(
addressLookupTableAddresses
);

let payerPublicKey;
try {
payerPublicKey = await this.base.getWalletSigner().publicKey;
Expand Down
69 changes: 69 additions & 0 deletions anchor/tests/glam_api_tx.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as anchor from "@coral-xyz/anchor";
import {
Transaction,
SystemProgram,
sendAndConfirmTransaction
} from "@solana/web3.js";
import { GlamClient } from "../src/client";

const API = "https://api.glam.systems";

describe("glam_api_tx", () => {
const glamClient = new GlamClient();

it("Wrap sol", async () => {
const response = await fetch(`${API}/tx/wsol/wrap`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
manager: "gLJHKPrZLGBiBZ33hFgZh6YnsEhTVxuRT17UCqNp6ff",
fund: "4gAcSdfSAxVPcxj2Hi3AvKKViGat3iUysDD5ZzbqhDTk",
amount: 1000000
})
});
const { tx } = await response.json();
console.log("Wrap tx:", tx);
const t = Transaction.from(Buffer.from(tx, "hex"));
t.sign(glamClient.getWalletSigner());
try {
const txId = await glamClient.provider.connection.sendRawTransaction(
t.serialize()
);
console.log("Wrap txId:", txId);
} catch (error) {
console.log("Error", error);
throw error;
}
});

it("unwrap", async () => {
const response = await fetch(`${API}/tx/wsol/unwrap`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
manager: "gLJHKPrZLGBiBZ33hFgZh6YnsEhTVxuRT17UCqNp6ff",
fund: "4gAcSdfSAxVPcxj2Hi3AvKKViGat3iUysDD5ZzbqhDTk"
})
});
const { tx } = await response.json();
console.log("unwrap tx", tx);

const t = Transaction.from(Buffer.from(tx, "hex"));
t.recentBlockhash = (
await glamClient.provider.connection.getLatestBlockhash()
).blockhash;
console.log("unwrap recentBlockhash", t.recentBlockhash);
t.sign(glamClient.getWalletSigner());
try {
const txId = await glamClient.provider.connection.sendRawTransaction(
t.serialize()
);
console.log("Wrap txId:", txId);
} catch (error) {
console.log("Error", error);
throw error;
}
});
});

0 comments on commit bcb535a

Please sign in to comment.