anchor examples: removed unaligned references

This commit is contained in:
Conner Gallagher 2022-07-17 13:12:28 -06:00
parent f8874d7f60
commit 1b173c509c
4 changed files with 24 additions and 28 deletions

View File

@ -52,6 +52,11 @@ export async function transferWrappedSol(
amount: number
): Promise<number> {
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);
}

View File

@ -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> {

View File

@ -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> {

View File

@ -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"
);
});
});