Эх сурвалжийг харах

tests: Move constant seed derivation test to `pda-derivation` (#3064)

acheron 1 жил өмнө
parent
commit
a8d2598cc9

+ 20 - 0
tests/pda-derivation/programs/pda-derivation/src/lib.rs

@@ -12,6 +12,7 @@ use anchor_spl::{
 declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
 
 pub const MY_SEED: [u8; 2] = *b"hi";
+pub const MY_SEED_BYTES: &[u8] = b"hi";
 pub const MY_SEED_STR: &str = "hi";
 pub const MY_SEED_U8: u8 = 1;
 pub const MY_SEED_U32: u32 = 2;
@@ -39,6 +40,10 @@ pub mod pda_derivation {
         Ok(())
     }
 
+    pub fn test_seed_constant(_ctx: Context<TestSeedConstant>) -> Result<()> {
+        Ok(())
+    }
+
     pub fn associated_token_resolution(_ctx: Context<AssociatedTokenResolution>) -> Result<()> {
         Ok(())
     }
@@ -127,6 +132,21 @@ pub struct Nested<'info> {
     account_nested: AccountInfo<'info>,
 }
 
+#[derive(Accounts)]
+pub struct TestSeedConstant<'info> {
+    #[account(mut)]
+    my_account: Signer<'info>,
+    #[account(
+      init,
+      payer = my_account,
+      seeds = [MY_SEED_BYTES],
+      space = 100,
+      bump,
+    )]
+    account: Account<'info, MyAccount>,
+    system_program: Program<'info, System>,
+}
+
 #[derive(Accounts)]
 pub struct AssociatedTokenResolution<'info> {
     #[account(

+ 4 - 0
tests/pda-derivation/tests/typescript.spec.ts

@@ -104,6 +104,10 @@ describe("typescript", () => {
     expect(called).is.true;
   });
 
+  it("Can use constant seed ref", async () => {
+    await program.methods.testSeedConstant().rpc();
+  });
+
   it("Can resolve associated token accounts", async () => {
     const mintKp = anchor.web3.Keypair.generate();
     await program.methods

+ 0 - 21
tests/relations-derivation/programs/relations-derivation/src/lib.rs

@@ -5,8 +5,6 @@ use anchor_lang::prelude::*;
 
 declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
 
-pub const SEED: &[u8] = b"contant-seed";
-
 #[program]
 pub mod relations_derivation {
     use super::*;
@@ -21,10 +19,6 @@ pub mod relations_derivation {
         Ok(())
     }
 
-    pub fn test_seed_constant(_ctx: Context<TestSeedConstant>) -> Result<()> {
-        Ok(())
-    }
-
     pub fn test_address_relation(_ctx: Context<TestAddressRelation>) -> Result<()> {
         Ok(())
     }
@@ -71,21 +65,6 @@ pub struct TestRelation<'info> {
     nested: Nested<'info>,
 }
 
-#[derive(Accounts)]
-pub struct TestSeedConstant<'info> {
-    #[account(mut)]
-    my_account: Signer<'info>,
-    #[account(
-      init,
-      payer = my_account,
-      seeds = [SEED],
-      space = 100,
-      bump,
-    )]
-    account: Account<'info, MyAccount>,
-    system_program: Program<'info, System>,
-}
-
 #[derive(Accounts)]
 pub struct TestAddressRelation<'info> {
     #[account(address = my_account.my_account)]

+ 0 - 4
tests/relations-derivation/tests/typescript.spec.ts

@@ -41,10 +41,6 @@ describe("typescript", () => {
     await tx.rpc();
   });
 
-  it("Can use relations derivation with seed constant", async () => {
-    await program.methods.testSeedConstant().accounts({}).rpc();
-  });
-
   it("Can use relations derivation with `address` constraint", () => {
     // Only compile test for now since the IDL spec doesn't currently support field access
     // expressions for the `address` constraint