0

I have the following

pub fn initialize_state(
    ctx: Context<InitializeState>,
    deposit_cap: u64,
) -> Result<()> {
    let mut state_account = ctx.accounts.state_account.load_init()?;
    state_account.deposit_cap = deposit_cap;
    Ok(())
}

#[derive(Accounts)]
#[instruction(deposit_cap: u64)]
pub struct InitializeState<'info> {
    ....
}

#[account(zero_copy)]
#[derive(Default)]
pub struct State {
    ....,
    pub deposit_cap: u64
}

When I test in js i do the following.

let depositCap = new BN(1_000_000)
const txInitState = await program.methods.initializeState(
      depositCap
    ).accounts({....})....

let state = await program.account.state.fetch(stateAccount)
console.log(state)

{....,
depositCap: <BN: 4000000000000000>
}

How do I compare the input of depositCap=1_000_000 with this struct depositCap for testing?

2 Answers 2

1

You can do

state.depositCap.eq(depositCap)
0

You can assert on both to check if they are equal or not.

assert.equal(depositCap.toNumber(), state.depositCap.toNumber());
1
  • no this doesnt work, i believe because the encoding of depositCap: <BN: 4000000000000000> is big endian byte array (i think). so to number is on the array. Error: Number can only safely store up to 53 bits
    – escargo
    Jul 27, 2022 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.