Skip to content

Commit 0892049

Browse files
committed
Make anchor test run at first try
1 parent 24dbba5 commit 0892049

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

examples/sol-anchor-contract/programs/sol-anchor-contract/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ pub mod sol_anchor_contract {
122122

123123
#[derive(Accounts)]
124124
pub struct InitRequest<'info> {
125-
#[account(
126-
address = *program_id @ ErrorCode::Unauthorized
127-
)]
128-
pub program: Signer<'info>,
129125
#[account(mut)]
130126
pub payer: Signer<'info>,
131127
#[account(
@@ -148,4 +144,4 @@ pub struct QueryRequest<'info> {
148144
address = config.collateral_price_feed_id @ ErrorCode::InvalidArgument
149145
)]
150146
pub pyth_collateral_account: Account<'info, PriceFeed>,
151-
}
147+
}

examples/sol-anchor-contract/tests/sol-anchor-contract.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,8 @@ describe("sol-anchor-contract", () => {
1818
.SolAnchorContract as anchor.Program<SolAnchorContract>;
1919
const payer = provider.wallet.publicKey;
2020
let programId = program.programId;
21-
var programKey;
22-
23-
try {
24-
let data = fs.readFileSync(
25-
"./target/deploy/sol_anchor_contract-keypair.json"
26-
);
27-
programKey = anchor.web3.Keypair.fromSecretKey(
28-
new Uint8Array(JSON.parse(data))
29-
);
30-
} catch (error) {
31-
throw new Error(
32-
"Please make sure the program key is program_address.json."
33-
);
34-
}
35-
36-
try {
37-
assert(programId.equals(programKey.publicKey));
38-
} catch (error) {
39-
throw new Error(
40-
"Please make sure you have the same program address in Anchor.toml and program_address.json"
41-
);
42-
}
21+
const programKey = program.programId;
22+
console.log(programKey)
4323

4424
it("Initialize the config.", async () => {
4525
const tx = await program.methods
@@ -53,7 +33,7 @@ describe("sol-anchor-contract", () => {
5333
config: config.publicKey,
5434
systemProgram: anchor.web3.SystemProgram.programId,
5535
})
56-
.signers([config, programKey])
36+
.signers([config])
5737
.rpc();
5838

5939
console.log("Config key: " + config.publicKey);

0 commit comments

Comments
 (0)