Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // Test a few things that should error
import { expect } from "@jest/globals";
import { createContext } from "./utils/context";
import { signAndSendInstructions } from "@bonfida/utils";
import { Connection, Keypair, SendTransactionError } from "@solana/web3.js";
import BN from "bn.js";
import {
initializeAccount,
placeOrder,
consumeEvents,
closeAccount,
} from "../src/bindings";
import { Market } from "../src/market";
import { OrderType, SelfTradeBehavior } from "../src/types";
import { Side } from "@bonfida/aaob";
import { random } from "./utils/random";
export const error = async (connection: Connection, feePayer: Keypair) => {
const tickSize = new BN(random(0, 5) * 2 ** 32);
const minBaseOrderSize = new BN(1);
const { marketKey, base, quote, Alice, Bob } = await createContext(
connection,
feePayer,
tickSize,
minBaseOrderSize,
6,
6
);
let market = await Market.load(connection, marketKey);
const tokenAmount = 10_000 * Math.pow(10, 6);
const aliceBaseAta = await base.getAssociatedTokenAccount(Alice.publicKey);
const aliceQuoteAta = await quote.getAssociatedTokenAccount(Alice.publicKey);
const bobBaseAta = await base.getAssociatedTokenAccount(Bob.publicKey);
const bobQuoteAta = await quote.getAssociatedTokenAccount(Bob.publicKey);
base.mintInto(aliceBaseAta, tokenAmount);
quote.mintInto(aliceQuoteAta, tokenAmount);
base.mintInto(bobBaseAta, tokenAmount);
quote.mintInto(bobQuoteAta, tokenAmount);
// Create user accounts with 1 capacity
await signAndSendInstructions(connection, [Alice], feePayer, [
await initializeAccount(marketKey, Alice.publicKey, 1, feePayer.publicKey),
]);
const failOrder = async () => {
return await signAndSendInstructions(connection, [Alice], feePayer, [
await placeOrder(
market,
Side.Ask,
10_000,
Math.random() * Math.pow(10, 5),
OrderType.Limit,
SelfTradeBehavior.AbortTransaction,
aliceBaseAta,
Alice.publicKey
),
await placeOrder(
market,
Side.Ask,
10_000,
Math.random() * Math.pow(10, 5),
OrderType.Limit,
SelfTradeBehavior.AbortTransaction,
aliceBaseAta,
Alice.publicKey
),
]);
};
await expect(failOrder()).rejects.toThrow(SendTransactionError);
// Consume 0 events
const failConsumeEvent = async () => {
return await signAndSendInstructions(connection, [], feePayer, [
await consumeEvents(
market,
feePayer.publicKey,
[Bob.publicKey],
new BN(10),
new BN(1)
),
]);
};
await expect(failConsumeEvent()).rejects.toThrow(SendTransactionError);
// Post only
await signAndSendInstructions(connection, [Bob, Alice], feePayer, [
await initializeAccount(marketKey, Bob.publicKey, 20, feePayer.publicKey),
await placeOrder(
market,
Side.Ask,
10_000,
Math.random() * Math.pow(10, 5),
OrderType.Limit,
SelfTradeBehavior.AbortTransaction,
aliceBaseAta,
Alice.publicKey
),
]);
const failPostOnly = async () => {
await signAndSendInstructions(connection, [Bob], feePayer, [
await placeOrder(
market,
Side.Bid,
2 * 10_000,
Math.random() * Math.pow(10, 5),
OrderType.PostOnly,
SelfTradeBehavior.AbortTransaction,
bobQuoteAta,
Bob.publicKey
),
]);
};
await expect(failPostOnly()).rejects.toThrow(SendTransactionError);
// Close account
const failCloseAccount = async () => {
return await signAndSendInstructions(connection, [Alice], feePayer, [
await closeAccount(market.address, Alice.publicKey),
]);
};
await expect(failCloseAccount()).rejects.toThrow(SendTransactionError);
};
|