@@ -3,7 +3,12 @@ import 'test-matchers/toBeFrozenObject';
33import { Encoder } from '@solana/codecs-core' ;
44import { getBase58Encoder } from '@solana/codecs-strings' ;
55
6- import { Blockhash , ITransactionWithBlockhashLifetime , setTransactionLifetimeUsingBlockhash } from '../blockhash' ;
6+ import {
7+ assertIsTransactionWithBlockhashLifetime ,
8+ Blockhash ,
9+ ITransactionWithBlockhashLifetime ,
10+ setTransactionLifetimeUsingBlockhash ,
11+ } from '../blockhash' ;
712import { ITransactionWithSignatures } from '../signatures' ;
813import { BaseTransaction } from '../types' ;
914
@@ -109,6 +114,71 @@ describe('assertIsBlockhash()', () => {
109114 } ) ;
110115} ) ;
111116
117+ describe ( 'assertIsBlockhashLifetimeTransaction' , ( ) => {
118+ beforeEach ( ( ) => {
119+ // use real implementation
120+ jest . mocked ( getBase58Encoder ) . mockReturnValue ( originalGetBase58Encoder ) ;
121+ } ) ;
122+ it ( 'throws for a transaction with no lifetime constraint' , ( ) => {
123+ const transaction : BaseTransaction = {
124+ instructions : [ ] ,
125+ version : 0 ,
126+ } ;
127+ expect ( ( ) => assertIsTransactionWithBlockhashLifetime ( transaction ) ) . toThrow ( ) ;
128+ } ) ;
129+ it ( 'throws for a transaction with a durable nonce constraint' , ( ) => {
130+ const transaction = {
131+ instructions : [ ] ,
132+ lifetimeConstraint : {
133+ nonce : 'abcd' ,
134+ } ,
135+ version : 0 ,
136+ } as unknown as BaseTransaction ;
137+ expect ( ( ) => assertIsTransactionWithBlockhashLifetime ( transaction ) ) . toThrow ( ) ;
138+ } ) ;
139+ it ( 'throws for a transaction with a blockhash but no lastValidBlockHeight in lifetimeConstraint' , ( ) => {
140+ const transaction = {
141+ instructions : [ ] ,
142+ lifetimeConstraint : {
143+ blockhash : '11111111111111111111111111111111' ,
144+ } ,
145+ version : 0 ,
146+ } as unknown as BaseTransaction ;
147+ expect ( ( ) => assertIsTransactionWithBlockhashLifetime ( transaction ) ) . toThrow ( ) ;
148+ } ) ;
149+ it ( 'throws for a transaction with a lastValidBlockHeight but no blockhash in lifetimeConstraint' , ( ) => {
150+ const transaction = {
151+ instructions : [ ] ,
152+ lifetimeConstraint : {
153+ lastValidBlockHeight : 1234n ,
154+ } ,
155+ version : 0 ,
156+ } as unknown as BaseTransaction ;
157+ expect ( ( ) => assertIsTransactionWithBlockhashLifetime ( transaction ) ) . toThrow ( ) ;
158+ } ) ;
159+ it ( 'throws for a transaction with a blockhash lifetime but an invalid blockhash value' , ( ) => {
160+ const transaction = {
161+ instructions : [ ] ,
162+ lifetimeConstraint : {
163+ blockhash : 'not a valid blockhash value' ,
164+ } ,
165+ version : 0 ,
166+ } as unknown as BaseTransaction ;
167+ expect ( ( ) => assertIsTransactionWithBlockhashLifetime ( transaction ) ) . toThrow ( ) ;
168+ } ) ;
169+ it ( 'does not throw for a transaction with a valid blockhash lifetime constraint' , ( ) => {
170+ const transaction = {
171+ instructions : [ ] ,
172+ lifetimeConstraint : {
173+ blockhash : '11111111111111111111111111111111' ,
174+ lastValidBlockHeight : 1234n ,
175+ } ,
176+ version : 0 ,
177+ } as unknown as BaseTransaction ;
178+ expect ( ( ) => assertIsTransactionWithBlockhashLifetime ( transaction ) ) . not . toThrow ( ) ;
179+ } ) ;
180+ } ) ;
181+
112182describe ( 'setTransactionLifetimeUsingBlockhash' , ( ) => {
113183 let baseTx : BaseTransaction ;
114184 const BLOCKHASH_CONSTRAINT_A = {
0 commit comments