From 1b173c509c783e5604cd0fbb9350e6b61312f979 Mon Sep 17 00:00:00 2001 From: Conner Gallagher Date: Sun, 17 Jul 2022 13:12:28 -0600 Subject: [PATCH] anchor examples: removed unaligned references --- libraries/sbv2-utils/src/token.ts | 7 ++-- programs/anchor-buffer-parser/src/lib.rs | 5 --- programs/anchor-feed-parser/src/lib.rs | 5 --- .../tests/anchor-feed-parser.test.ts | 35 ++++++++++--------- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/libraries/sbv2-utils/src/token.ts b/libraries/sbv2-utils/src/token.ts index b478f73..dfba1e8 100644 --- a/libraries/sbv2-utils/src/token.ts +++ b/libraries/sbv2-utils/src/token.ts @@ -52,6 +52,11 @@ export async function transferWrappedSol( amount: number ): Promise { const payerBalance = await connection.getBalance(payerKeypair.publicKey); + if (payerBalance < amount) { + throw new Error( + `TransferWrappedSolError: Payer has insufficient funds, need ${amount}, have ${payerBalance}` + ); + } const payerAssociatedWallet = ( await spl.getOrCreateAssociatedTokenAccount( connection, @@ -102,8 +107,6 @@ export async function transferWrappedSol( ephemeralAccount, ]); - console.log(`WRAP SOL TRANSFER TXN = ${txn}`); - const finalBalance = await spl.getAccount(connection, payerAssociatedWallet); return Number(finalBalance.amount); } diff --git a/programs/anchor-buffer-parser/src/lib.rs b/programs/anchor-buffer-parser/src/lib.rs index 3716d68..9bb5704 100644 --- a/programs/anchor-buffer-parser/src/lib.rs +++ b/programs/anchor-buffer-parser/src/lib.rs @@ -1,14 +1,9 @@ -#[allow(unaligned_references)] use anchor_lang::prelude::*; use anchor_lang::solana_program::clock; pub use switchboard_v2::{BufferRelayerAccountData, SWITCHBOARD_V2_DEVNET, SWITCHBOARD_V2_MAINNET}; declare_id!("96punQGZDShZGkzsBa3SsfTxfUnwu4XGpzXbhF7NTgcP"); -#[account(zero_copy)] -#[derive(AnchorDeserialize, Debug)] -pub struct BufferClient {} - #[derive(Accounts)] #[instruction(params: ReadResultParams)] pub struct ReadResult<'info> { diff --git a/programs/anchor-feed-parser/src/lib.rs b/programs/anchor-feed-parser/src/lib.rs index 0be2621..25578a7 100644 --- a/programs/anchor-feed-parser/src/lib.rs +++ b/programs/anchor-feed-parser/src/lib.rs @@ -1,4 +1,3 @@ -#[allow(unaligned_references)] use anchor_lang::prelude::*; use anchor_lang::solana_program::clock; use std::convert::TryInto; @@ -8,10 +7,6 @@ pub use switchboard_v2::{ declare_id!("FnsPs665aBSwJRu2A8wGv6ZT76ipR41kHm4hoA3B1QGh"); -#[account(zero_copy)] -#[derive(AnchorDeserialize, Debug)] -pub struct FeedClient {} - #[derive(Accounts)] #[instruction(params: ReadResultParams)] pub struct ReadResult<'info> { diff --git a/programs/anchor-feed-parser/tests/anchor-feed-parser.test.ts b/programs/anchor-feed-parser/tests/anchor-feed-parser.test.ts index 7bdfc32..0334364 100644 --- a/programs/anchor-feed-parser/tests/anchor-feed-parser.test.ts +++ b/programs/anchor-feed-parser/tests/anchor-feed-parser.test.ts @@ -82,21 +82,24 @@ describe("anchor-feed-parser test", () => { }); it("Fails to read feed if confidence interval is exceeded", async () => { - await assert - .rejects( - (async () => { - await feedParserProgram.methods - .readResult({ maxConfidenceInterval: 0.0000000001 }) - .accounts({ aggregator: aggregatorKey }) - .rpc(); - // .catch((err) => { - // throw err; - // }); - })() - // { code: 6002 } - ) - .catch((err) => { - throw err; - }); + // await assertThrowsAsync( + // async () => + // feedParserProgram.methods + // .readResult({ maxConfidenceInterval: 0.0000000001 }) + // .accounts({ aggregator: aggregatorKey }) + // .rpc(), + // /Error/ + // ); + + await assert.rejects( + async () => { + await feedParserProgram.methods + .readResult({ maxConfidenceInterval: 0.0000000001 }) + .accounts({ aggregator: aggregatorKey }) + .rpc(); + }, + /ConfidenceIntervalExceeded/, + "Confidence interval was not exceeded" + ); }); });