Skip to content

Commit

Permalink
add close_signatures instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Jul 16, 2024
1 parent 2a4ba94 commit b8d731c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
4 changes: 4 additions & 0 deletions programs/example-queries-solana-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub mod example_queries_solana_verify {
Ok(())
}

pub fn close_signatures(ctx: Context<CloseSignatures>) -> Result<()> {
processor::close_signatures(ctx)
}

pub fn post_signatures(
ctx: Context<PostSignatures>,
guardian_signatures: Vec<[u8; 66]>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use anchor_lang::prelude::*;

use crate::state::GuardianSignatures;

#[derive(Accounts)]
pub struct CloseSignatures<'info> {
#[account(mut, has_one = refund_recipient, close = refund_recipient)]
guardian_signatures: Account<'info, GuardianSignatures>,

#[account(address = guardian_signatures.refund_recipient)]
refund_recipient: Signer<'info>,
}

/// Allows the initial payer to close the signature account in case the query was invalid.
pub fn close_signatures(_ctx: Context<CloseSignatures>) -> Result<()> {
Ok(())
}
3 changes: 3 additions & 0 deletions programs/example-queries-solana-verify/src/processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod close_signatures;
pub use close_signatures::*;

mod post_signatures;
pub use post_signatures::*;

Expand Down
29 changes: 23 additions & 6 deletions tests/example-queries-solana-verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import { deriveGuardianSetKey } from "./helpers/guardianSet";

use(chaiAsPromised);

// borrowed from https://github.com/wormhole-foundation/wormhole-circle-integration/blob/solana/integration/solana/ts/tests/helpers/consts.ts
export const PAYER_PRIVATE_KEY = Buffer.from(
"7037e963e55b4455cf3f0a2e670031fa16bd1ea79d921a94af9bd46856b6b9c00c1a5886fe1093df9fc438c296f9f7275b7718b6bc0e156d8d336c58f083996d",
"hex"
);

// TODO: PR to @wormhole-foundation/wormhole-query-sdk
export function signaturesToSolanaArray(signatures: string[]) {
return signatures.map((s) => [
Expand Down Expand Up @@ -407,4 +401,27 @@ describe("example-queries-solana-verify", () => {
"Error Code: InvalidGuardianKeyRecovery. Error Number: 7800. Error Message: InvalidGuardianKeyRecovery."
);
});
it("Closes signaure accounts!", async () => {
const signatureData = signaturesToSolanaArray(wethNameResponse.signatures);
const signatureKeypair = anchor.web3.Keypair.generate();
await program.methods
.postSignatures(signatureData, signatureData.length)
.accounts({ guardianSignatures: signatureKeypair.publicKey })
.signers([signatureKeypair])
.rpc();
await expect(
program.account.guardianSignatures.fetch(signatureKeypair.publicKey)
).to.be.fulfilled;
await expect(
program.methods
.closeSignatures()
.accounts({
guardianSignatures: signatureKeypair.publicKey,
})
.rpc()
).to.be.fulfilled;
await expect(
program.account.guardianSignatures.fetch(signatureKeypair.publicKey)
).to.be.rejectedWith("Account does not exist or has no data");
});
});
15 changes: 0 additions & 15 deletions tests/helpers/GuardianSignature.ts

This file was deleted.

0 comments on commit b8d731c

Please sign in to comment.