Closed metaproph3t closed 10 months ago
Making createMint
work as-is would require hacks for getMinimumBalanceForRentExemptMint
and sendAndConfirmTransaction
which would be quite ugly and not compatible with TypeScript.
I'd recommend just rebuilding the transaction like they build it:
const transaction = new Transaction().add(
SystemProgram.createAccount({
fromPubkey: payer.publicKey,
newAccountPubkey: keypair.publicKey,
space: MINT_SIZE,
lamports,
programId,
}),
createInitializeMint2Instruction(keypair.publicKey, decimals, mintAuthority, freezeAuthority, programId)
);
If you want to calculate the rent you can do it with (await banksClient.getRent()).minimumBalance(MINT_SIZE)
. Or you could just stick a large number in the lamports
field if you're happy to skip the rent calculation step.
I would like if there were SPL Token helpers for solana-program-test
though. Then I'd be happy to wrap them in solana-bankrun
or an extension library
Huh, getting a fairly non-informative error from doing (await banksClient.getRent()).minimumBalance(MINT_SIZE)
:
at Context.<anonymous> (tests/conditionalVault.ts:59:35)
at Generator.next (<anonymous>)
at fulfilled (tests/conditionalVault.ts:28:58)
Oh what about (await banksClient.getRent()).minimumBalance(BigInt(MINT_SIZE))
?
Tried that one, it tells me that BigInts must be explicitly converted
Turns out that BigInts and bigints are different. Ah JS, the most well-designed language
Isn't MINT_SIZE just a regular number
?
Yep, it was something w/ BigInts but unrelated to that line. Just on one test now supported, I got test time down from 4s to 80ms - this is awesome!
There are some small footguns I've run into (e.g., you have to do context initialization in a before
function rather than just inside the describe
block for some reason), so I think I'll publish a gist of my test file as an example migration from anchor to bankrun when I'm done. Relatedly, how do I stop these debug and info messages from getting sent to stdout?
These come from the underlying Rust libraries. Use the RUST_LOG env var to silence them e.g. RUST_LOG= jest --runInBand
Got it, thx
It would be nice to be able to call the spl-token functions, such as the following:
I think this would require implementing some more of the functions on web3.js'
Connection
, such asgetMinimumBalanceForRentExemption