updated tests
This commit is contained in:
parent
33a33c9125
commit
4f3a6afc98
|
@ -1,6 +1,7 @@
|
|||
/node_modules/
|
||||
/dist/
|
||||
/coverage/
|
||||
test-ledger/
|
||||
/test-ledger
|
||||
/tests/keys
|
||||
|
||||
NOTES.md
|
|
@ -1 +1 @@
|
|||
[13,138,132,157,187,125,140,59,238,206,86,78,56,233,88,124,37,67,149,199,70,71,176,218,252,126,33,81,72,101,116,170,131,60,149,208,183,249,52,206,60,228,236,182,139,75,141,181,222,41,82,64,168,238,26,172,228,120,36,233,211,254,39,175]
|
||||
[111,190,165,118,25,191,114,217,98,107,42,45,15,31,244,48,231,80,186,109,222,70,99,105,101,11,104,132,232,24,105,16,32,40,197,240,151,132,9,59,36,127,101,141,76,74,63,22,211,113,191,59,111,49,236,75,208,54,247,131,78,131,37,38]
|
|
@ -1,5 +1,11 @@
|
|||
import { getOrCreateAssociatedTokenAccount, mintTo } from "@solana/spl-token";
|
||||
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
||||
import {
|
||||
Connection,
|
||||
Keypair,
|
||||
PublicKey,
|
||||
RpcResponseAndContext,
|
||||
TokenAmount,
|
||||
} from "@solana/web3.js";
|
||||
|
||||
export class Coin {
|
||||
symbol: string;
|
||||
|
@ -26,6 +32,27 @@ export class Coin {
|
|||
this.freezeAuthority = freezeAuthority;
|
||||
}
|
||||
|
||||
public async getBalance(
|
||||
owner: Keypair,
|
||||
connection: Connection,
|
||||
): Promise<RpcResponseAndContext<TokenAmount>> {
|
||||
const ata = await getOrCreateAssociatedTokenAccount(
|
||||
connection,
|
||||
owner,
|
||||
this.mint,
|
||||
owner.publicKey,
|
||||
true,
|
||||
"confirmed",
|
||||
);
|
||||
|
||||
const tokenAmount = await connection.getTokenAccountBalance(
|
||||
ata.address,
|
||||
"confirmed",
|
||||
);
|
||||
|
||||
return tokenAmount;
|
||||
}
|
||||
|
||||
public async fundAccount(
|
||||
decimalAmount: number,
|
||||
owner: Keypair,
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
import {
|
||||
Connection,
|
||||
Keypair,
|
||||
LAMPORTS_PER_SOL,
|
||||
PublicKey,
|
||||
} from "@solana/web3.js";
|
||||
import { Connection, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { assert } from "chai";
|
||||
import { Dex } from "../src";
|
||||
import { Coin, Dex, FileKeypair } from "../src";
|
||||
|
||||
describe("Serum Dev Tools", () => {
|
||||
const connection = new Connection("http://localhost:8899", "confirmed");
|
||||
const owner = Keypair.generate();
|
||||
const owner = FileKeypair.generate("./tests/keys/owner.json");
|
||||
|
||||
const dexAddress = new PublicKey(
|
||||
"7zo7HCQAZPRb4pYiQQ6fLjC8ssN3E8LkavVs8JUA5NMn",
|
||||
|
@ -18,33 +13,48 @@ describe("Serum Dev Tools", () => {
|
|||
|
||||
const dex = new Dex(dexAddress, connection);
|
||||
|
||||
let baseCoin: Coin;
|
||||
let quoteCoin: Coin;
|
||||
|
||||
before(async () => {
|
||||
const sig = await connection.requestAirdrop(
|
||||
owner.publicKey,
|
||||
owner.keypair.publicKey,
|
||||
20 * LAMPORTS_PER_SOL,
|
||||
);
|
||||
await connection.confirmTransaction(sig);
|
||||
|
||||
console.log(await connection.getBalance(owner.publicKey, "confirmed"));
|
||||
});
|
||||
|
||||
it("can create coin", async () => {
|
||||
const coin = await dex.createCoin("SAYA", 6, owner, owner.publicKey, null);
|
||||
it("can create coins", async () => {
|
||||
baseCoin = await dex.createCoin(
|
||||
"SAYA",
|
||||
9,
|
||||
owner.keypair,
|
||||
owner.keypair,
|
||||
owner.keypair,
|
||||
);
|
||||
quoteCoin = await dex.createCoin(
|
||||
"SRM",
|
||||
9,
|
||||
owner.keypair,
|
||||
owner.keypair,
|
||||
owner.keypair,
|
||||
);
|
||||
|
||||
assert.equal(coin.decimals, 6);
|
||||
assert.equal(coin.symbol, "SAYA");
|
||||
assert.equal(baseCoin.decimals, 9);
|
||||
assert.equal(baseCoin.symbol, "SAYA");
|
||||
|
||||
assert.equal(quoteCoin.decimals, 9);
|
||||
assert.equal(quoteCoin.symbol, "SRM");
|
||||
});
|
||||
|
||||
it("can init dex market", async () => {
|
||||
await dex.createCoin("SRM", 6, owner, owner.publicKey, null);
|
||||
|
||||
const dexMarket = await dex.initDexMarket(
|
||||
owner,
|
||||
owner.keypair,
|
||||
dex.getCoin("SAYA"),
|
||||
dex.getCoin("SRM"),
|
||||
{
|
||||
tickSize: 0.001,
|
||||
lotSize: 10,
|
||||
lotSize: 1e-3,
|
||||
tickSize: 1e-2,
|
||||
feeRate: 10,
|
||||
quoteDustThreshold: new BN(100),
|
||||
},
|
||||
|
@ -55,4 +65,15 @@ describe("Serum Dev Tools", () => {
|
|||
dexMarket.serumMarket.address.toBase58(),
|
||||
);
|
||||
});
|
||||
|
||||
it("can fund token accounts", async () => {
|
||||
await baseCoin.fundAccount(1e6, owner.keypair, connection);
|
||||
await quoteCoin.fundAccount(2e6, owner.keypair, connection);
|
||||
|
||||
const baseBalance = await baseCoin.getBalance(owner.keypair, connection);
|
||||
const quoteBalance = await quoteCoin.getBalance(owner.keypair, connection);
|
||||
|
||||
assert.equal(baseBalance.value.uiAmount, 1e6);
|
||||
assert.equal(quoteBalance.value.uiAmount, 2e6);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue