88 PublicKey ,
99 SystemProgram ,
1010 SYSVAR_RECENT_BLOCKHASHES_PUBKEY ,
11+ Transaction ,
1112} from "@solana/web3.js" ;
1213import * as assert from "assert" ;
1314import BN from "bn.js" ;
@@ -299,19 +300,28 @@ describe("system-coder", () => {
299300 ] )
300301 . signers ( [ nonceKeypair ] )
301302 . rpc ( ) ;
303+
304+ let nonceAccount = await program . account . nonce . fetch (
305+ nonceKeypair . publicKey
306+ ) ;
307+ let previousNonce = nonceAccount . nonce . toString ( ) ;
308+
302309 // These have to be separate to make sure advance is in another slot.
303- await program . methods
310+ const tx = await program . methods
304311 . advanceNonceAccount ( provider . wallet . publicKey )
305312 . accounts ( {
306313 nonce : nonceKeypair . publicKey ,
307314 recentBlockhashes : SYSVAR_RECENT_BLOCKHASHES_PUBKEY ,
308315 } )
309- . rpc ( ) ;
316+ . transaction ( ) ;
317+ tx . recentBlockhash = previousNonce ;
318+ tx . feePayer = provider . publicKey ;
319+
320+ await provider . sendAndConfirm ( tx , [ ] ) ;
310321 // assert
311- const nonceAccount = await program . account . nonce . fetch (
312- nonceKeypair . publicKey
313- ) ;
322+ nonceAccount = await program . account . nonce . fetch ( nonceKeypair . publicKey ) ;
314323 assert . notEqual ( nonceAccount , null ) ;
324+ assert . notEqual ( nonceAccount . nonce . toString ( ) , previousNonce ) ;
315325 } ) ;
316326
317327 it ( "Authorizes a nonce account" , async ( ) => {
@@ -383,7 +393,13 @@ describe("system-coder", () => {
383393 ] )
384394 . signers ( [ nonceKeypair ] )
385395 . rpc ( ) ;
386- await program . methods
396+
397+ let nonceAccount = await program . account . nonce . fetch (
398+ nonceKeypair . publicKey
399+ ) ;
400+ let previousNonce = nonceAccount . nonce . toString ( ) ;
401+
402+ const tx = await program . methods
387403 . advanceNonceAccount ( provider . wallet . publicKey )
388404 . accounts ( {
389405 nonce : nonceKeypair . publicKey ,
@@ -398,24 +414,47 @@ describe("system-coder", () => {
398414 } )
399415 . instruction ( ) ,
400416 ] )
401- . rpc ( ) ;
417+ . transaction ( ) ;
418+ tx . feePayer = provider . publicKey ;
419+ tx . recentBlockhash = previousNonce ;
420+
421+ await provider . sendAndConfirm ( tx , [ ] ) ;
422+
423+ nonceAccount = await program . account . nonce . fetch ( nonceKeypair . publicKey ) ;
424+ previousNonce = nonceAccount . nonce . toString ( ) ;
425+
402426 await program . methods
403427 . authorizeNonceAccount ( aliceKeypair . publicKey )
404428 . accounts ( {
405429 nonce : nonceKeypair . publicKey ,
406430 authorized : provider . wallet . publicKey ,
407431 } )
408432 . rpc ( ) ;
409- await program . methods
410- . withdrawNonceAccount ( new BN ( amount ) )
433+
434+ let withdrawTx = await program . methods
435+ . advanceNonceAccount ( aliceKeypair . publicKey )
411436 . accounts ( {
412- authorized : aliceKeypair . publicKey ,
413437 nonce : nonceKeypair . publicKey ,
414438 recentBlockhashes : SYSVAR_RECENT_BLOCKHASHES_PUBKEY ,
415- to : aliceKeypair . publicKey ,
439+ authorized : aliceKeypair . publicKey ,
416440 } )
417- . signers ( [ aliceKeypair ] )
418- . rpc ( ) ;
441+ . postInstructions ( [
442+ await program . methods
443+ . withdrawNonceAccount ( new BN ( amount ) )
444+ . accounts ( {
445+ authorized : aliceKeypair . publicKey ,
446+ nonce : nonceKeypair . publicKey ,
447+ recentBlockhashes : SYSVAR_RECENT_BLOCKHASHES_PUBKEY ,
448+ to : aliceKeypair . publicKey ,
449+ } )
450+ . instruction ( ) ,
451+ ] )
452+ . transaction ( ) ;
453+
454+ withdrawTx . feePayer = provider . publicKey ;
455+ withdrawTx . recentBlockhash = previousNonce ;
456+ await provider . sendAndConfirm ( withdrawTx , [ aliceKeypair ] ) ;
457+
419458 // assert
420459 const aliceBalanceAfter = (
421460 await program . provider . connection . getAccountInfo ( aliceKeypair . publicKey )
0 commit comments