This meant that when you run the instruction and pass in the CLOCK_SYSVAR public key, it would fail that constraint and error
This PR fixes it by:
Setting the clock account to be immutable as a Ty
When generating account annotations, set immutability based on ty.is_mut(). Previously we just used AccountAnnotation::new which is always mutable.
Full example test case:
# programs_py/clock.py
# seahorse_clock
# Built with Seahorse v0.2.2
from seahorse.prelude import *
declare_id('Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS')
@instruction
def hello(c: Clock):
ts = c.unix_timestamp()
print(ts)
// tests/seahorse-clock.ts
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { SeahorseClock } from "../target/types/seahorse_clock";
import { SYSVAR_CLOCK_PUBKEY } from "@solana/web3.js"
describe("seahorse_clock", () => {
// Configure the client to use the local cluster.
const anchorProvider = anchor.AnchorProvider.env()
anchor.setProvider(anchorProvider);
const program = anchor.workspace.SeahorseClock as Program<SeahorseClock>;
it("Is initialized!", async () => {
// Add your test here.
const tx = await program.methods
.hello()
.accountsStrict({
c: SYSVAR_CLOCK_PUBKEY,
})
.rpc();
console.log("Your transaction signature", tx);
});
});
On current main the test will fail with:
1) seahorse_clock
Is initialized!:
Error: AnchorError caused by account: c. Error Code: ConstraintMut. Error Number: 2000. Error Message: A mut constraint was violated.
at Function.parse (node_modules/@project-serum/anchor/src/error.ts:167:14)
at translateError (node_modules/@project-serum/anchor/src/error.ts:276:35)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:35:29)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
This was first flagged on Discord: https://discordapp.com/channels/1005658120548270224/1006027519952171028/1036610124925632542
The clock account was being generated as mutable:
This meant that when you run the instruction and pass in the
CLOCK_SYSVAR
public key, it would fail that constraint and errorThis PR fixes it by:
Ty
ty.is_mut()
. Previously we just usedAccountAnnotation::new
which is always mutable.Full example test case:
On current main the test will fail with:
With this PR the test passes